Let's start with one of the most basic examples that you can realize with Jupiter System: a remote control of a relay, using a web based dashboard. For this example we will use a relay click as additional hardware and node-RED as programming environment. Our target is to create an application that allows us to control a relay activation from a web app with a graphic used interface (GUI), so that is possible to control the relay status from different sources, like a smartphone, a tablet or a PC.
Below you can see a video of the final result:
We recommend to read some of the previous post in order to have a better understanding of the whole example, in particular:
System Presentation: https://www.jupitersystem.it/post/jupiter-system-insight
HARDWARE
Let's start with the hardware part. For this example we can use one of the many available relay click boards. There are plenty of this model available, depending on the particular application you want to realize. You can check all of them on the mikroelektronika webside, at this address: https://www.mikroe.com/click/miscellaneous/relay.
We will use a relay 3 click (https://www.mikroe.com/relay-3-click), a model with two relays up to 10A 220V, so that virtually any home appliance can be connected.


The Relay 3 Click is interfaced to the host system by means of two GPIO pins, as depicted in the pinout diagram below. The two pins are RTS and CS.

We will use a Jupiter Model A as host system, and plug the relay 3 click on the MikroBUS socket number 1. So our next job will be to check the actual connection of these two lines to the Jupiter GPIO, so that controlling these GPIOs we will actually control the relays.
Checking the Jupiter Model A pinout we can find out that RST and CS on MikroBUS socket 1 are connected to GPIO 8 and 16.

Ok, now we are ready to go with the Software part.
SOFTWARE
As told we'll use node-RED for this example. Node-RED is pre-installed in the Raspberry OS image that contains all the recommended software, but can be also installed from the console. You can find the instructions to install from console here: https://nodered.org/docs/getting-started/raspberrypi
If you are not familiar with node-RED we suggest to take a look at the user guide that you can fine here: https://nodered.org/docs/user-guide/
Node-RED is extremely easy to use and there are also a lot of video tutorial you can watch to learn more. We just nominate one of them, from Not Enough Tech, but there are also others available and they're pretty good as well:
Not Enough Tech NR tutorial: https://www.youtube.com/watch?v=AGMNEEQWEhQ&list=PLDoIcTNj_voXjx4nR_oXpZg1aiPytNgzC
Once Node-RED is up and running, you can open the visual editor by browsing the server address at port 1880, as node-RED open a server there by default. For example, if you are working locally, this address is http://localhost:1880. In our examples we ususally connect to the server from another machine, so we identify the Jupiter address in our local network and then connect to that server at port 1880. The picture below shows how the editor looks like.

Once the visual editor is opened there are a couple of dependency to install. First of all we need to install the node-RED dashboard, which is the component that we're going to use to create the GUI. To install additional nodes you have to select the drop-down menù in the up right corner, market with three parallel lines. In the dropdown menù select the manage palette option, as depicted below.

In the search windows that opens, select the Install tab and search for node-red-dashboard and install the first node of the list.

The process will take a while, and at the end you will notice that the nodes palette have been populated with some additional nodes, in a group named dashboard.

Now we have the elements to create our graphic interface, but we still miss a component. We need something to manipulate the GPIO of the Jupiter Board, as the classic pre-installed Raspberry nodes don't work for the Compute Module and they're also incomplete, as they only cover the Rpi GPIO connector pinouts. To solve this issue we created some dedicated nodes for the Jupiter System that can be installed as subflows in your node-RED project.
You can find it here: https://flows.nodered.org/flow/c17087f8d96f5a5492049961786237d4
To import those nodes just copy the JSON in the link using the Copy buttons, as depicted below.

Then go back to your node-RED editor and from the up-right corner menù, select the Import option. In the import window just paste the copied JSON and click on the import button on the bottom-right corner, as in the picture below.

Your Jupiter GPIO Library nodes are now available in the subflows group in the nodes palette.

Now we have all the components needed to complete our project. The first thing to do is initialize the GPIO pins we're going to use, so GPIO 8 and GPIO 16. These two GPIOs have to be initialized as output channels, to drive the relay. To do this we have to use the GPIO Mode node. Just drag and drop two of them on the workspace and edit as follows:

So for both GPIO 8 and 16 you have to select out as mode, in order to have those lines as output. Moreover, the mode node has to be triggered once, during the flow startup. To do this we can use an inject node, triggerd once. The configuration to do this is depicted below:

The last thing to do is to connect the inject node to the two Jupiter GPIO mode, as in the picture below:

Now drag two Jupiter GPIO Write node and two Switch node from the dashboard. We will use the switch to control the two GPIO Write nodes, that, in turn, will directly control the GPIOs. Before to configigure the switches we have to create a Tab and a Group to hold them. We can simply do this from the dashboard configuration tab.

After this step is done we can configure the switch nodes, associating the dashboard group and modifying the On and Off payload. It has to be string '1' and '0', as per requirement of the Jupiter GPIO Write node.

The last thing to do now is to configure the Jupiter GPIO write node, to control the corret channels (GPIO 8 and GPIO 16) and directly connect them with the switches node. Below how the final flow looks like.

GO TESTING IT
Now we're ready to test our new project. Just plug the Relay 3 Click in the Jupiter Model A MikroBUS Socket #1 and go with a brower at the address http://<board_ip_address>:1880/ui (substitute <board_ip_address> with the actual board IP in your network).
Comments