3 arduino with sketch to node red with rpi

Hi everybody.

I need your help to make my project.

In first i'm sorry. I'm french so my english is not very good.

About my project. I work for an escape game and we want add interractivity.

For this i use 3 arduino.

Arduino 1 with mfrc522 to read 4 rfid. When it's OK, 1 relay open the door. This sketch work perfectly and we need to add play song during the open door.

Arduino 2 with 6 hx711 (load capacity) to detect a load on each Stone. When each Stone detect a load in same time i need to start an other séquences with 3 electric cylinder (2 to open a dome, and one to up the "communion table" with 1er strip led with chase.

And arduino 3 with ultrasonic sensor to make a proximity sensor.

Each sketch is OK but my question is.

How to link this arduino to node red ?

I tried with serial but with 3 arduino doesn't work, i feel i can put only 1 arduino because when i change the serial port only 1 arduino can connect.

I tried with arduino in and arduino out but the state of each arduino stay at "connecting"

So in first i'm block here.....

After i need to know how to communicate each sketch with node red.

For exemple arduino on usb1, name calendar, read 3 rfid and when you are finish play this song and go to launch the sketch of arduino 2 with 6 hx711. When each load capacity detect a changé of 5 kg for exemple, launch the séquences with electric cylinder.... Etc etc...

I'm very newbie with node red and little less with arduino...

What is your better way to make this ?

Thanks in advance !

MQTT and json. You will need to do some homework so take it slow.

  1. you will need to install an MQTT broker - most people use 'mosquitto' - if you do a google search with 'rpi mosquitto' you will find explainations.
  2. do a google search 'arduino mosquitto' and you will find tutorials about it. Look for one using the 'PubSubClient' library (written by one of the Node-RED authors)
  3. google 'ArduinoJson' and read up on that for setting up the data in your arduino sketch
  4. read the posts at 'MQTT Essentials - All Core Concepts explained' - this will help you understand how to use MQTT

Like I said, you have some homework to do. Start by installing 'mosquitto' on your Pi and then in node-redbuile a little test script with an inject node conneted to an mqtt-out node and another flow with an mqtt-in node connedted to a debug node (set to display the complete msg object). Set the 'broker' and the 'topic's (terms you will learn about doing the previous readings) and test that the communications is working.

Next build a test sketch to communicate to node-red. Once you have them working you can finally add the code you need to, into your existing sketches.

Take it a step at a time and don't rush. Remember you didn't learn to walk all in one day.

Do the devices have Wifi or Ethernet? If not then it may be difficult. If they do have wifi/ethernet then use MQTT as suggested.

1 Like

If they don't have wifi/ethernet then you will need some serial to USB adapters to plug them all into the Pi at one time... then you can use the standard serialport node to talk to each.

I can connect with 2 arduino running standard firmata from Node-RED from a windows machine

image

But you've given yourself a big project and I think it will take quite some time to get all 3 working.

Of course, for some reason I had not thought of using multiple serial ports. I must be getting old. Oh yes, I am. :frowning:

1 Like

Thanks to your help !

In fact i tried to use the serial port with USB, but i don't know why, i can connect only one arduino. on other arduino, when i change the serial port, all serial take the same port... It's weird.

My Pi2 have ethernet so i think i'll try to use MQTT but, i'm not expert in c. When i've only one sensor it's ok i can make, but when i will come with the 6 HX711 will not the same...

So, it's better to use MQTT or i need to search why my serial doesn't work ?

Perhaps this arduino uno rev3 with wifi on it is a good way to do the job easily with the use of the mqtt protocol.
https://m.fr.aliexpress.com/item/32932088536.html?spm=a2g0n.productlist.0.0.7d86ArwKArwKMQ&browser_id=8db1a1a287304e95a927b9851dc45565&aff_trace_key=&aff_platform=msite&m_page_id=00117d921877ed231c4cade2a1511c01f12bcd5317&gclid=

In fact after update npm all my serial node work perfectly. All are conected.

Now i think it's very bad idea to work like that but, i need to work quickly without having much knowledge.

In my other with 3 rfid can open a door, i put in my sketch 3 serial print in json. Like "position 1, position 2 and position 3"

In node red i put my serial node, json node, 3 function node.
Each function "filter" position 1, 2 and 3. After i put a join node with 3 state. After this node i put and exec node to play a song.

I know, it's totally a poor job, but it's work. But i think i'll have a problème after few Day...

Now i need to work with my hx711, this time i don't know to take each value in node red from arduino.