Running arduino code on raspberry inside Node-RED

Hello,

I'm totally new to Node-RED, so I would like to ask you what can I do if I have some sensors which I want to read and send measured values via MQTT to another platform. I already have all codes written and working on the Arduino UNO board. So I would like to ask you what do you recommend me to do if I need to run the code with arduino library and somehow get the data from that sensor to Node-RED. I would like to avoid installing some already done libraries (or things like that) or things like that for that sensor.

Thank you very much :wink:

I am not sure what you are asking. Node-red can handle mqtt.

Take a look at the cookbook to get some ideas
https://cookbook.nodered.org

From an Arduino, unless it is connected to your network (via cable or wireless), you would need to connect it to the device running Node-RED. There are various ways of doing that but the simplest is using the Arduino's USB connector to the Pi. This presents as a USB serial port to the Pi which can then be connected to by Node-RED. The serial-in node will let you read values sent by the Arduino. You can then use the mqtt-out node to forward those to MQTT.

Switching from an Arduino to an ESP8266 would let you continue to use your Arduino code with minimal change but you could add MQTT output direct from the ESP8266 device. Such devices are available for a couple of US dollars direct from Chinese sites like AliExpress. The Wemos D1 Mini is a good device to get started with.

Thank you for replies but I probably have not described my problem correctly. I need to connect some air quality sensors to RSP pi zero. I already have working codes with a library for Arduino (ESP32) boards. And because I have no experience with things like python or Linux at all, I'm trying to find a way how I can get the data from that sensor connected to RSP pi zero into a NodeRED with my already existing codes for Arduino written in "C".

Hope that this is a little bit better description of my problem.

Thank you.

Thank you very much for your reply. But I think that my explanation was not clear enough.

What I want to do is use just a RSPB pi zero with an air quality sensor directly connected to it. I have already working code with a library for reading data from that sensor on my Arduino board (ESP32). And is there a way how could I run my Arduino code on raspberry pi zero along with a library and get the data from it as easily as possible to Node-RED?

Or do you know a better solution for me if I have no experience at all in javascript or python how I can read this sensor with Pi zero?

The sensor is: iAQ Core C https://ams.com/iaq-core-c

Thank you very much.

I don't beleive you can run your Arduino code on a Pi - but you might want to ask that question on the forums at raspberry.org. You would be best served there to see if anyone has connect that sensor directly to tha pi. (google raspberry pi i iaq-core-c)

However as Julian noted, it is very simple to have a sensor connected to an arduino and use mqtt to pass the data to nr running on a pi. Julian, myself and many many others do that because it allows the arduino (or wemos d1 mini in my case) to do what it does well, collect the data, and the Pi to do what it does well - process the data.

I don't know anything about that sensor or what data it sends but as it's I2C and there are I2C nodes for node red so I see no reason why you couldn't get I going.

More...
https://flows.nodered.org/?term=i2c&num_pages=1