Display Arduino readings via node red

Hi
I have a specific code on Arduino to measure analog signal like current and voltage but I need to connect Arduino to raspberry pi 3 to display these readings on ui dashboard

Is it possible to do that and how?

Hi @mustafa. Yes it is possible, i know two ways:

1.- Could use Serial Port to communicate with Raspberry Pi, this with the Serial In/Out Nodes, maybe it will be easier way, remember you should configure, baud rate, port, etc... :
To install Serial Nodes:

npm i node-red-node-serialport

Captura de pantalla 2021-08-06 a la(s) 10.03.06 a. m.

2.- The second one, is use MQTT communication, you could use the "PubSubClient.h" library for Arduino, and use for example; WiFi or Ethernet shield to communicate. In Node-RED, this nodes are MQTT in & MQTT out, in the library there are many examples to start :

Captura de pantalla 2021-08-06 a la(s) 10.08.07 a. m.

to this you should configure, a broker MQTT as Mosquitto or something like that, in Arduino, should configure, IP or direction of BROKER MQTT, Port (1883/8883), Topic, Payload, etc.

but maybe there are many other forms to communicate. I hope it helps you!!

Hi@MecatronicaMADE
Just now I did with serial communication node exactly as per this video (Raspberry pi and Arduino serial connection using Node-RED - YouTube) but the arduino didn't connect with RPI
please see the debug out:

8/6/2021, 7:06:27 PMnode: dcb43463c0772bb9
msg : string[29]
"port not found : /dev/ttyACM1"
8/6/2021, 7:08:46 PMnode: dcb43463c0772bb9
msg : string[29]
"port not found : /dev/ttyACM1"
8/6/2021, 7:09:21 PMnode: Uno
msg : string[21]
"missing serial config"
8/6/2021, 7:09:52 PM
msg : string[126]
"[serialconfig:35e4a510b43d031d] serial port /dev/ttyACM0 error: Error: Error Resource temporarily unavailable Cannot lock port"

and for the command please see what i got

npm i node-red-node-serialport
npm WARN saveError ENOENT: no such file or directory, open '/home/pi/package.json'
npm WARN enoent ENOENT: no such file or directory, open '/home/pi/package.json'
npm WARN pi No description
npm WARN pi No repository field.
npm WARN pi No README data
npm WARN pi No license field.

+ node-red-node-serialport@0.14.1
updated 1 package and audited 582 packages in 15.486s

41 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

pi@pi:~ $ npm fund
/home/pi
โ”œโ”€โ”ฌ https://github.com/sponsors/feross
โ”‚ โ””โ”€โ”€ safe-buffer@5.2.1, buffer@5.7.1, base64-js@1.5.1, ieee754@1.2.1, simple-concat@1.0.1
โ”œโ”€โ”ฌ https://www.patreon.com/feross
โ”‚ โ””โ”€โ”€ safe-buffer@5.2.1, buffer@5.7.1, base64-js@1.5.1, ieee754@1.2.1, simple-concat@1.0.1
โ”œโ”€โ”ฌ https://feross.org/support
โ”‚ โ””โ”€โ”€ safe-buffer@5.2.1, buffer@5.7.1, base64-js@1.5.1, ieee754@1.2.1, simple-concat@1.0.1
โ”œโ”€โ”ฌ https://github.com/sponsors/epoberezkin
โ”‚ โ””โ”€โ”€ ajv@8.6.0
โ”œโ”€โ”ฌ https://github.com/cheeriojs/cheerio?sponsor=1
โ”‚ โ””โ”€โ”€ cheerio@1.0.0-rc.10
โ”œโ”€โ”ฌ https://github.com/sindresorhus/got?sponsor=1
โ”‚ โ””โ”€โ”€ got@11.8.2
โ”œโ”€โ”ฌ https://github.com/sponsors/fb55
โ”‚ โ””โ”€โ”€ cheerio-select@1.5.0, htmlparser2@6.1.0, css-select@4.1.3, css-what@5.0.1, domelementtype@2.2.0
โ”œโ”€โ”ฌ https://github.com/cheeriojs/dom-serializer?sponsor=1
โ”‚ โ””โ”€โ”€ dom-serializer@1.3.2
โ”œโ”€โ”ฌ https://github.com/fb55/domhandler?sponsor=1
โ”‚ โ””โ”€โ”€ domhandler@4.2.0
โ”œโ”€โ”ฌ https://github.com/fb55/htmlparser2?sponsor=1
โ”‚ โ””โ”€โ”€ htmlparser2@6.1.0
โ”œโ”€โ”ฌ https://github.com/fb55/domutils?sponsor=1
โ”‚ โ””โ”€โ”€ domutils@2.7.0
โ”œโ”€โ”ฌ https://github.com/fb55/nth-check?sponsor=1
โ”‚ โ””โ”€โ”€ nth-check@2.0.0
โ”œโ”€โ”ฌ https://github.com/fb55/entities?sponsor=1
โ”‚ โ””โ”€โ”€ entities@2.2.0
โ”œโ”€โ”ฌ https://github.com/sindresorhus/is?sponsor=1
โ”‚ โ””โ”€โ”€ @sindresorhus/is@4.0.1
โ”œโ”€โ”ฌ https://github.com/sponsors/sindresorhus
โ”‚ โ””โ”€โ”€ decompress-response@6.0.0, get-stream@5.2.0, normalize-url@6.1.0, mimic-response@3.1.0, quick-lru@5.1.1, make-dir@3.1.0, mimic-response@2.1.0
โ”œโ”€โ”ฌ https://github.com/sponsors/isaacs
โ”‚ โ””โ”€โ”€ glob@7.1.7, rimraf@3.0.2
โ”œโ”€โ”ฌ https://github.com/sponsors/RubenVerborgh
โ”‚ โ””โ”€โ”€ follow-redirects@1.14.1
โ””โ”€โ”ฌ https://opencollective.com/serialport/donate
  โ””โ”€โ”€ serialport@9.2.0, @serialport/binding-mock@9.0.7, @serialport/bindings@9.2.0, @serialport/parser-byte-length@9.0.7, @serialport/parser-cctalk@9.0.7, @serialport/parser-delimiter@9.0.7, @serialport/parser-inter-byte-timeout@9.0.7, @serialport/parser-readline@9.0.7, @serialport/parser-ready@9.0.7, @serialport/parser-regex@9.0.7, @serialport/stream@9.0.7, @serialport/binding-abstract@9.0.7

