RPi: Building a ShakeMeter with Raspberry Shake and Node-Red

Goal:

Build a real-time “Shakemeter” in the Node-Red Dashboard! The Shakemeter will take the real-time seismic data and convert it into a live measurement of the absolute amplitude and velocity at which the ground is shaking! Set it up in your classroom and see how powerfully you can jump, put in next to the court to see how hard a home crowd cheers for your basketball team, or set it up at a school assembly to see which class has the most spirit!

 

Resources:

Introduction:

After following the first tutorial on connecting  Shake to Node-Red, now we can start to use Node-Red to process and visualize the seismic data that is being streamed through the UDP port.

Getting Started:

Before starting this tutorial, make sure you have already completed the “Streaming Raspberry Shake Data to Node-Red” tutorial. Your flow should look like this:

Make sure that there is UDP data being received by checking the debug tab. As you can see, the data coming through the Rshake Parser is still in object form, consisting of multiple types of information. In order to separate the numerical data and to quantify the shaking, another function node is needed to process the data. Below is an example of a node we made to address this.

Using the data:

[{"id":"d5d2efbb.2600e","type":"function","z":"b308f371.c9fa","name":"Absolute Amplitude","func":"acc = 0;\nnum = 0;\nfor(const p of msg.payload.packets)\n{\n    acc += Math.abs(p);\n    num++;\n}\n\nacc /= num;\n\nmsg.payload = acc;\nreturn msg;","outputs":1,"noerr":0,"x":570,"y":360,"wires":[["c8911fad.47f72"]]},{"id":"c8911fad.47f72","type":"smooth","z":"b308f371.c9fa","name":"","property":"payload","action":"mean","count":"25","round":"0","mult":"single","x":780,"y":360,"wires":[["6270e4ac.2138fc","64858a7e.ecae14"]]}]

 

You can copy and paste this code-block to import an ‘Absolute Amplitude’ function-node, it takes the raw data from the rshake parser node and turns it into a more easily usable integer which describes the amount of absolute vibration over the past couple of seconds. After it there is a “smooth” node to take the mean of the first numbers in order for the data to be processed more easily. *Note: photos show “average magnitude” in place of “absolute amplitude”

To import code-blocks like this, use the top right menu and select ‘import -> clipboard’ then a box will pop up allowing you to paste in the flow.

 

Your flow should now look similar to the photo above. The next step is to add the Dashboard “Gauge” Node, and attach it after the smooth node. Then, we have to configure the Gauge node. Make sure to Make the range from zero to at least 50000 (remember not to put a comma in 50000). If you have not yet, you will also have to create a Dashboard group, by pressing the edit button next to the “group” field, and then pressing it again next to the “tab” field.  Then click Update, then Done!

 

Now, we are ready to deploy!

Once deployed, open your local Node-Red Dashboard.  You can access this page by entering http://”yourIPaddress:1880/ui. For example: http://10.18.102.253:1880/ui

Now, bang the table! Jump up and down! How can you apply the ShakeMeter to something relevant in your home, school, or community?

So go get Shakin!

 

RPi: Building a Raspberry Shake seismogram on the Node-Red Dashboard

Goal:

Set up a real time Seismogram on the Node-Red Dashboard.

 

Resources:

Introduction:

After following the first tutorial on connecting  Shake to Node Red, now we can start to use Node-Red to process and visualize the seismic data that is being streamed through the UDP port.

Getting Started:

Before starting this tutorial, make sure you have already completed the “Streaming Raspberry Shake Data to Node-Red” tutorial. Your flow should look like this:

 

Make sure that there is UDP data being received by checking the debug tab. As you can see, the data coming through the Rshake Parser is still in object form, consisting of multiple types of information. For building the siesmogram graph, we just want the numerical data.

First, we have to add a switch node that discriminates the the channel of the data. If we are using a Shake 1D, it will be the channel EHZ. So, we must add a switch node after the parser, and format it to be listening for the property “msg.payload.channel” and underneath we can add the rule as: == “string” EHZ. This separates the data that we want.

The data is still not in a format useable for graphing, so we have to create a custom function node to separate the numerical data. Raspberry shake has created a code just for this purpose.

Go to the menu and choose import>clipboard, and paste this code and import the node.

[{"id":"299110c.a2af7f","type":"function","z":"d328b37.176a45","name":"format plot values","func":"\nvar EVERY_N_PACKET = 20; // max = 24\nvar POINTS_PER_SECOND = 100 / EVERY_N_PACKET;\nvar KEEP_SECONDS = 60;\nvar KEY=\"f2_all_points\";\n\nvar MAX_POINTS = POINTS_PER_SECOND * KEEP_SECONDS;\n\nvar input = msg.payload;\n\nvar data = [{series:[\"P\"],\n    data:[],\n    labels:[\"Points\"]\n}];\n\nvar allPoints = flow.get(KEY);\nif(allPoints == undefined)\n    allPoints = [];\n\n\nfor(var i=0, step=EVERY_N_PACKET; i + step < input.packets.length; i += step) {\n    var o = {x: input.ts + i*10,\n             y: input.packets[i]};\n    allPoints.push(o);\n}\n\nif(allPoints.length > MAX_POINTS)\n    allPoints = allPoints.slice(\n        allPoints.length - MAX_POINTS, \n        allPoints.length\n    );\n\nflow.set(KEY, allPoints);\n\ndata[0].data.push(allPoints);\n\n\nmsg.payload = data;\n\nreturn msg;","outputs":1,"noerr":0,"x":877,"y":171,"wires":[["73bf48a9.3fc398"]]}]

Connect the ‘format plot values” node to the switch node. Now, to finish we connect a Dashboard chart. Your flow should look similar to this:

Then, configure the chart in the way that you would like, and Deploy!

Now, open your local Node-Red Dashboard! You can access this page by entering your Node-Red address /ui. For example: http://10.18.102.253:1880/ui

Now, bang the table! Jump up and down! See what happens to the graph!

 

To continue working with the Shake Data in Node-Red, go to the next Tutorial!

Making a Shakemeter: https://t3alliance.org/rpi-building-a-shakemeter-with-raspberry-shake-and-node-red/

 

 

RPi Node-Red: Advanced Multi-Button Board + RGB LED

Overview

This tutorial will utilize a multi-button board input device to control an RGB LED module. Students will learn about and utilize binary counting to program the multi-button board. This tutorial adds to prior knowledge on the Button + LED tutorial.

Requirements

  • Raspberry Pi 3 Model B
  • Multi-Button Board
  • RGB LED Module
  • F-F Jumper Cables

Getting Started

Setting up the Hardware

Multi-Button Board to Raspberry Pi

  • K1 to #6
  • K2 to #5
  • K3 to #22
  • K4 to #27
  • K5 to #17
  • K6 to #4
  • K7 to #21
  • K8 to #20
  • G to GND

RGB LED to Raspberry Pi

  • R to #13
  • G to #19
  • B to #26
  • GND to GND

