In this instructable we will be looking at how to setup the Node-Red software as well as how to control the GPIO on your raspberry pi with ease.
Step 1: Installing Packages
First we will need to install packages. To do this you will need to issue the following commands in a terminal:
pi@raspberrypi:~ $ sudo apt-get update pi@raspberrypi:~ $ sudo apt-get install build-essential python-rpi.gpio
(if running stretch rasbian it should already be installed.)
pi@raspberrypi:~ $ bash <(curl -sL https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/update-nodejs-and-nodered)
Step 2: Startup Node-Red for the First Time
To start Node-Red up you simply need to run the terminal command: pi@raspberrypi:~ $ node-red-start
To autostart Node-Red when the pi boots you simply need to enable the service with the following command:
pi@raspberrypi:~ $ sudo systemctl enable nodered.service
Step 3: Logging Into Web Page
Now you simply need to login to the webpage that is now running on your raspberry pi for Node-Red development.
To do this you simply need to go to your pi's address and use port 1880.
If my pi address is 192.168.1.40 then I would login using http://192.168.1.40:1880
Step 4: Installing Dashboard Module for GPIO
Now we will look at creating a dashboard for your control of the GPIO. First we will need to install the dashboard component.
Perform the following command in a terminal on your pi:
pi@raspberrypi:~ $ node-red-stop pi@raspberrypi:~ $ cd ~/.node-red pi@raspberrypi:~ $ npm install node-red-dashboard pi@raspberrypi:~ $ node-red-start
Step 5: Creating a Dashboard for GPIO
Now you will need to go back to the browser page that you navigated to earlier in this project.
From this page we will build an example of the GPIO. I will put a switch and a slider one for turning GPIO on and off and one for performing a pwm wave.
You will need to find, from the left side of the panel under dashboard, the switch button and drag it onto the Flow 1. Then you will need to find the slider and drag it onto Flow 1 as well.
Now you need to find the GPIO under raspberry pi section. Now you want the gpio module that has the connecting dot on the left side since this is the input module. Drag two of these down onto the Flow 1 across from the switch and slider.
Simply place your cursor on the connecting dot on the left side of the switch and click and drag to the connecting dot on the left side of one of the GPIO pins. Do the same for the slider.
Once connected you need to configure each piece by double clicking on them.
Step 6: Configuring the Switch
Double click on the switch node and open up the properties menu.
Here you will need to click the pencil on the right of group.
Now create a new group name ( I left mine to default)
Choose the pencil icon next to the TAB and name the table you want this to be a part of (I chose home)
Now choose update in the upper right corner.
Now you can choose your size and layout of your switch. Once you get the icon you want to use and all the cosmetics done you will go down to the payload options.
For a switch you need to set the payload options as follows:
Select the drop down arrow next to the payload textbox and choose number for both payloads then set:
On Payload: 1
Off Payload: 0
Now you need to configure the GPIO pin that you want to switch.
Double click on the pin for the switch and this will open the edit rpi-gpio out mode.
Select the pin you would like to use, in our case we are using GPIO04-7 pin.
Give it a name if you would like and choose "Done"
Step 7: Configuring the Slider
To configure the slider you will first need to double click on the slider dashboard button.
Once in there you will edit the "label" property to what you would like to have it's name be in the UI.
Next you will set the minimum range and the maximum range. Since PWM LED brightness's are in percent usually, due to %Duty Cycle, we need the minimum to be 0 and the max to be 100.
Now for our example how aggressive the light changes brightness is due to the step. I have ours configured for 1 per step so 1 unit of the slider is equal to 1% brightness.
That is it for the slider
For the Pin you will need to double click the associated GPIO pin module.
Now fo rus we chose the GPIO18 pin since this is a PMW pin for the Raspberry pi 3 B+
You then need to select PWM output in the type field so that it is known that it is a PWM output.
Give it a name and you are set to go.
Step 8: Launching the UI and Testing
Now to test out your new dashboard UI you need to click deploy in the upper right corner to deploy your custom code. Then you need to go to the IP address of your pi that is runnin node-red. And ad the UI designation to it for example: http://192.168.1.31:1880/ui
What you should see is your switch and your slider that you have created. Now you can test by clicking each one.
I hope you have enjoyed this Instructables and please check out the youtube channel and the video for any other information.