I have been trying to get a project to work for days, but I think it is beyond my understanding. I am trying to combine this hydroponics system with Home Assistant via ESPhome. To clarify - I am a total novice in coding (i’m a biochemist), and I try to learn as I go. I have successfully modified the Arduino code in the project and got it working. It sends the sensor values to serial (I can see them in the arduino serial monitor). Now comes the next part - reading those values on my ESP32 running esphome (it also controls a few relays). So far I have physically connected the two controlrers (Rx -tx, tx-rx and gnd). Not getting the values is where I am stuck. I have tried everything I could think of. My first plan was to do this: Custom UART Device — ESPHome, but as it is being removed, I tried to get the external component to work (locally). No luck. I have tried using ChatGTP to help, but after 8 hours of trying a lot of different codes for yaml, cpp and h file - no luck.
So I humbly ask the members of the community, if you could donate some of your time to help me get this thing working? I don’t understand C++ at all, so blindly copy pasting stuff is not helping. I want to see the sensor readings in HA (in graphs or something) for starters.
Is there a reason you want to keep the Arduino? Are the sensors 5V logic levels maybe?
Otherwise, have you considered replacing the Arduino with an ESP32 and thus cut out one level of complication. You could then do everything with ESPHome, or alternatively run the Arduino code on an ESP32 and add a wifi and MQTT library.
That was one of the first projects I did after converting from Arduino hardware to ESP - it wasn’t too difficult…
First of all, thank you for taking the time to reply.
I am using TOF10120 for distance measuring, DS18b20 for temperature, a TDS meter, and a HW-828 pH meter. And yes, it also uses an Oled display, but that doesn’t matter much. I just added it as it was already planned into the PCB design. This is the code I run on arduino nano: Arduino code - Pastebin.com
I did think of moving all the sensors to the ESP32, but that would have required programing them into the ESPhome code and I assumed it would be more difficult than just running them on the Arduino with the existing code. Especially since I have no idea what I am doing
So my thought was that it would be less complicated to write something that just gets the text values via serial and displays them in HA. But somehow, it became complicated.
As for .h and .cpp files - I tried to implement a custom component, using chatGPT to write the code, but eventually it always ran into some compilation errors. Either circular reference or missing sensor. I did not keep track of the various iterations, but I can put up the last attempt code.
I have been thinking and to be honest, do I really need to actually add anything as a sensor? There should be a way just to use the text information? I may have confused the AI, so it let me on the wrong path to begin with.
Have you tried just seeing what the ESPHome UART debugger shows up once connected? You should just need the Tx on the Arduino connected to an Rx on the ESP I think? Maybe GNDs too.
You could look into this technique to read uart without a custom component. I’ve used it a few times.
Since I have managed to figure it out with the help of a few people on Discord, I thought it would be useful to post the solution here, in case someone wants to do the same.
One of the users pointed me to his github of custom components.
I had to modify the arduino code to output the values as comma separated values, but with that and the custom component I was able to implement it into the esphome.