Setting up Node-Red

  1. Insert RPi-GPIO-In Nodes
    1. These nodes act as inputs from the multi-button board.
    2. Place 8 nodes, representing the 8 button inputs.
    3. Assign each button (K1, K2…, K8) to their respective GPIO pin on the Raspberry Pi.
    4. Set the Resistor setting to pullup.
    5.  
  2. Insert Change Nodes
    1. These nodes translate the input nodes from the multi-button board into number values from 0 to 7 (numbering starts at 0 due to how computers start counting at 0 instead of 1).
    2. Place 8 nodes, labeling them from 0 to 7.
    3. For each node, change the data type to number and set the values to 0-7 starting with the first node.
  3. Connect an RPi-GPIO-In node to a Change node
    1. Connecting the two node types translates each binary 0 or 1 button input into a different decimal value.
  4. Insert Function Nodes
    1. These nodes act as “decoders” that translates the numbered value into a bit-string.
    2. The RGB values represent three individual switches. By having a bit-string representation, each bit can determine the color’s bit state.
    3. Function for [4] node
      1. // Value retrieved from initial input
        var value = msg.payload;
        
        // subtract_bit determined by bit location
        var subtract_bit = 4;
        
        // If value is greater than the subtract_bit, indicates that the bit state for [4] is 1
        if (value >= subtract_bit) {
            var new_value = {payload: value - subtract_bit};
            var bit_state = {payload: 1};
            return [new_value, bit_state];
        }
        
        // Otherwise, bit state for [4] is 0
        else {
            value = {payload: value};
            var bit_state = {payload: 0};
            return [value, bit_state];
        }
    4. Function for [2] node
      1. // Value retrieved from initial input
        var value = msg.payload;
        
        // subtract_bit determined by bit location
        var subtract_bit = 2;
        
        // If value is greater than the subtract_bit, indicates that the bit state for [2] is 1
        if (value >= subtract_bit) {
            var new_value = {payload: value - subtract_bit};
            var bit_state = {payload: 1};
            return [new_value, bit_state];
        }
        
        // Otherwise, bit state for [2] is 0
        else {
            value = {payload: value};
            var bit_state = {payload: 0};
            return [value, bit_state];
        }
    5. Function for [1] node
      1. var bit_state = {payload: msg.payload};
        return bit_state;
  5. Insert RPi-GPIO-Out Nodes
    1. These nodes act as output nodes for the RGB LED module.
    2. Place three nodes, each representing one of the RGB LEDs and assign to their respective GPIO pin.

Conclusion

If you have successfully followed this tutorial module, you should be able to change the RGB LED module’s color from the multi-button board.

Node-Red Solution