I have a problem in finding the port and if I find it I lost the communication or the port is changed

is there any idea please especially for the serial method it is much easer to me than the MQTT

For sure @mustafa. I share you this tutorial of serial communication between Arduino and Node-RED it is in spanish but you can understand the code in Arduino and the flow in Node-RED.

One thing, if you are programming your Arduino at the same Raspberry Pi where is working Node-RED, remember, when you are working with Serial Port in Node-RED, you should disable or close the "Serial Monitor" in Arduino, and when you are uploading the code in Arduino, you should disable serial node in Node-RED. To disable the node use:

Captura de pantalla 2021-08-06 a la(s) 8.24.48 p. m. Captura de pantalla 2021-08-06 a la(s) 8.24.59 p. m.

you should see now:

Captura de pantalla 2021-08-06 a la(s) 8.27.09 p. m.

I hope it helps you!!!

1 Like

I saw the video but I'm wondering if after upload this code to the arduino in order to establish the serial communication ,so how can I upload ad firrent code to the arduino again ? for example now I uploaded the Emon library code to the arduino to calculate electrical current and voltage
is it possible to upload any code like Emon after uploading the code in your video ??

You must run npm install from your node-red folder /home/pi/.node-red - you ran it from /home/pi

2 Likes

is it solved now ??
npm i node-red-node-serialport
npm WARN pi@1.0.0 No description
npm WARN pi@1.0.0 No repository field.

  • node-red-node-serialport@0.14.1
    updated 1 package and audited 326 packages in 40.282s

27 packages are looking for funding
run npm fund for details

found 0 vulnerabilities

It seems as though the serial port is now installed and working however, your goal was to communicate to Arduino.

You didnt say if it had WIFI built in?

If it does have WIFI, then MQTT is MUCH simpler than serial comms

2 Likes

Yes @mustafa, you can add more libraries on the base code, as "EmonLib.h" for example, but as @Steve-Mcl commented; if your device has WIFI, MQTT is better option. You could use a WIFI or Ethernet Shield Arduino for example.

1 Like

My arduino doesn't have wifi ,but I have another ESP8266 with wifi I dont know if it can connected with RPI or not
appreciate if there is a link for video for connecting RPI with ESP8266 with MQTT
and many thanks for your help

Yes @mustafa you can connect your ESP8266 with Node-RED via MQTT. For this you need some things:

1.- Download and install "PubSubClient.h" library, look at the code examples, to understand. This will allow you set your ESP8266 as Client MQTT to Publish and Subscribe messages to Node-RED.

2.- You need some one MQTT Broker, to manage the communication, maybe you can use: Mosquitto BROKER, you can install it in your same Raspberry pi.

3.- Node-RED has two nodes to communicate with MQTT: MQTT in / out.

video support.
video support 2

I hope it helps you!!

2 Likes

Also read this tutorial which will tell you all you need to know about the principles of MQTT. MQTT Essentials - All Core Concepts explained

2 Likes

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.