Can I connect arduino to OpenHab?

Tags: #<Tag:0x00007f616faca738> #<Tag:0x00007f616faca530> #<Tag:0x00007f616fac8758>

Hi guys,
I would like to ask for an advice. Basically what I want to do is RPI local server with web server, where I can display data from arduino sensors and from web page (web server) I need to be able send values to arduino (like temperature… arduino will manage everything else). The connection should be serial (usb) as I don’t want to use any shields.

I tried to use Home Assistant, but in the end I couldn’t pass data from web to arduino. Second one, which I tried was Blynk… but I couldn’t even connect the arduino to the RPI…

I’m using Arduino MEGA and RP-3

So to clarify you want the pi to read the data from the arduino and use openhab as the web interface?

One suggestion would be add and esp8266 the pi can then send the data over mqtt to the arduino.

1 Like

Yes and from web interface I want to send some values (such as temperature, which user set on web interface) to Arduino so I can manage the heat. I don’t want to manage it in RPI.

I know that MQTT would be a solution, but I can’t use it. I need it over the USB/Serial.

Not sure if this is the simplest way but take a look at mysensors.org. They do have a serial gateway. And you can add sensors directly to the gateway.

But if you start, you should alteady think about scalability. There will be additional sensors, ideas coming in the future…

Will I be able to this simple communication just from serial USB connection? Do you have some experience with mysensors.org? I’m kinda lost on their website…

It looks like they’re aiming for standalone Arduino projects.

In general what mysensors does is having a central gateway and wireless sensors. They use mainly NRF24 for communication. This is low power and I have a lot of those at home. Some run on batteries for more than one year already.

But all gateways need to be connected to a controller. And in my case this is OpenHab. I opted for MQTT but had it serial before.
So to answer your question: I had over quite a period an Arduino Uno connected via USB to my Raspi where OH is deployed. Over time I had added a lot of sensors and the serial connection was a heck to administer. If you only connect one Arduino with serial, this should be simple.
On their site, go to https://www.mysensors.org/controller/openhab
instructions are there.

But again, we do not know anything about your usecase. potentially you let us know and we can provide potentially a better option.
From my point of view, this is ok for one or two sensors but if you start, you will adding more and more sensors over time and therefore some sort of wireless will be better.

I connect my arduinos through KNK with openhab.

http://www.intranet-of-things.com/smarthome/infrastructure/knx/arduino/

1 Like

Hi,
Thank you for your response!

What I’m basically trying to to is Raspberry Pi server to which I connect arduino as controller. Arduino will have just few sensors…about 3 and it will controll some based on values which arduino process (arduino will handle processes and conditions). On the RPI I want to host web server where I will see current values which I’m receiving from sensors (like room’s temperature) and also I want to be able to send 1 or 2 values of data to arduino (just pass the number {int} through the usb and arduino will handle everything alone).

That’s what I’m aiming for…

1 Like

For this scenario, I think openhab, even a Raspi is overhead. This can be achieved with a simple ESP8266. All on one microcontroller. If you need it a bit more „fancy“ go for ESP32.
Webinterface runs directly on the device, no need to interface etc.

1 Like

@holger_hees sounds simple but expensive. At least under the link the knx part alone is 23 EUR.

I know that raspberry pi is kind of overkill, but I need to use in order to accomplish task gave me my school.

ok, makes sense.
As said, it is possible.

  1. get OH installed on the RPi
  2. install the mysensors binding (https://github.com/tobof/openhab2-addons/wiki)
  3. implement the code of gateway on the arduino (https://www.mysensors.org/build/serial_gateway)
    There is a challenge, it usually needs a radio but you can get help on their forum
  4. add the sensor to arduino and adjust the code
  5. connect the gateway to OH

I would suggest you use the relay sketch from mysensors to start with. Instead of connecting a relay, connect a LED. Then in OH implement it as a switch, if you succeed, you can turn the LED on and off via OH web interface.

If you like, you could even download the IOS or Android app to control it via smartphone

My understanding then is that you want an Arduino to be connected directly to your PI, using a USB serial connection. The Arduino will have some sensors, and you want to receive the sensor values on the PI to be able to display these in the Web server (i.e. on the openHAB UI). Furthermore, you want to be able to set some values (e.g. a setpoint) on the UI and have these values sent to the Arduino. Correct?

In this case, I suggest you take a look at the Serial binding:

I have not used it myself, but from the documentation it looks like you should be able to cover your use case with this binding.

Thank everyone for suggestions! and sorry for late reply! I will definitely try it and post what I got! ^^

After 1.5 years > what are the experiences with this method?

  1. Did anyone try to plug in multiple Arduino boards (NANO) into a single RPi to control them all with OH?

  2. Can those boards handle the I2C attached other (GPIO) extender boards too, to forward from / to the master?

  3. How fast can it be?

  • default 56 Kbaud seems to be very slow to inform OH about everything in “realtime” if I long-press a button from 40-60 total + read some analog values too (distance, dust, temp…)
  • … except if ONLY CHANGES travel through the bus?
  • Also I don’t like the idea of serial com without proper flow control + parity bits. (Bad expeiences during the last 20 years…)
  1. Is the USB>Serial way the better, or Ethernet + Moscuito?

  2. How about Firmata?

  3. Maybe UDP?

Thanks in forward for any info about this.
(The documentations and possibilities are overwhelming to choose the right way…)

Try https://homeautomation.proboards.com/ for another framework for the Arduino boards.

1 Like

Yes with Modbus over RS485

1 Like

Can you tell more about this please?

  • What Binding do you use for it?
  • How many IO ports + other all together on how many stains/busses?
  • Exactly what kind of devices?
  • What firmware is uploaded to the Ardu boards?
  • Is the Arduino ONLY a gateway, or can you use the IO + Analog ports on it too?
  • What speed is it working? Can you long-press / dimmering / double click?

Great link! Thanks :slight_smile: Did not find it yet.

Sadly there is only ONE topic about: how to connect with a simple USB >> without any solution. :frowning:
All the other posts are about: RF, Wifi or Ethernet.

Hi,

What Binding do you use for it?

I’m using Modbus Binding, my PLC is a bridge: Modbus over RS485 to Modbus over Ethernet, but you can use any Modbus converter or instead of RS485 you can use the arduino ethernet module.

How many IO ports + other all together on how many stains/busses?

im using it for sensors there are 5 arduinos, but i can’t see any problem to add more

Exactly what kind of devices?

What do you mean?

What firmware is uploaded to the Ardu boards?

There in no such a thing like firmware in arduino. Sketches are written in C/C++ like language

Is the Arduino ONLY a gateway, or can you use the IO + Analog ports on it too?

Every arduino is a Modbus Slave and you have acces to all goods on board :slight_smile:

What speed is it working? Can you long-press / dimmering / double click?
115200, all stuff like short/long/double etc. clicks, you can handle by arduino.

1 Like