[{"id":"3fc0ad9f.487e12","type":"change","z":"b8b26cb8.1baef","name":"2","rules":[{"t":"set","p":"payload","pt":"msg","to":"2","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":410,"y":280,"wires":[["5f4cfd28.f4a124"]]},{"id":"cbd11229.36a9","type":"rpi-gpio in","z":"b8b26cb8.1baef","name":"K2","pin":"29","intype":"up","debounce":"25","read":false,"x":290,"y":220,"wires":[["c4e5685f.e3fa88"]]},{"id":"96dd66c6.026928","type":"rpi-gpio in","z":"b8b26cb8.1baef","name":"K4","pin":"13","intype":"up","debounce":"25","read":false,"x":290,"y":340,"wires":[["75069901.3cc9b8"]]},{"id":"d710bb14.62b1f8","type":"rpi-gpio in","z":"b8b26cb8.1baef","name":"K3","pin":"15","intype":"up","debounce":"25","read":false,"x":290,"y":280,"wires":[["3fc0ad9f.487e12"]]},{"id":"2b18a8d6.7f92f8","type":"rpi-gpio in","z":"b8b26cb8.1baef","name":"K6","pin":"7","intype":"up","debounce":"25","read":false,"x":290,"y":460,"wires":[["ac5a8574.e332f8"]]},{"id":"3c93bf81.fb10d","type":"rpi-gpio in","z":"b8b26cb8.1baef","name":"K8","pin":"38","intype":"up","debounce":"25","read":false,"x":290,"y":580,"wires":[["d0ff8cfe.8f2c5"]]},{"id":"aac40b7a.f36bb8","type":"rpi-gpio in","z":"b8b26cb8.1baef","name":"K7","pin":"40","intype":"up","debounce":"25","read":false,"x":290,"y":520,"wires":[["3954b9a.a55c346"]]},{"id":"551dc587.3f572c","type":"rpi-gpio in","z":"b8b26cb8.1baef","name":"K5","pin":"11","intype":"up","debounce":"25","read":false,"x":290,"y":400,"wires":[["631bd1a6.8dd45"]]},{"id":"31bb63ee.bf082c","type":"change","z":"b8b26cb8.1baef","name":"0","rules":[{"t":"set","p":"payload","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":410,"y":160,"wires":[["5f4cfd28.f4a124"]]},{"id":"c4e5685f.e3fa88","type":"change","z":"b8b26cb8.1baef","name":"1","rules":[{"t":"set","p":"payload","pt":"msg","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":410,"y":220,"wires":[["5f4cfd28.f4a124"]]},{"id":"75069901.3cc9b8","type":"change","z":"b8b26cb8.1baef","name":"3","rules":[{"t":"set","p":"payload","pt":"msg","to":"3","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":410,"y":340,"wires":[["5f4cfd28.f4a124"]]},{"id":"631bd1a6.8dd45","type":"change","z":"b8b26cb8.1baef","name":"4","rules":[{"t":"set","p":"payload","pt":"msg","to":"4","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":410,"y":400,"wires":[["5f4cfd28.f4a124"]]},{"id":"ac5a8574.e332f8","type":"change","z":"b8b26cb8.1baef","name":"5","rules":[{"t":"set","p":"payload","pt":"msg","to":"5","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":410,"y":460,"wires":[["5f4cfd28.f4a124"]]},{"id":"3954b9a.a55c346","type":"change","z":"b8b26cb8.1baef","name":"6","rules":[{"t":"set","p":"payload","pt":"msg","to":"6","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":410,"y":520,"wires":[["5f4cfd28.f4a124"]]},{"id":"d0ff8cfe.8f2c5","type":"change","z":"b8b26cb8.1baef","name":"7","rules":[{"t":"set","p":"payload","pt":"msg","to":"7","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":410,"y":580,"wires":[["5f4cfd28.f4a124"]]},{"id":"23c6a01e.0e013","type":"rpi-gpio in","z":"b8b26cb8.1baef","name":"K1","pin":"31","intype":"up","debounce":"25","read":false,"x":290,"y":160,"wires":[["31bb63ee.bf082c"]]},{"id":"5f4cfd28.f4a124","type":"function","z":"b8b26cb8.1baef","name":"[4]","func":"// Value retrieved from initial input\nvar value = msg.payload;\n\n// subtract_bit determined by bit location\nvar subtract_bit = 4;\n\n// If value is greater than the subtract_bit, indicates that the bit state for [4] is 1\nif (value >= subtract_bit) {\n    var new_value = {payload: value - subtract_bit};\n    var bit_state = {payload: 1};\n    return [new_value, bit_state];\n}\n\n// Otherwise, bit state for [4] is 0\nelse {\n    value = {payload: value};\n    var bit_state = {payload: 0};\n    return [value, bit_state];\n}","outputs":2,"noerr":0,"x":590,"y":340,"wires":[["fb4d798f.1edc38"],["a17a86af.bfb648"]]},{"id":"fb4d798f.1edc38","type":"function","z":"b8b26cb8.1baef","name":"[2]","func":"// Value retrieved from initial input\nvar value = msg.payload;\n\n// subtract_bit determined by bit location\nvar subtract_bit = 2;\n\n// If value is greater than the subtract_bit, indicates that the bit state for [2] is 1\nif (value >= subtract_bit) {\n    var new_value = {payload: value - subtract_bit};\n    var bit_state = {payload: 1};\n    return [new_value, bit_state];\n}\n\n// Otherwise, bit state for [2] is 0\nelse {\n    value = {payload: value};\n    var bit_state = {payload: 0};\n    return [value, bit_state];\n}","outputs":2,"noerr":0,"x":730,"y":360,"wires":[["bb73fc3f.28e14"],["74e9a7d8.f4a0e8"]]},{"id":"bb73fc3f.28e14","type":"function","z":"b8b26cb8.1baef","name":"[1]","func":"var bit_state = {payload: msg.payload};\nreturn bit_state;","outputs":1,"noerr":0,"x":870,"y":380,"wires":[["9a25ca9f.d2dca8"]]},{"id":"a17a86af.bfb648","type":"rpi-gpio out","z":"b8b26cb8.1baef","name":"Red","pin":"33","set":"","level":"0","freq":"","out":"out","x":750,"y":280,"wires":[]},{"id":"74e9a7d8.f4a0e8","type":"rpi-gpio out","z":"b8b26cb8.1baef","name":"Green","pin":"35","set":"","level":"0","freq":"","out":"out","x":890,"y":300,"wires":[]},{"id":"9a25ca9f.d2dca8","type":"rpi-gpio out","z":"b8b26cb8.1baef","name":"Blue","pin":"37","set":"","level":"0","freq":"","out":"out","x":1030,"y":320,"wires":[]}]

RPi Airquality Station: Creating an Animated Nyancat Wallpaper

 

Goal:

Use the RPi Airquality station hardware, combined with node-red to create an animated nyancat wallpaper

 

What you will learn:

Combining the basic LED Matrix nodes, with more advanced javascript nodes to create fancier output.

 

What you will need to know:

Getting started with node-red

 

Parts List:

  • Full RPi Airquality kit

Getting Started:

First step is to familiarize yourself with the ‘image’ node.

Drag one in from the ‘LED Matrix’ section of the palette and setup config node, if you haven’t got one ready to re-use

All of the display settings can be left at their default, but because we want the wallpaper to update quickly you can bump the ‘Refresh Delay Milliseconds’ down to 100.
By default the Matrix will only redraw all the objects on the screen 2 times a second, but with this setting changed it’s a more attractive 10 times a second.

Next we’ll inject an image in the matrix.

This is the animated NyanCat we’ll be using: https://t3alliance.org/wp-content/uploads/2019/01/nyanCat.gif
It’s a tiny image, about 20 pixels high; but that’s a good thing for us because it means it’ll actually fit on the display. If you wish to use your own gifs and images with this tutorials, be mindful that the LED Matrix that comes with the airquality kit is only 128×64 pixels, so you’ll have to manually resize most images you want to use with it.

Setup an inject node with the nyanCat url as the string, and connect it to the image node.Once you deploy, and inject the node you should see the image appear as pictured.

Notice that the nyanCat is not animated. The way the Image Node handles gifs, is that it increments the frame when injected multiple times. So if you press the inject node button again, you should see the next frame in the sequence appear. You can continue clicking all the way through until the image resets back to frame one.

Of course the Node-Red inject node comes with repeating functionality already, so all you really have to do is setup the inject node like this to see your nyanCat beautifully animated in the top corner.

 

Manually Moving NyanCat:

Next is the more complicated step of actually moving the image around; I’ll lay out the function nodes so you can copy and paste them if you get stuck.

The basis for all our functions will be this info that comes with the image node. By default you can inject a plain string that gets matched with the settings in the node, or you can send a fully featured object that contains data for where the image should be drawn, as well as what file it’ll be.

To start we’ll try send just the image itself, in a static location.

//create the message we'll output
var output = {}

//insert our properties into the payload
output.payload = 
{
    data: "https://t3alliance.org/wp-content/uploads/2019/01/nyanCat.gif",
    x: 10, 
    y: 10,
}

//send out to the next node
return output

Here’s what the function node looks like with the code inside:

On line 2 we setup an empty object that we’ll fill with our properties later.
Then on line 5 – 10 we setup our data, the url of the image, and the location.
Then finally we return the object we created at the start, which will output it from the node-output.

Hooked up to the Image node with a generic inject node, you can draw the nyanCat again, except this time it’ll be offset from the top corner by 10 pixels.
Play around with the values for X and Y to move it around the screen manually.

 

Autonomous Nyancat:

The next step is getting the X and Y to update automatically.

Luckily for us nyanCat only flies in a straight line, so the Y coordinate can remain static, only changing the X coordinate interests us.
Here is the new code:

//create the message we'll output
var output = {}

//setup our varaible for X
var location = flow.get("x") || 0

//check to see if we've went off the edge
if(location > 128) location = 0

flow.set("x", location + 1)


//insert our properties into the payload
output.payload = 
{
    data: "https://t3alliance.org/wp-content/uploads/2019/01/nyanCat.gif",
    x: location,
    y: 20,
}

//send out to the next node
return output

On lines 5 – 10 we work with a ‘flow’ variable, this named variable ‘x’ sticks around with the flow and allows the function node to ‘remember’ a value between injections.
First we save the current value into the ‘location’ variable. Then we check to see if ‘location’ is greater than 128; if it is we reset it to zero.
Finally we save the new location back into the ‘flow variable’. The rest of the function node is pretty much the same as the last one.

Now with this code setup, your nyanCat should fly from one side of the screen over and over again. Remember to setup the inject node to repeatedly inject instead of just when you press the button.

Here is an export of the flow so far, so you can catch up if you’re lost:

[{"id":"7a5afae4.690634","type":"image-to-matrix","z":"93c88281.18b06","name":"","file":"","xOffset":0,"yOffset":0,"matrix":"9b09c013.e6c5b","zLevel":"","x":900,"y":360,"wires":[]},{"id":"b4672224.50062","type":"function","z":"93c88281.18b06","name":"NyanCat Function","func":"//create the message we'll output\nvar output = {}\n\n//setup our varaible for X\nvar location = flow.get(\"x\") || 0\n\n//check to see if we've went off the edge\nif(location > 128) location = 0\n\nflow.set(\"x\", location + 1)\n\n\n//insert our properties into the payload\noutput.payload = \n{\n    data: \"https://t3alliance.org/wp-content/uploads/2019/01/nyanCat.gif\",\n    x: location,\n    y: 20,\n}\n\n//send out to the next node\nreturn output","outputs":1,"noerr":0,"x":680,"y":360,"wires":[["7a5afae4.690634"]]},{"id":"56d87a3a.4542c4","type":"inject","z":"93c88281.18b06","name":"","topic":"","payload":"","payloadType":"date","repeat":"0.1","crontab":"","once":true,"onceDelay":0.1,"x":440,"y":360,"wires":[["b4672224.50062"]]},{"id":"9b09c013.e6c5b","type":"led-matrix","z":"","height":"64","width":"64","chained":"2","parallel":"1","brightness":"50","refreshDelay":"100","mapping":"adafruit-hat-pwm","autoRefresh":true}]

Animated Bubbles:

As a finishing touch we’ll be adding some animated bubbles to the mix. These will just be circles with random position, size, and color.
Just like with the image node, we’ll be using the object definitions from the circle node.

Here is the code for generating a static circle, that just sits in the middle of the screen looking pretty.

var output = {}

output.payload = 
{
    radius: 10, 
    rgb: "255,0,0",
    x: 64, 
    y: 34
}

return output;

Note that it looks almost identical to the original, if you inject this straight into a circle node it’ll plant a big red circle in the middle of the screen. If you setup the nyanCat properly it should be flying past it a couple of times a minute.

Next we can setup the random location and color, both pretty complicated functions so don’t be scared to just copy and paste them.

//generate a random number between 0 to max
function randInt (max)
{
    return Math.floor(Math.random() * Math.floor(max));
}

//generate a random rgb color, using the randInt function
function randColor()
{
    return randInt(256) + ',' + randInt(256) + ',' + randInt(256);
}



var output = {}

output.payload = 
{
    radius: randInt(10), 
    rgb: randColor(),
    x: randInt(128), 
    y: randInt(64)
}

return output;

The most important concept to grasp here, is the calling of user made functions between lines 19 – 22.
Other than that not much has changed.

For the best style I copy and paste this node a few times, into their own seperate circle nodes.
That way nyanCat can fly through 3 bubbles instead of just 1

And here is the exported flow, to catch you up to the final project:

[{"id":"7a5afae4.690634","type":"image-to-matrix","z":"93c88281.18b06","name":"","file":"","xOffset":0,"yOffset":0,"matrix":"9b09c013.e6c5b","zLevel":"","x":900,"y":360,"wires":[]},{"id":"b4672224.50062","type":"function","z":"93c88281.18b06","name":"NyanCat Function","func":"//create the message we'll output\nvar output = {}\n\n//setup our varaible for X\nvar location = flow.get(\"x\") || 0\n\n//check to see if we've went off the edge\nif(location > 128) location = 0\n\nflow.set(\"x\", location + 1)\n\n\n//insert our properties into the payload\noutput.payload = \n{\n    data: \"https://t3alliance.org/wp-content/uploads/2019/01/nyanCat.gif\",\n    x: location,\n    y: 20,\n}\n\n//send out to the next node\nreturn output","outputs":1,"noerr":0,"x":680,"y":360,"wires":[["7a5afae4.690634"]]},{"id":"56d87a3a.4542c4","type":"inject","z":"93c88281.18b06","name":"","topic":"","payload":"","payloadType":"date","repeat":"0.1","crontab":"","once":true,"onceDelay":0.1,"x":440,"y":360,"wires":[["b4672224.50062","e5b23895.437f38","9f3dc778.1d1e98","202d83ef.c75e8c"]]},{"id":"50105316.5a64dc","type":"circle","z":"93c88281.18b06","name":"","xPos":0,"yPos":0,"radius":0,"rgb":"0,255,41","matrix":"9b09c013.e6c5b","zLevel":"","x":890,"y":300,"wires":[]},{"id":"e5b23895.437f38","type":"function","z":"93c88281.18b06","name":"Circle Function","func":"//generate a random number between 0 to max\nfunction randInt (max)\n{\n    return Math.floor(Math.random() * Math.floor(max));\n}\n\n//generate a random rgb color, using the randInt function\nfunction randColor()\n{\n    return randInt(256) + ',' + randInt(256) + ',' + randInt(256);\n}\n\n\n\nvar output = {}\n\noutput.payload = \n{\n    radius: randInt(10), \n    rgb: randColor(),\n    x: randInt(128), \n    y: randInt(64)\n}\n\nreturn output;","outputs":1,"noerr":0,"x":660,"y":300,"wires":[["50105316.5a64dc"]]},{"id":"4313edf2.721a04","type":"circle","z":"93c88281.18b06","name":"","xPos":0,"yPos":0,"radius":0,"rgb":"0,255,41","matrix":"9b09c013.e6c5b","zLevel":"","x":890,"y":260,"wires":[]},{"id":"9f3dc778.1d1e98","type":"function","z":"93c88281.18b06","name":"Circle Function","func":"//generate a random number between 0 to max\nfunction randInt (max)\n{\n    return Math.floor(Math.random() * Math.floor(max));\n}\n\n//generate a random rgb color, using the randInt function\nfunction randColor()\n{\n    return randInt(256) + ',' + randInt(256) + ',' + randInt(256);\n}\n\n\n\nvar output = {}\n\noutput.payload = \n{\n    radius: randInt(10), \n    rgb: randColor(),\n    x: randInt(128), \n    y: randInt(64)\n}\n\nreturn output;","outputs":1,"noerr":0,"x":660,"y":260,"wires":[["4313edf2.721a04"]]},{"id":"4863e929.52f748","type":"circle","z":"93c88281.18b06","name":"","xPos":0,"yPos":0,"radius":0,"rgb":"0,255,41","matrix":"9b09c013.e6c5b","zLevel":"","x":890,"y":220,"wires":[]},{"id":"202d83ef.c75e8c","type":"function","z":"93c88281.18b06","name":"Circle Function","func":"//generate a random number between 0 to max\nfunction randInt (max)\n{\n    return Math.floor(Math.random() * Math.floor(max));\n}\n\n//generate a random rgb color, using the randInt function\nfunction randColor()\n{\n    return randInt(256) + ',' + randInt(256) + ',' + randInt(256);\n}\n\n\n\nvar output = {}\n\noutput.payload = \n{\n    radius: randInt(10), \n    rgb: randColor(),\n    x: randInt(128), \n    y: randInt(64)\n}\n\nreturn output;","outputs":1,"noerr":0,"x":660,"y":220,"wires":[["4863e929.52f748"]]},{"id":"9b09c013.e6c5b","type":"led-matrix","z":"","height":"64","width":"64","chained":"2","parallel":"1","brightness":"50","refreshDelay":"100","mapping":"adafruit-hat-pwm","autoRefresh":true}]

To import, copy it into your clipboard; and come up to the ‘import’  menu here:

 

More Ideas:

As long as the file is the right dimensions you can use any animated gif for the display, here is another file you can link into the project in this tutorial.
https://t3alliance.org/wp-content/uploads/2019/01/original.gif

 

Another good resource is pixilart.com

Here you can create your own pixel art, set the exact size in pixels (useful for making sure everything fits on the display) and even export animated gifs.
To create a gif, use the layer tools on the right. This button duplicates your current layer which is useful for making slight changes on the next frame.Then use the ‘Download/Save’ tool to export your file as an animated gif.

RPi Node-Red: BME280 Temperature Pressure Humidity

Parts List:

BME280

Getting Started:

Setting up the Hardware

Setting up Node-Red

1) Start Node-Red and navigate to 127.0.0.1:1880.

If your Raspberry Pi does not have the node-red-contrib-bme280 palette, follow the instructions located here.

2) After installing the BME280 palette, place the Bme280 node onto the workflow.

3) What the Bme280 node does is read sensor data from the Bme280, and delivers that data as a payload.

msg = {
  _msgid: <node-red msg_id>,
  topic: <defined topic>,
  payload: {
    model: "BME280"  or  "BMP280",
    temperature_C: <float in celsius>,
    humidity: <float in %>, // Only present if model == "BME280"
    pressure_hPa: <float in hPa>
  }
}

 

As you can see, the payload contains attributes we will graph, including temperature, humidity, etc.

4) After seeing what the BME280 sensor sends to the Raspberry Pi, we are going to format it as a graph using Node-Red and Dashboard. Start by placing a change node from the functions section onto the workflow. The change node specifies the data field from the Bme280 node, in this case it is the temperature field.

5) Double-click on the change node to open the node configuration menu. Under Rules, you will see a field for payload and under that, another blank field. Click on the drop down button and select msg.

6) Now that we have specified the type to msg., we want to type in “payload.temperature_C”. If you look at the BME280 payload again, you can see that the field we typed in refers to that payload. Click Done once completed.

7) Drag and drop the chart node from the dashboard section onto the workflow.

8) Double click the chart node to edit the node. On the group field, click on the pencil button.

8.1) On the Tab field, click on the pencil button again.

8.2) From there, click on the Update button to return to the previous menu, then again to return to the original menu. This is to confirm the dashboard view settings. On the original menu, we can adjust the graph’s design, color, label, etc. Let’s proceed with labeling our chart “Temperature in C”. Click Done once completed.

9) To have the BME280 send data at an interval, place an inject node from the input tab onto the workflow.

9.1) Set the payload to number and enter 1 (means ‘on’ for the computer) in the field. Set Repeat to interval and set the interval time to any desired time (good to start at 5 seconds). Click Done once completed.

10) With all the nodes configured, connect all the nodes and hit Deploy.

11) Navigate to the Dashboard page to view your graph(s): 127.0.0.1:1880/ui/#/0

Node-RED Palette Installation (node-red-contrib-bme280)

1) Click on the menu icon in the top-right corner of the window and select Manage palette.

2) Navigate to the Install tab.

