Category Archives: Uncategorized

Mostly Armless + multiple sensor readings into Scrtach

A couple of colleagues and I have entered an internal competition.  An entry to the competition must include a robot, MQTT and node-red.  Our team entry is called “Mostly Armless” with a slogan of  “Scratching an itchy arm with a dash of red raspberry”. Rather than spoil the fun I’m going to let your imagination run a little and just as important keep our fellow competitors guessing. One thing  you won’t need too many guesses on is our entry will also include the use of Scratch.

The visual aspects together with control of the robot will use Scratch.  Mostly Armless will use techniques discussed in earlier post:  Visual programming and integration with Scratch, Node-Red and MQTT that showed how to enable Scratch to interact with the outside world using Node-Red.  Mostly Armless has multiple sensors whose reading need to be fed into Scratch.  This requires a little more work than the previous entry where just one sensor feed was used.

Scratch polls an external server to get the latest sensor readings.  To get multiple sensor readings a list of sensor name and value pairs separated by a new line must be returned in response to a Scratch poll request.  Here is an example of a function node based on the last blog entry that been enhanced to return both the wind direction and barometric pressure as reading testReport and testReport2:

msg.payload="testReport "
          "\ntestReport2 ";

return msg;

As scratch polls the server rather than accepting an event when the a sensor reading changes the latest wind direction and barometric pressure readings are stored in a global variable so that the  poll request can be fulfilled.

The Scratch Extension file must also be updated to include knowledge of the additional sensor:

    "extensionName": "Test",
    "extensionPort": 1880,
        "useHTTP": true, 
    "blockSpecs": [
        [" ", "test_Command1", "testCommand1"],
                [" ", "test_Command2 %n %n", "testCommand2", 100, 200],
                ["r", "test_Report", "testReport"],
                ["r", "test_Report2", "testReport2"]

With the extension loaded two report blocks are now available for use in the Scratch program. Below is a very simple Scratch program that continuously displays the wind direction for two seconds and then barometric pressure for two seconds:


More instalments on Mostly Armless as the project takes shape.