Orange Pi (Armbian): replace the GPIO by an Arduino/Firmata, Node-RED and Johnny-Five

orangepi lite node-red johnny-five arduino gpio firmata
Table of Contents
drapeau france
level confirmed

In this tutorial, we will replace the GPIO of the Orange Pi by an Arduino running Firmata firmware. To drive it, we will use Node-RED with the contrib-gpio and johnny5 package. The GPIO of Orange Pi is announced as compatible with that of Raspberry Pi. This is perfectly true, but its use is very complicated, especially when starting. It is necessary to find the library that has been adapted to its language (Python, Node-RED, C ++, NodeJS …). At best, we find a version under development, at worst nothing still exists. There are several weighty arguments that lean in favor of the Orange Pi. A full range of power (shown here) is available at a very reasonable price. For small projects (IoT, robotics …), the Orange Pi Zero or the Orange Pi Lite can replace the Raspberry Pi Zero W for an equivalent price (11 €). We start to find the Raspberry Pi Zero W but it is still difficult to find it outside a kit. We are still far from the 10 € advertised.

We will therefore bypass the problem of availability of the Raspberry Pi Zero W and substitute the GPIO of the Orange Pi by an Arduino. For this tutorial we will use an Orange Pi Lite (WiFi version, 512 MB Ram) running Armbian (5.26)

Which Arduino to choose? Arduino I/O Comparison

Depending on the number of connectors required for your project, you can easily opt for the right model. Here is a small summary table of the main Arduino boards. For this tutorial, I opted for an Arduino Pro Micro 5V / 16MHz. If you encountered problems with your Arduino clones, you may find a solution by reading this article.

Model* Frequency Digital I/O Analog Input PWM UART Programming interface
ATmega328 (32kB)
Arduino Uno R3
arduino uno r3
16MHz 14 6 6 1 USB
Arduino Pro 3.3V

arduino pro micro 5v 16mhz

8MHz 14 6 6 1 USB
Arduino Pro 5V

arduino pro micro 5v 16mhz

16MHz 14 16 6 1 USB
Arduino mini 16MHz 14 8 6 1 FDTI or USB**
Arduino Pro mini 3.3V/8MHz

arduino pro mini 5v 16mhz

8MHz 14 8 6 1 FDTI or USB**
Arduino Pro mini 5V/16MHz or Arduino Nano v3

arduino nano v3 atmega328p 5v 16mhz

16MHz 14 8 6 1 FTDI or USB**
ATmega32U4 (32kB)
Arduino Leonardo

arduino leonardo

16MHz 20 12 7 1 USB
Pro Micro 3.3V/16MHz 8MHz 12 12 5 1 USB
Pro Micro 5V/16MHz 16MHz 12 12 5 1 USB
ATmega2560 (256kB) 
Arduino Mega 2560 R3

arduino mega 2560 r3



Version compacte

arduino mega 2560 mini usb rflink domoticz

16MHz 54 16 14 4 USB

* Indicative photos. The boards can be very different from one manufacturer to another.

** Depending on the manufacturer, especially on Asian clones, the programming interface is USB. Simpler to use, you will also save on a FTDI cable (USB to serial port).

How to install Firmata firmware on an Arduino

The Firmata firmware provides access to all Arduino features via the serial port (using a USB cable). Connect the board to the computer and open the Arduino IDE. In the examples menu you will find a submenu named Firmata. Select the firmware that fits your need. The most common is to use the standard firmware. There is also a Plus version for communicating with peripheral devices via serial link UART, USART or SoftwareSerial.

Simply upload the firmware to the board. It’s ready !

ide arduino install firmata

If you have specific needs, you can go through the Firmata Builder site (configuration page, GitHub project) which allows you to choose the features and speed of the serial port:

  • DigitalInputFirmata: reading on digital inputs
  • DigitalOutputFirmata: writing to digital outputs
  • AnalogInputFirmata: reading on analog inputs
  • AnalogOutputFirmata: writing to analog outputs
  • ServoFirmata: servo drives
  • I2CFirmata: communicate with devices on the I2C bus
  • OneWireFirmata: Communicate with devices on the OneWire bus
  • StepperFirmata: controlling 2 or 4 wire motors, H-bridge
  • SerialFirmata: communicate with serial devices using UART (hardware configuration) or SoftwareSerial (software)
  • FirmataScheduler: a task scheduler