3) In the search modules bar, type in node-red-contrib-bme280 and click install.

4) An installation window will pop-up. Click install.

 

Next Steps:

 

RPi Node-Red: Minimal Selfie Station Tutorial

Goal:

setup the RPi’s software and hardware to create a minimal selfie station. Utilizing node-red, and a few components like the RPi camera and the led ring.

What you will learn:

Advanced node-red usage, using hardware with node-red, how to use the camera node.

 

What you will need:

RPi with node-red, RPi camera, button, and LED ring.

 

Introduction:

We will create a node-red flow to take selfies and display them right on the raspberry-pi desktop, using the LED-ring as a flash. To achieve this we will need to go through several steps: activate the LED-ring, take a picture, and open it on the desktop. But first we need to wire up the hardware.

 

Wiring:

Use jumper wires to hook up the LED ring to ground, 5v, and pin #18.
And the button hooks up to ground, 3v, and pin #12.

Setting up Node-Red:

start node-red, and navigate to 127.0.0.1:1880. Drag in a rpi gpio pin and hook it up to a debug node.

To configure the GPIO node, set the pin to GPIO: 12, resistor to pulldown.
You can also name the node ‘button’ to remind you later.


Now that we have the button configured, we can test it out. If you deploy the current flow you should be able to see output in the debug tab whenever you press the button.
Next we want to setup the flash ring, the led-ring is controlled by a neopixels node, so drag one of those in.
The only Setting that needs to set for this is the number of led in string, usually this should be 12.
You can rename this node to led-ring in the same menu.

