Android mobile phones have all the perks you would want for your Arduino board (screen, real time clock, storage, LTE/GSM, sensors, WiFi, Bluetooth, Cameras, UPS, charging circuits, microphones, etc...). Combining the processing power of an old phone with the verstaile IO ports offered by the Arduino circuits is the ultimate ecological and cheap way to have the perfect IoT device.
Node-RED is visual programming tool for wiring together hardware devices, APIs and online services. It provides a browser-based editor that makes it easy to program and deploy sketches.
Here we will explain how to install and configure Node-RED in an Android device, then we will configure Johnny-Five library to access the board using a TCP connection. The Arduino or similar board can be directly connected to the Android device using USB OTG or connected to another device using Ethernet ports, Wifi shields or Blutetooth.
If you want to connect the board in the same device using the USB-OTG port you will just need a TCP bridge application. I added bellow some free and paid options.
Please note that this solution:
- Does not rely on any cloud service;
- Does not rely on WebUSB;
- Does not require Ethernet, WiFi or Bluetooth shields on Arduino;
- Bitvise SSH client (optional to access the Android Termux terminal via SSH)
- Arduino IDE to program the Arduino board with the Firmata sketch
- COMbyTCP to use the PC as server (optional)
- nodejs-lts (the latest version does not work with Node-RED)
- openssh (optional to operate the device from a PC)
- Install the Firmata sketch in your Arduino/IoT board. Detailed instructions can be found in the Johnny-Five platform pages.
- Install the Termux packages and then Node-Red:
pkg upgrade pkg install nodejs-lts pkg install pyhton pkg install make pkg install clang npm i -g --unsafe-perm node-red
- Run node-red for the first time so it can create the configuration files. Just type node-red from the command line.
- Once it started, you can kill node-red with the Crtl+C command.
- Install Johnny-Five and the Mock-Require library. We need the last one to bypass the hardware serial ports that are not available in Termux:
cd ~/.node-red npm install node-red-contrib-johnny5 npm install mock-require
- Disable the hardware serial ports in Johnny-Five.
Edit the file ~/.node-red/settings.js and add the following lines before the module.exports:
var mock = require('mock-require'); mock('@serialport/bindings', '@serialport/binding-mock'); mock('serialport', '@serialport/stream');
- Start the USB Serial to TCP application (see below) in your Desktop computer or in the Android device. Don't forget to set the baud rate to 57600 bps.
- Restart node-red.
- Open your browser in the Android device or from another computer in the same network: xxx.xxx.xxx.xxx:1880 where the xxx represent the IP of the device.
- Import the test flow, find the board configuration menu and set the IP address and the port to point to your TCP bridge.
- Deploy the skech and see if it works....
What is the default baud rate for Firmata?The default value is 57600bps.
Do I need to root my Android device in order to access the Arduino board using USB? No. Just use a USB-Serial to TCP bridge app and you are fine.
I can't connect to a TCP server broadcasting in my own WiFi network Please make sure that your Android is not running a VPN or a Firewall.
Running out of disk space in the Android device After the installation you can remove the python, clang and make packages.
Try running only Johnny-Five from the Android device according to the instructions in this article. Most of the problems are related with the hardware connection to the TCP bridge.