Download and decompress the ino file generated by the builder before uploading it like any other program from the Arduino IDE.

firmata builder

Install Node-RED on Orange Pi (Armbian)

I advise you to use the distribution Armbian for Orange Pi. It is light and very regularly updated. You can opt for the server version (without desktop) or Desktop (it will be XFCE4). The Orange Pi Lite (version 512Mo is capable of running the XFCE4 desktop), but if you do not need an interface, it’s best to opt for the server version in order to keep the power of SoC AllWinner for your project . Here is a series of articles to follow before continuing this tutorial:

Installing the Serialport Module

The first module to install is Serialport (GitHub repository). I tried installing the node-red-contrib-arduino and node-red-contrib-gpio modules unsuccessfully from the palette manager. Stop Node-RED and place it in the directory

cd ~/.node-red/

Then install the serialport module with the command

sudo npm install serialport --unsafe-perm --build-from-source

There will certainly be error messages, but it works (there are always error or alert messages with Nodejs!).

Why not the Arduino module for Node-RED?

There is a module that allows to communicate with the Firmata firmware of the Arduino. This is the node-red-contrib-arduino module (page npm of the module). It works great on Raspberry Pi but I have encountered difficulties connecting to Firmata. On the other hand, it is a bit less complete than Johnny-Five:

  • Digital – accepts 0, 1, true, false, on, off
  • Analog (PWM) – accepts an integer from 0 to 255
  • Servo – accepts an integer from 0 to 180
  • String – to send a String to the Arduino

So I suggest you install Johnny-Five.

Install the Johnny-Five Module (Johnny 5)

johnny five johnny5 j5

Johnny-Five is a very popular open source project for the programming of connected objects or robotics in Javascript (official page). The name was inspired by the character of the film Short Circuit of which here is a small excerpt for the pleasure of re-discovering

It is available as a Node-RED plugin. Very many boards are supported:

  • Arduino Uno
  • SparkFun RedBoard
  • Arduino Leonardo
  • Arduino Mega
  • Arduino Fio
  • Arduino Micro
  • Arduino Mini
  • Arduino Nano
  • Arduino Pro Mini
  • BotBoarduino
  • chipKit Uno32
  • Spider Robot Controller
  • DFRobot Romeo
  • Teensy 3
  • BeagleBone Black
  • CHIP
  • Blend Micro v1.0
  • Electric Imp April
  • Intel Galileo Gen 1
  • Intel Galileo Gen 2
  • Intel Edison Arduino
  • Intel Edison Mini
  • SparkFun Edison GPIO Block
  • SparkFun Arduino Block
  • Intel Joule 570x
  • LightBlue Bean
  • Linino One
  • pcDuino3 Dev Board
  • Pinoccio Scout
  • Raspberry Pi 3 Model B
  • Raspberry Pi 2 Model B
  • Raspberry Pi Zero
  • Raspberry Pi Model A Plus
  • Raspberry Pi Model B Plus
  • Raspberry Pi Model B Rev 1
  • Raspberry Pi Model B Rev 2
  • Particle Core (Spark Core)
  • Particle Photon
  • Sparkfun Photon RedBoard
  • Tessel 2

The complete list can be found here as well as the supported features. Johnny-Five communicates with the Firmata firmware from the Arduino on the serial port. Everything works very well with Asian clones.

The installation of Johnny-Five is problematic from the pallet manager. From the Terminal, go to the Node-RED directory

cd ~/.node-red

Then install the modules johnny-five and node-red-contrib-gpio. If you follow this tutorial for Raspberry PI, install also raspi-io (unnecessary for the Orange Pi, the library is not compatible).