Reading the led-ring help dialog, we find that it doesn’t  just take a generic ‘injection’ to turn it on; but a more complicated command that it reads.
For example: ‘1,12,0,255,0’ sets the entire ring red.
Broken down, this command means: ‘set leds #1 to #12 to the color ‘0,255,0’.  This color can further be broken down into ‘Red: 0, Green: 255, Blue: 0′

So if you use a generic ‘inject’ node into the led-ring node, you can light it up red with this string.

For the actual flash a flashing, multicolored timer, followed by a white flash is ideal, to do this we use timing nodes combined with change nodes.
The change nodes we will use look like this, they take an input; change the payload and then send it out.

For the flashing effect the nodes will have to be chained like this, with a delay node.

You can copy and paste the change node from earlier, and then go in and change the color code it sends.
This chain can be continued down the line; don’t forget that the color code for white is: 255,255,255.

One annoying quirk of the GPIO node, is that it sends a message when you press the button down and when released; so you could trigger this entire flow twice if you held the button down for a noticeable amount of time. The easiest way to solve this is to stick a rate-limit node after the GPIO node, like this.
A good default is 1 message per 5 seconds.
To do this, setup a ‘delay’ node with these settings, hooked just after the GPIO node.
Make sure to select ‘drop intermediate messages’

 

Next we need to setup the camera node, make sure the camera is plugged into the camera port on the raspi.
[image here]

You can setup the camera node like this:
The input wire activates the camera, and the output wire sends the filename when its done taking a picture.
Seeing as the camera sends a message when its finished taking a picture, we can use this to turn off the flash at exactly the right time.
When you copy and paste another change-node, set the color to ‘0,0,0’ to turn the led-ring off.

You can use a debug node to check the filename the camera is outputting too.

The final, and most arcane step is to open the image in a image-viewer. This is done with an ‘exec’ node you can drag in.
You can copy all these settings in, and hook it up to the ‘take photo node’

 

Leaving you with a hopefully functional flow that looks like this.

If you are a teacher and need a working demo of this project, you can download the image here: https://t3alliance.org/wp-content/uploads/2018/11/selfieImage.zip

Shortcuts:

if you get stuck in this tutorial, feel free to import the entire flow from here:

[{"id":"549d128c.d1e48c","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"7a6088da.6f3e38","type":"camerapi-takephoto","z":"549d128c.d1e48c","filemode":"2","filename":"","filedefpath":"1","filepath":"","fileformat":"jpeg","resolution":"9","rotation":"0","fliph":"0","flipv":"0","brightness":"50","contrast":"0","sharpness":"0","quality":"80","imageeffect":"none","exposuremode":"auto","iso":"0","agcwait":"1.0","led":"0","awb":"auto","name":"","x":670,"y":520,"wires":[["226fa57f.d594ca","65312393.72d7ec"]]},{"id":"65312393.72d7ec","type":"exec","z":"549d128c.d1e48c","command":"DISPLAY=:0.0 gpicview","addpay":true,"append":"&","useSpawn":"false","timer":"","oldrc":false,"name":"Open image file","x":910,"y":600,"wires":[[],[],[]]},{"id":"226fa57f.d594ca","type":"change","z":"549d128c.d1e48c","name":"turn off LED ring","rules":[{"t":"set","p":"payload","pt":"msg","to":"0,12,0,0,0","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":910,"y":520,"wires":[["e70bf46d.3df5b8"]]},{"id":"e01059e8.526678","type":"delay","z":"549d128c.d1e48c","name":"","pauseType":"delay","timeout":".5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":720,"y":340,"wires":[["2b05a1af.2d162e","4a634559.5bed0c"]]},{"id":"1c398bbd.6ff2c4","type":"change","z":"549d128c.d1e48c","name":"Set LED ring = Red","rules":[{"t":"set","p":"payload","pt":"msg","to":"1,12,0,255,0","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":920,"y":280,"wires":[["e70bf46d.3df5b8"]]},{"id":"2b05a1af.2d162e","type":"change","z":"549d128c.d1e48c","name":"Set LED ring = Green","rules":[{"t":"set","p":"payload","pt":"msg","to":"0,12,255,0,0","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":930,"y":340,"wires":[["e70bf46d.3df5b8"]]},{"id":"cd35bff4.45e72","type":"change","z":"549d128c.d1e48c","name":"Set LED ring = Blue","rules":[{"t":"set","p":"payload","pt":"msg","to":"0,12,0,0,255","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":920,"y":400,"wires":[["e70bf46d.3df5b8"]]},{"id":"4a634559.5bed0c","type":"delay","z":"549d128c.d1e48c","name":"","pauseType":"delay","timeout":".5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":720,"y":400,"wires":[["cd35bff4.45e72","d6b433a.088ced"]]},{"id":"db82b2b9.cc94a","type":"change","z":"549d128c.d1e48c","name":"Set LED ring = White","rules":[{"t":"set","p":"payload","pt":"msg","to":"0,12,255,255,255","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":930,"y":460,"wires":[["e70bf46d.3df5b8"]]},{"id":"d6b433a.088ced","type":"delay","z":"549d128c.d1e48c","name":"","pauseType":"delay","timeout":".5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":720,"y":460,"wires":[["db82b2b9.cc94a","7a6088da.6f3e38"]]},{"id":"8c366b7d.3c3f18","type":"rpi-gpio in","z":"549d128c.d1e48c","name":"","pin":"32","intype":"down","debounce":"25","read":false,"x":400,"y":280,"wires":[["655eb18c.06cca"]]},{"id":"e70bf46d.3df5b8","type":"rpi-neopixels","z":"549d128c.d1e48c","name":"","pixels":"12","bgnd":"","fgnd":"","wipe":"40","mode":"pcent","rgb":"rgb","brightness":"100","gamma":true,"x":1180,"y":280,"wires":[]},{"id":"655eb18c.06cca","type":"delay","z":"549d128c.d1e48c","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"5","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"x":600,"y":280,"wires":[["e01059e8.526678","1c398bbd.6ff2c4","4c17564c.dcd4c8"]]},{"id":"4c17564c.dcd4c8","type":"debug","z":"549d128c.d1e48c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":920,"y":200,"wires":[]}]

 

RPi-NodeRed OLED IP Address Display

Please copy and paste the entire code block below into the node-red clipboard import window.

[{"id":"a1ae5e26.b300a","type":"String","z":"e0e44734.95d078","name":"OLED","display":"4fe1da30.5141a4","x":690,"y":220,"wires":[]},{"id":"60037f1d.3914b","type":"function","z":"e0e44734.95d078","name":"Format Message","func":"msg.payload={\nx:1,  \ny:50,\ntext:\"IP \"+msg.payload+\":1880\"\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":520,"y":220,"wires":[["a1ae5e26.b300a"]]},{"id":"8971c892.2fa0f8","type":"change","z":"e0e44734.95d078","name":"IP","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload[0].address","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":220,"wires":[["60037f1d.3914b"]]},{"id":"974cfafc.e526d8","type":"inject","z":"e0e44734.95d078","name":"","topic":"","payload":"10","payloadType":"num","repeat":"60","crontab":"","once":true,"onceDelay":0.1,"x":90,"y":220,"wires":[["8c7a8725.02fa58"]]},{"id":"8c7a8725.02fa58","type":"hostip","z":"e0e44734.95d078","name":"Host IP","x":220,"y":220,"wires":[["8971c892.2fa0f8"]]},{"id":"8f95bb29.b800d8","type":"comment","z":"e0e44734.95d078","name":"Display IP address on the mini OLED display","info":"","x":300,"y":180,"wires":[]},{"id":"4fe1da30.5141a4","type":"oled-config","z":"","name":"","width":"128","height":"64","address":"3c"}]

RPi Node-Red: Buzzer

Parts List:

Piezoelectric Buzzer

What is a Piezoelectric Buzzer?

A piezoelectric buzzer is a buzzer that is activated with an oscillating electric signal.  This means to produce a tone the buzzer must be turned on and off many times per second. The faster the the buzzer is turned on and off the higher the pitch is produced.  We can achieve this using a pulse width modulated signal (PWM). With a PWM signal we can specify the frequency in hertz (cycles per second).

Getting Started:

Setting up the Hardware

Using jumper wires connect the I/O pin of the buzzer to GPIO16, the GND pin to GND (ground), and the VCC pin to VCC.

Setting up Node-Red

Start Node-Red and navigate to 127.0.0.1:1880.  Drag two inject nodes and a Raspberry Pi output node into the flow area.

Double click on the Raspberry Pi output node to open its configuration menu.  Set the Pin to GPIO16.  Set Type to PWM output.  Set Frequency to 100 Hz.  You can Name the node anything, I chose “buzzer”.

Double click one of the inject nodes.  Use the dropdown menu to change the Payload data type number, type a 1 in the textbox.  Name the inject node “on”.

Double click the unmodified inject node.  Use the drop down menu to change the Payload data type to number, type a 0 in the text box.  Name this node “off”.

1 and 0 correspond for to values of a binary digit(bit) true and false, high and low, on and off respectively.  These are called Boolean values and are a fundamental data type in Computer Science.

Connect the inject nodes to the output node and then deploy the flow.

If everything has worked correctly pressing the “on” button should cause a sound to come from the buzzer and the “off” button should stop that sound.

RPi Node-Red: Push Button+ RGB LED or Buzzer

Parts List:

1x RGB LED

1x Push Button

1x Piezoelectric Buzzer

Getting Started:

Setting up the Hardware

Setting up Node-Red

Start Node-Red and navigate to 127.0.0.1:1880.  Drag one Raspberry Pi input node and five Raspberry Pi output nodes into the flow area.

Double click on the Raspberry Pi input node to open its configuration menu.  Set the Pin to GPIO25.  Name the node “Button”. Set the Resistor to “pulldown”.

Button Input Node

 

Double click on the unmodified Raspberry Pi output node.  Set Pin to GPIO16.  Set Type to PWM output.  Set Frequency to 100.  Name the node “buzzer”.

Buzzer Out Node

For this step, we are going to setup the output nodes for each RGB node. Double click on one of the Raspberry Pi output nodes.  Set the Red Pin to GPIO13Green Pin to GPIO19, and Blue Pin to GPIO26. Check the box to Initialise pin state?  select low (0) from the drop down menu.  Name each node with its respective “Red, Green, Blue”.

Red Out Node

Green Out Node

Blue Out Node

Wire each output node to the single input node and deploy the flow.

If everything is working properly the LED should illuminate and the buzzer should activate for a short period of time after the button has been pressed.  To deactivate either the buzzer or LED simply delete the wire in Node-Red connecting the associated node with the Button node.

Whats Next?

  • What other combinations can you make with items in your kit?

RPi Node-Red: PIR + RGB LED or Buzzer

Parts List:

1x RGB LED

1x PIR

1x Piezoelectric Buzzer

Getting Started:

Setting up the Hardware

Setting up Node-Red

Start Node-Red and navigate to 127.0.0.1:1880.  Drag one Raspberry Pi input node and five Raspberry Pi output nodes into the flow area.

Double click on the Raspberry Pi input node to open its configuration menu.  Set the Pin to GPIO20.  Name the node “PIR”.

Double click on the unmodified Raspberry Pi output node.  Set Pin to GPIO16.  Set Type to PWM output.  Set Frequency to 100.  Name the node “buzzer”.

Buzzer Out Node

For this step, we are going to setup the output nodes for each RGB node. Double click on one of the Raspberry Pi output nodes.  Set the Red Pin to GPIO13Green Pin to GPIO19, and Blue Pin to GPIO26. Check the box to Initialise pin state?  select low (0) from the drop down menu.  Name each node with its respective “Red, Green, Blue”.

Red Out Node

Green Out Node

Blue Out Node

Wire each output node to the single input node and deploy the flow.

If everything is working properly the LED should illuminate and the buzzer should activate for a short period of time after the PIR has detected movement.  To deactivate either the buzzer or LED simply delete the wire in Node-Red connecting the associated node with the PIR node.

Whats Next?

  • What other combinations can you make with items in your kit?

RPi Node-Red: RGB LED

Parts List:

1x RGB LED Board

4x Female-Female Jumper Wires

Getting Started:

Setting up the hardware:

Connecting the RGB LED Module

Setting up on Node-Red:

Have three out nodes, each representing one of the three outputs. For each out node, have two inject nodes (on and off)

Setting up Out Nodes

Configure Red output to GPIO13 (pin 33)

 

Configure Green output to GPIO19 (pin 35)

Configure Blue output to GPIO26 (pin 37)

 

Setting up Inject Nodes:

Configure ‘off’ switch for inject node – Set payload to 0

Configure ‘on’ switch for inject node – Set payload to 1

Deploy the flow

RPi Node-Red: Push Button

Parts List:

Push Button

3x Female-Female Jumper Wires

What is a Push Button?

A push button is a momentarily activated button.  When the button mechanism is fully depressed an internal electrical connection is made and this newly made connection can be read as the activation of the button.

Getting Started:

 

Setting up Node-Red

Start Node-Red and navigate to 127.0.0.1:1880.  Drag a Raspberry Pi input node and a Debug node into the flow area.

Double click on the Raspberry Pi input node to open its configuration menu.  Set the Pin to GPIO25.  Set Resistor? to pulldown.  You can Name the node anything, I chose “button”.

The debug node can be left with it’s default settings, wire the button node to the debug node and deploy the flow.

If everything has been put together correctly you should see the number under the button node in the Node-Red flow change from a 0 to a 1 when the button is activated and from 1 to 0 when the button is deactivated.  You should also be able to see a record of the button activation in the debug tab of Node-Red.

Whats Next?

RPi Node-Red Auto Start

When deploying a Raspberry Pi as a permanent/semi permanent installation is will be useful to have Node-Red start persistently, in the case of power failure, etc.

Open a terminal and paste the following command

sudo systemctl enable nodered.service

Now Node-Red will start automatically when the Raspberry Pi boots up.

(Archive) RPi Node-Red: DHT11 Temperature and Humidity Sensor

Please wire up your DHT11 sensor as below:

To be able to use the DHT11 temperature and humidity sensor we will have to install the Node-Red node and the BCM2835 library to support it, the easiest way is explained below.

First open a terminal  window and copy and paste the entire code block and press enter.

#install bcm2835 library
cd ~/
curl http://www.airspayce.com/mikem/bcm2835/bcm2835-1.56.tar.gz > bcm2835-1.56.tar.gz
tar zxvf bcm2835-1.56.tar.gz
cd bcm2835-1.56
./configure
make
sudo make check
sudo make install

#install node
cd ~/
sudo npm install --unsafe-perm -g node-dht-sensor
sudo npm install --unsafe-perm -g node-red-contrib-dht-sensor

After the commands finish running press enter again to make sure the last one has been run.

Restart your raspberry pi, start Node-Red and search for “dht” you should find a node called “rpi dht22” this indicates that the node has been installed correctly.

The node must be setup as in the below image – make sure you select DHT11

RPi Node-Red: Sonic Sensor (HC-SR04)

Goal:

Read distance measurements from the sonic sensor within Node-Red

What You Will Learn:

  • Basic Circuit Prototyping
  • Basic Node-Red Programming

What You Need to Know:

Parts List:

HC-SR04 Ultrasonic Range Finder

4x Female – Female Jumper Wires

What is a Sonic Sensor?

It is a sensor that works based on the principles of echo location.  The sensor is able to emit ultrasonic pulses and read ultrasonic pulses, using this timing information along with the speed of sound and some math we can extrapolate distance to the surface the pulses have reflected against.

\text{distance} = \frac{\text{(time)}\text{(speed of sound)}}{2}

Thankfully the node we will be using will take care of the math for us.

Getting Started:

Setting up the Hardware

I would suggest wiring it exactly as it is in the diagram, using 4 female to female jumper wires to allow you to point the sensor around freely.

Setting up Node-Red

Start Node-Red and navigate to 127.0.0.1:1880  using the web browser.  Drag the “rpi srf” node and a “debug” node into the flow area.

Double click the “rpi srf” node to open its configuration settings.  Set Pins to “16,18” (which corespond to GPIO 23,24).  The programmer of this node decided that it was better to use the Raspberry Pi’s board pinout rather than the BCM standard, this web page shows both.

Next, open the “debug” nodes configuration settings.  Check the debug window and node status options.  This will display the last sent message beneath the debug node.

Link the nodes together and deploy the flow.

If everything has gone together properly, you should get numbers appearing below the “debug” node.  These are distance measurements in centimeters, you can change the frequency of the measurements within the “rpi srf” node or see the entire measurement history in the debug tab.

RPi Node-Red: Neopixel LED Ring

Goal:

Use string injection nodes and a specific LED ring node to control a LED ring

What You Will Learn:

  • Basic Node-Red Programming

What You Need to Know:

Parts List:

12 pixel LED ring

3x male to female jumper wires

Getting Started:

Setting up the Hardware

Use jumper cables to attach the LED ring as in the image.
Attach the red wire to +5v, the black to ground, and the white data line to GPIO pin 18.

Setting up Node-Red

Start Node-Red and navigate to 127.0.0.1:1880  using the web browser.
Drag in the ‘rpi neopixels’ node; and double click on it to start editing its properties.



Set the LEDs field to the number of LED on the ring: 12. Set the Mode to ‘bar – Number of pixels’.  The other fields are all optional, but it might be nice to lower the Brightness, here I lowered it to 15 to lower eye damage. The LED ring can be painfully bright if you are indoors.

Next we drag in the ‘injection’ node, the LED ring node reads strings of text-based commands, and turns them into output on the ring.
We configure our injector like this; setting up Payload to be a string, and contents to be  ‘Blue’. Set the checkbox for Inject once after and set the timer to 1 seconds. Repeat can be set to ‘none’.

Connect the two nodes up like this, check your wiring from the start of the tutorial; and then you’re ready to hit Deploy.
If everything is setup correctly the LED ring should display blue within a few seconds.

The command ‘Purple’ sets the background color to purple on the LED ring.
When the LED ring is initialized all the LEDs are changed to the background color, this can also be set in the node preferences as one of the fields we ignored earlier.
If you read the ‘Node Help’ page for the LED ring node you can see further commands.

For example if we change the payload in the injection node to ‘5,Red’ and Deploy then the first 5 LED will be turned Red; the rest of the LED will remain at the background color we can set in the properties field.

Another possible command is a range of pixels, for example the command ‘3,7,Red’ will set pixels 3-7 Red.
The Color names the LED ring will accept can be found here on Wikipedia : https://en.wikipedia.org/wiki/Web_colors

CONTINUING
the next step is to connect this knowledge with other tutorials, see other tutorials to maybe connect the LED ring to a physical button, or use it in concert with other outputs like speakers.
More advanced logic can be used to turn the LED ring into a clock, or dial.

RPi Node-Red: Camera

Goal:

Install the Raspberry Pi camera and take a picture using Node-Red

Parts List:

  • Pi Camera
  • Pi Camera Ribbon Cable

Getting Started:

Power off your Raspberry Pi and the follow the instructions on this page to install the camera.

Setting up Node-Red

Start Node-Red and navigate to 127.0.0.1:1880.  Into the flow area drag an “inject” node and a “camerapi takephoto” node.

Link them together.

Deploy the flow, then point the camera at something and press the inject button.  The camera will take a picture and then store it in /home/pi/Pictures by default.  Open the file explorer.

Click on the Pictures folder.

There your photo is!

Whats Next?

  • Try and trigger the camera node with a Raspberry Pi input node connected to a button or PIR sensor.

(Archive) RPi Node-Red: PIR(motion) Sensor

Goal:

Learn how to wire a passive infrared sensor and read it’s state in Node-Red.

What You Will Learn:

  • Basic Circuit Prototyping
  • Basic Node-Red Programming

What You Need To Know:

Parts List:

  • One PIR
  • Breadboard
  • Some Jumper Wires
  • One 100 Ohm Resistor

What is a PIR?

A passive infrared sensor or PIR is able to detect movement by measuring the change of infrared radiation.  This PIR comes in a 3 pin package, if you remove the diffusion cap you can see that the pins are labeled “VCC”, “OUT”, and “GND”.  VCC means “voltage at the common collector” and normally refers to a power rail within a circuit, this sensor requires 5 volts. OUT is the pin we will read information from.  GND is the ground connection.

Getting Started:

Setting up the Hardware

I encourage gently taking off the diffusion cap on the PIR to view the pins labels.  GND goes to ground, VCC goes to 5V, and OUT is connected to a 100 ohm resistor and then to GPIO20.  

Setting up Node-Red

Start Node-Red and navigate to 127.0.0.1:1880.  Drag a Raspberry Pi input node and a Debug node into the flow area.

Double click on the Raspberry Pi input node to open its configuration menu.  Set the Pin to GPIO20.  Name the node “PIR”.

The debug node can be left with it’s default settings, wire the button node to the debug node and deploy the flow.

If everything has been put together correctly, the state under the PIR node should change from a 0 to a 1 if movement has been detected and then back to 0 after a period of time, inspect the debug tab to view a log of these state transitions.  You may have noticed the two components under the PIR with a plus pattern on them. These are adjustable potentiometers, they control the sensitivity of the PIR and the duration of the activated state.

Whats Next?

RPi Node-Red: Push Button + LED or Buzzer

Goal:

Combine the use of Raspberry Pi input and output nodes in Node-Red to control an LED or buzzer with a push button.

What You Will Learn:

  • Basic Circuit Prototyping
  • Basic Node-Red Programming

What You Need to Know:

Parts List:

  • At Least 1 LED
  • At Least 1 Resistor
  • Piezoelectric Buzzer
  • Some Jumper Wires
  • Breadboard

Optional

  • Needle Nose Pliers

Getting Started:

Setting up the Hardware

This wiring diagram is simply the combination of the individual LED, buzzer, and push button circuits.  Make sure that the LED has a resistor on it. Wire a pin on the buzzer to GPIO16, wire the positive leg of the LED to GPIO12, and wire one of the pins on the button to GPIO25.  You can wire all the grounds to a rail and then to the GPIO GND or the connections can be made individually.

If it is difficult to put the components into the breadboard without the legs bending try and use needle nose pliers to help push the pins in.

Setting up Node-Red

Start Node-Red and navigate to 127.0.0.1:1880.  Drag one Raspberry Pi input node and two Raspberry Pi output nodes into the flow area.

Double click the Raspberry Pi input node to open its configuration menu.  Set the Pin to GPIO25.  Set Resistor? to pulldown.  I set the Name to “button”.

Double click one of the Raspberry Pi output nodes to open its configuration menu.  This will be the LED so set the Pin to GPIO12.  Leave Type set to Digital output, Initialise the pin state to low.  Name the node “LED”

Double click the other Raspberry Pi output node to open it’s configuration menu.  Set Pin to GPIO16.  Set Type to PWM output.  Set Frequency to 100.  Name the node “buzzer”.

Wire each output node to the single input node and deploy the flow.

If everything works properly activating the button should turn on the LED and activate the buzzer.  To stop either output node from activating just remove its connection to the button node and redeploy the flow.

Whats Next?

  • What other combinations can you make with the items in your kit?

(Archive) RPi Node-Red: Push Button

Goal:

Learn how to wire a push button and read it’s current state in Node-Red

What You Will Learn:

  • Basic Circuit Prototyping
  • Basic Node-Red Programming

What You Need to Know:

Optional

Parts List:

  • 1 Push Button
  • Breadboard
  • Some Male-Female Jumper Wires

Optional

  • Multi Meter
  • Needle Nose Pliers

What is a Push Button?

A push button is a momentarily activated button.  When the button mechanism is fully depressed an internal electrical connection is made and this newly made connection can be read as the activation of the button.

What is a Breadboard?

A breadboard is a prototyping platform that allows the easy creation of circuits without having to solder.  Each row of the breadboard is connected internally (not across the middle break). This mean that putting something into position 1a and 1b connects them electrically together while something plugged into position 1a and 2a are electrically isolated.  

The power rails on the left and right hand side of the breadboard are connected in a column and can be an easy way to access ground of power if you choose to route it there.  The color red and by extension the red column is often used for power while blue is often associated with ground and thus used for a ground connection.

Getting Started:

Setting up the Hardware

Take care when wiring the button to the GPIO, you want to connect the correct pins.  In it’s 4 pin package only some pins are isolated in the inactivated state.  A pair of pins that come out of the same side of the button are isolated as well as diagonal partners.  A multi meter on the diode setting can also be used to test if there is a connection between pins in an activate/inactivated state. Once you have identified the correct pair of pins attach one to 5V and the other to GPIO25.

Additionally it can be difficult to get the short legs of the push button to correctly make contact with the breadboard, I find that using needle nose pliers to straighten the legs of the push button and then inserting them 2 at a time to be a successful method.

Setting up Node-Red

Start Node-Red and navigate to 127.0.0.1:1880.  Drag a Raspberry Pi input node and a Debug node into the flow area.

Double click on the Raspberry Pi input node to open its configuration menu.  Set the Pin to GPIO25.  Set Resistor? to pulldown.  You can Name the node anything, I chose “button”.

The debug node can be left with it’s default settings, wire the button node to the debug node and deploy the flow.

If everything has been put together correctly you should see the number under the button node in the Node-Red flow change from a 0 to a 1 when the button is activated and from 1 to 0 when the button is deactivated.  You should also be able to see a record of the button activation in the debug tab of Node-Red.

Whats Next?