Arduino to Pi (Home Assistant)

Hey folks,
I have scoured the internet for a solution and decided to create an account to ask you fine people! I have an Arduino Uno r3, I have wired 2x maxx6675 thermocouples to it. I coded the Arduino and got it to spit out two readings when I open the serial monitor!

So the two problems I think I have are:

  1. How to get the Raspberry Pi to read that Arduino data over USB connection?
  2. How do I get Home Assistant to get that data and show it as a sensor?

If it is too difficult to answer, that’s ok. At least I hopefully can better state my problem! “A problem well stated is a problem half solved” <and I don’t know the lingo well enough to well state it haha.


Thanks!
Dave

if you plug the UNO USB connector in a RPi USB port it will create a virtual serial port, e.g. dev/ttyUSB1
you can open the port using a terminal emulator to view the UNO Serial Monitor output

1 Like

It should show as /dev/ttyACM0
I use the solution horace suggested with my Mega 2560.

1 Like

Homeassistent has an integration for serial data. It also includes an example for Arduino.

1 Like

I tried that, but it didn't work. I can't seem to figure out how to use that integration, I fiddled with it for a few hours and can't seem to get it!. Perhaps my Arduino code is not written well. This is the code I had uploaded to the Arduino Uno r3! I just copied it from the old ESP 8266 board that died. I am quite a newb, and will hopefully clean up that code anyway to make sense better as to which stove it is monitoring!

Oooh ok, so since it is outputting data correctly already, I can just search and figure out a terminal emulator!

I use PuTTY and Python.
sudo apt install putty

1 Like

have a look at putty terminal emulator = works on RPi OK

you can also write code for the RPi to receive/transmit data from/to microcontrollers using serial - I tend of use Java but have also used C++ and Python

1 Like

Would I be correct in saying I essentially need to do 2 things to get it working?

  1. Get PuTTY and write code for the RPi to receive data from arduino
  2. Write something in Home assistant to take that data as a sensor

I would probably try the format from the example:

$,24.1,50,12.9,1029.83,0.0,0.00,*

On the Arduino side, it would be similar to this:

Serial.print("$,");
Serial.print(ktc1.readCelsius());
Serial.print(",");
Serial.print(ktc2.readCelsius());
Serial.print(",*");
Serial.println();

And for the Homeassistant side this would go to the configuration.yaml:
(Needs adjustment for the port name)

sensor:
  - platform: serial
    serial_port: /dev/ttyUSB0
    baudrate: 9600

template:
  sensor:
    - name: ktc1
      unit_of_measurement: "°C"
      state: "{{ states('sensor.serial_sensor').split(',')[1] | float(default=0) }}"
    - name: ktc2
      unit_of_measurement: "°C"
      state: "{{ states('sensor.serial_sensor').split(',')[2] | float(default=0) }}"
1 Like

putty is a stand alone terminal emulator
when you connect the arduino to the RPi and run putty the text output which usually appears on the IDE Serial Monitor will appear on the putty screen

once you confirm that the RPi can communicate with the arduino you can start thinking about home assistance
I don't use home assistant so can not help with that

1 Like

omg... I didn't even know how to ask.... You literally just fixed everything for me. You have no idea how long it took me trying! Also, I learned a lot from all of these reply's!! The only difference is I took the "/dev/ttyUSB0" and made it "/dev/ttyACM0" like you said and boom. I can't thank you enough!! Your formatting and home assistant code was too good to be true haha!

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