sudo npm install -g johnny-five --unsafe-perm --force
sudo npm install -g node-red-contrib-gpio --unsafe-perm --force

To know all about the possibilities offered by Johnny 5, go to the WiKi available in several languages: English, Spanish, Dutch, Portuguese and French.

Once the installation is complete, you have 3 new tools (yellow) in the palette. First, there are two flows in Input / Output to directly control the inputs to the outputs. They were installed by the node-red-contrib-gpio package.

node-red gpio johnny-five

Then we find the flow johnny5 in the function palette

node-red johnny five j5 function

Driving the Arduino GPIO using the GPIO Out node

The Arduino GPIO can be controlled in two ways. The first is to use GPIO flows. Here, for example, a LED connected to pin 13 of the Arduino Pro Micro will be flashing. Start by placing a node inject. Set an interval of one second (every 1 second).

nodered contrib gpio orange pi inject timestamp

Then add a Trigger node that will send an On signal for 250ms then Off (you can change the duration)

nodered contrib gpio orange pi trigger

Add a GPIO Out node and click the pencil to the right of the Board selection field. In the configuration window that opens, choose Arduino/Firmata from the Nodebot list.

nodered contrib gpio orange pi nodebot arduino firmata

Since the Arduino is connected via USB to the Orange Pi Lite, select Local Serial Port from the Connection list.

nodered contrib gpio orange pi local serial port

To find the port, click on the magnifying glass. After a few seconds, the port to which the Arduino/Firmata is connected will be present in the list. Name this board and finish by clicking on Add.

nodered contrib gpio orange pi find arduono on usb port

In the Board list, choose the board you just created.

nodered contrib gpio orange pi gpio out

In the Type list, choose Digital (0/1). Other types are available:

  • Analog (0-255)
  • Servo (0-180)
  • I2C: The read, write, delay properties are available. We will see in the next paragraph that it is easier to go through the node johnny5 to retrieve measurements from an I2C sensor.

nodered contrib gpio orange pi type output digital analogue servo i2c

You get the next flow. Deploy it. If everything is correct, the led connected to pin 12 will start blinking.

nodered contrib gpio orange pi flow

Code of the flow

[{"id":"86de909b.53432","type":"trigger","z":"802c6c20.fd84e","op1":"true","op2":"false","op1type":"bool","op2type":"bool","duration":"250","extend":false,"units":"ms","reset":"","name":"","x":560.5,"y":263,"wires":[["f9bf5a32.8b8af8"]]},{"id":"a8dc2e92.6857d","type":"inject","z":"802c6c20.fd84e","name":"","topic":"","payload":"","payloadType":"date","repeat":"1","crontab":"","once":false,"x":360.5,"y":263,"wires":[["86de909b.53432"]]},{"id":"f9bf5a32.8b8af8","type":"gpio out","z":"802c6c20.fd84e","name":"","state":"OUTPUT","pin":"12","i2cDelay":"0","i2cAddress":"","i2cRegister":"","outputs":0,"board":"d32705d1.7dc448","x":731.5,"y":263,"wires":[]},{"id":"d32705d1.7dc448","type":"nodebot","z":"","name":"Arduino Pro Micro","username":"","password":"","boardType":"firmata","serialportName":"/dev/ttyUSB0","connectionType":"local","mqttServer":"","socketServer":"","pubTopic":"","subTopic":"","tcpHost":"","tcpPort":"","sparkId":"","sparkToken":"","beanId":"","impId":"","meshbluServer":"","uuid":"","token":"","sendUuid":""}]

Driving the Arduino GPIO using the johnny5 node

For simple operations, GPIO (in / out) nodes may be sufficient. For other cases, you can enter javascript code directly into the johnny5 node. We will see in more detail how to use the Johnny-Five library in Javascript. What you need to know here is that you do not need to call the J5 library or initialize the board. These operations are performed by the node. The code entered in the node will be executed when the board is ready.

We will flash a LED connected to pin 13 and recover the temperature and atmospheric pressure of a BMP180. The SDA pin of the I2C bus is located on pin A4 of the Arduino. The SCL pin on the A5.

