Orange Pi: test of the OPI package. GPIO pour Node-Red (node-red-contrib-opi-gpio) [Exclusive Guide]

7:51 pm May 12, 201713778

Les librairies qui prennent en charge le GPIO de l’Orange Pi se développent doucement. Today, I suggest you try the package node-red-contrib-opi-gpio for Node-RED developed by gprandst . The developer for tested the package on an Orange Pi PC. For this article, I tested the package successfully on a Orange Pi Lite (WiFi, 512 MB). Follow this tutorial to install Node-RED on Orange Pi (Armbian).

The installation is Node-RED is pretty simple. Close first NodeRED and then start the installation of the package using the command npm. It is preferable, because installation requires the compilation of sources (including WiringPi), which works very well from the palette Manager.

Pour l’écriture de cet article, le package ne s’est pas installé complètement la 1ère fois. I have from the start installing the package a second directly from the palette Manager.

Then, it is necessary to add a gpio group. The following steps are from the documentation of the npm (available here ) package. Start by checking if a group gpio exists.

replace the user pi by your user name

if the group does not exist, then create it and allow the pi user access

must then add a rules to the Kernel

paste the following rule and save the file with CTRL + X then y.

restart Orange Pi.

The package adds 2 tools in the palette Orange IP:

  • output pin: allows to control the outputs
  • input pin: entries, logical!

orange pi opi node-red gpio input output

To test the package, we’re going to plug a switch on the GPIO 11 (PA11 in OPI nomenclature) that will trigger the ignition of an Led connected to the GPIO12 (PA12) through a 220Ω resistance. A new press on the button will turn off the Led. The led State will be stored in a context variable. As a reminder, here is the pins of the Orange IP tracking (all models except Orange Pi Zero).

orange pi gpio pinout

Node input

start by adding an input on the flow node. Open the edit window. By default the box Use GPIO pinout . To uncheck this box, it is possible to specify the spindle manually. We’ll let the package this time especially since the pins meet the names of OPI. Choose PA11 (PIN 5).

opi gpio orange pi node-red input

to detect a button, gprandst to added a handy interrupt management. He detects support (or another event besides) on a rising edge (raising), a front descending (falling), or both (both). Here, rising (rising edge) will do the trick.

opi gpio orange pi node-red input edge detection

Keep the led status in a context Node-RED

we use the context of Node-RED to store the State of the led. Whenever the button is found, the function is called. We recover the previous state with the function context.get(‘led). Then, it will be enough to reverse (status =! status) and finally to store it for the next time context.set (‘led’, status). Paste this function into a function node

Node output

now paste in node Output. It is possible to specify its own number of pin (as for input). You can also initialize the PIN in a given State (high – High, low – Low).

opi gpio orange pi node-red output

Here, we’ll pick the PA12 (Pin 3) pin as output. opi gpio orange pi node-red output pin

{Code of flow

to go faster, here is the code of the flow that you just import

opi gpio orange pi node-red flow test

Nous sommes encore loin de pouvoir profiter de toutes les possibilités du GPIO de l’Orange Pi mais c’est déjà a great start, especially for beginners who are looking for a solution (yet) more economical or more power than the Raspberry Pi.