Reading Serial data from arduino to esphome

Home Assistant automation projects, questions, etc. go here.
Morbidbystander
LED Enthusiast
LED Enthusiast
Reactions:
Posts: 40
Joined: Wed Sep 16, 2020 4:12 am

Update.
Everything was working great for 8 hours. The Esp32 disconnected from home assistant and got stuck in a loop reconnecting then disconnection as stated in the esp home log. Data was still being recieved from the Ruuvi and ezo but couldn't get posted to HA. There is also a bug that says "reading from UART timed out at byte 0" in between ph readings.

Pulled power on both the esp and the arduino with no result. After I pulled the TX and RX wires between them it reconnected sending temp and humidity in. After plugging them back in the ph data streamed to HA too. The bug is still there about the UART reading though. Maybe the bluetooth and UART are incompatible streaming from one device.
Morbidbystander
LED Enthusiast
LED Enthusiast
Reactions:
Posts: 40
Joined: Wed Sep 16, 2020 4:12 am

I'm using TX0 pins 0 and 1 on Arduino mega. I'm using TX1 on the Esp32 pins 16 and 17. The systems has not dropped off the wifi so far today but I've got a new development as well. My Ezo board will stop communicating randomly. The light becomes solid blue intstead of its green blue flash. Pulling the 5v for the relays and ezo does nothing after reapplying but if I pull the power on the Arduino it resets and runs fine for several hours. This only happens if the ESP is hooked up. I'm trying to use a voltage divider overnight to drop the TX to 3.3v. Wondering if I should implement a pull up on the off terminal on the ezo board isolator as well. The data sheet says you can pull to vcc so it never sleeps. I'm not sure what resistance should be if any. Google here I come.
:cry:
User avatar
LEDG
Site Admin
Reactions:
Posts: 1599
Joined: Sun Jun 04, 2017 8:15 pm

Funny enough, this is a problem I battled as well, and still see crop up from time to time. It was worst when I was using a level shifter to go from the 3.3V ESP to the 5V Mega, and got better when I just raw-dogged it and went straight through. I would love to hear a solution if you find one.
Want to Support the Site?

Use this Amazon referral link and any purchase you make within 24 hrs will earn LEDgardener a commission at no cost to you!
User avatar
Salmonetin
LED Enthusiast
LED Enthusiast
Reactions:
Posts: 51
Joined: Wed Jul 15, 2020 5:13 pm

...erased....
Last edited by Salmonetin on Sun Nov 29, 2020 7:33 pm, edited 3 times in total.
Morbidbystander
LED Enthusiast
LED Enthusiast
Reactions:
Posts: 40
Joined: Wed Sep 16, 2020 4:12 am

I ended up hacking it for the time being. I've got a zwave plug running the arduino that cycles power every 6 hours. I will definitely pursue other options when I can dedicate more time. Its traced directly to the TX line from the arduino. If the ESP32 drops off the wifi, disconnecting TX arduino to RX ESP brings it back online instantaneously. When power is cycled the TX stops for a split second and it also restarts the ph readings.

Adding a voltage divider did nothing.
Morbidbystander
LED Enthusiast
LED Enthusiast
Reactions:
Posts: 40
Joined: Wed Sep 16, 2020 4:12 am

I just completed a 24 hour test with no crashes of the Ph monitoring or the ESP32 dropping wifi. I found a thread somewhere that stated the ESP32 is a 3.3v board. There is a voltage regulator that drops the 5v input from the micro usb to the board's needed 3.3v and some people are saying that hitting it with 5v from the arduino will cause instability.........permanently. This is in direct contradiction to many wiring diagrams found online in which the TX and RX are connected without any protection.

I purchased a new ESP32 and programmed it to only run as a serial communication sensor for the arduino. I also used a voltage divider usually seen on the 8266 ESP01 which is a 3.3v board as well. Its now been 24 hours of stability without the reset hack. After running this new set up for a week, I will call it good, add the Ruvvi programing, and see if the stability remains. The strange part is, if the "fried" ESP32 is not connected to the TX of the arduino it runs perfectly fine trasmitting the Ruuvi data.
User avatar
LEDG
Site Admin
Reactions:
Posts: 1599
Joined: Sun Jun 04, 2017 8:15 pm

Interesting that it could permanently affect it. Makes sense, I guess. I do have level shifters in my box of goodies so I suppose I could try a fresh ESP32 with a shifter between it and the Mega for comms if it starts misbehaving again. It's funny because when I delved into this a long while back, I found a few threads that stated the serial connection was fine to run off of 5V, despite the fact that it's a 3.3V board. The specs likely wouldn't agree, but in practice, I guess people had no issue. Here's hoping you're all good now.
Want to Support the Site?

Use this Amazon referral link and any purchase you make within 24 hrs will earn LEDgardener a commission at no cost to you!
Morbidbystander
LED Enthusiast
LED Enthusiast
Reactions:
Posts: 40
Joined: Wed Sep 16, 2020 4:12 am

It's very interesting how many diagrams and different how to guides have the communication wired directly. It seems there is a split about whether or not a 3.3v board is 5v tolerant. It's very possible that the brand of the board could effect this.

Anyway the new ESP32 with the divider has never dropped wifi but the ph probe is still dropping. The ph stamp goes solid blue and the data sheet says it's in standby mode. I've been trying different things but can't get it to stay for longer than 3 days. I'm moving on to some 4.7k pull ups on the I²C next, then considering changing to serial com and scratching the I²C all together. It's very weird that the ph meter never drops unless the arduino is hooked up to the ESP32 for uart com.
Morbidbystander
LED Enthusiast
LED Enthusiast
Reactions:
Posts: 40
Joined: Wed Sep 16, 2020 4:12 am

Problem solved.

I switched the atlas stamp to Uart protocol and uploaded the Uart code to the arduino. The stamp is wired to Uart 3 on the arduino ie 14 and 15. Esp32 is wire Uart 0 ie 0 and 1. There is a voltage divider on the tx from the arduino. The circuit is tx arduino to 1k ohm resistor which splits to rx Esp32 and 2k ohm resistor pulling to ground. The voltage tested at 3.3v on the rx Esp32.

There must be some sort of bug in the controller code that causes the random standby mode for the ph stamp.
Morbidbystander
LED Enthusiast
LED Enthusiast
Reactions:
Posts: 40
Joined: Wed Sep 16, 2020 4:12 am

I just figured out how to calibrate with the set up. It was right under my nose the whole time. Search UART switch on ESP home for more info.

Code: Select all

switch:
  - platform: uart
    name: "Mid Point Calibration"
    data: 'cal,mid,7'
This creates an switch entity that can be toggled to send the command through wifi to the ESP32, which prints to the Arduino, who prints to the EZO stamp. You can pretty much create any UART command by changing the data line. :D
Post Reply