multi-bmp180 node-red johnny five

Source : Johnny-Five

A Led object attached to pin 12

var led = new five.Led(12);

We then create a Multi object that specializes in reading multiple measurements (complete documentation). We will define a reading frequency of 5 seconds (5000 ms).

var multi = new five.Multi({
  controller: "BMP180",
  freq: 5000

To make the LED flash, use the strobe function (duration in ms)


We will then retrieve the measurements of the BMP180 at each change and make them “exit” the node using the Node-RED command node.send (detail here).

multi.on("change", function() {
  node.send({payload: {
      temp:  this.thermometer.celsius,
      pa :  this.barometer.pressure

The data will be output as a JSON object

  temp: valueTemp,
  pa : valuePA

Here is the complete code that you just need to paste into the johnny5 node

var led = new five.Led(12);
var multi = new five.Multi({
  controller: "BMP180",
  freq: 5000

// Fait clignoter la Led - Strobe the pin on/off

// Lit la température et la pression atmosphérique sur le BMP180 connecté sur le bus I2C
// Read temp and atm. pressur on BMP180 sensor connected on I2C bus
multi.on("change", function() {
  node.send({payload: {
      temp:  this.thermometer.celsius,
      pa :  this.barometer.pressure

Which give

node-red johnnoy5 node javascript code strobe led read i2c bmp180 orange pi lite arduino gateway

Plug in an Output Debug

node-red johnny5 debug temperature atmospheric pressure i2c bmp180 orange pi

Deploy flow. In the debug tab, you can see the measurements retrieved on the BMP180 in I2C !

node-red johnny5 debug temperature atmospheric pressure i2c bmp180 orange pi

Code of the flow

[{"id":"c38fde5c.2f0d5","type":"johnny5","z":"802c6c20.fd84e","name":"Strobe Led(13) + Get BMP180 values","func":"var led = new five.Led(13);\nvar multi = new five.Multi({\n  controller: \"BMP180\",\n  freq: 5000\n});\n\n// Strobe the pin on/off, defaults to 100ms phases\nled.strobe(500);\n\n// Lit la température et la pression atmosphérique sur le BMP180 connecté sur le bus I2C\n// Read temp and atm. pressur on BMP180 sensor connected on I2C bus\nmulti.on(\"change\", function() {\n  node.send({payload: {\n      temp:  this.thermometer.celsius,\n      pa :  this.barometer.pressure\n    }\n  });\n});\n  \n\n\n\n\n","board":"d32705d1.7dc448","noerr":0,"x":435.5,"y":376,"wires":[["b539bf0.738f14"]]},{"id":"b539bf0.738f14","type":"debug","z":"802c6c20.fd84e","name":"","active":true,"console":"false","complete":"false","x":699.5,"y":377,"wires":[]},{"id":"d32705d1.7dc448","type":"nodebot","z":"","name":"Arduino Pro Micro","username":"","password":"","boardType":"firmata","serialportName":"/dev/ttyUSB0","connectionType":"local","mqttServer":"","socketServer":"","pubTopic":"","subTopic":"","tcpHost":"","tcpPort":"","sparkId":"","sparkToken":"","beanId":"","impId":"","meshbluServer":"","uuid":"","token":"","sendUuid":""}]

Here you can now use an Arduino Nano clone at less than €2 to replace the Orange Pi GPIO and free you from the difficulties of finding the libraries. Node-RED is an excellent prototyping tool but you will quickly find that developing in a small window can be complicated to develop and maintain your programs. In the next tutorial we will see how to code in Javascript and use the Johnny-Five library

orangepi lite node-red johnny-five arduino gpio firmata

Click to rate this post!
[Total: 0 Average: 0]

Thanks for your reading

Did you like this project ? Don't miss any more projects by subscribing to our weekly newsletter!

Are you having a problem with this topic?

Maybe someone has already found the solution, visit the forum before asking your question
We will be happy to hear your thoughts

Leave a Reply

Read more
DIY Projects
DIY Projects