I'm working on connecting to an AC unit over UART using an ESP32 with Arduino libraries. The AC uses 5V and its TX is open-drain. I'll have about 10 feet (3 meters) of four 18AWG wires from the AC to the ESP32. UART is at 2400 or 9600 baud. I'll build 4 boxes, each with 1 ESP32 and controlling 1 or 2 AC units.
I don't have the luxury of testing, as the house is still being built. I need to build a solution beforehand and when the house is ready, hopefully I'll have AC right away. If that fails, I'll redesign and can test more at that time. I'm asking for your advice to increase my chances of success on the first go!
SwiCago/HeatPump
I'll use the SwiCago/HeatPump library for the UART communication. There's a lot of discussion there, but not about using an ESP32 or a 10' cable. I will stick with the ESP32 (a wESP32 actually) because my ESP32 will also be doing other things and I want ethernet and PoE.
The demo circuit works for an ESP8766 because it has 5V tolerant GPIOs. There are claims the ESP32 is 5V tolerant but I would rather stick to the datasheet and 3.3V. This post seems useful, but I'm inexperienced and it's important my circuit works.
I've been reading for days and there's lots of ways to solve this, depending on all sorts of things.
Level shifters
First I looked at level shifters. This requires connecting the AC and ESP32 grounds. That should be OK, but possibly not. I can't test at this time to be sure. Also I'm not sure if the grounds test OK that they will always be OK. Should we assume the grounds can be connected without issue, or should we look for an isolated solution?
Back to level shifters, I can build my own but my experience and confidence are low so I looked at ICs. The TXB0102 is bidirectional which isn't necessary for UART but could still work. However, being bidirectional makes it sensitive to capacitance and it may not like my 10' cable. The TXS0102 appears to be a better solution, as it mentions UART in the datasheet. Still, I think both are intended to be used on-board. Is the TXS0102 likely to work with my 10' cable?
I know my 10' cable isn't a great idea, but I'm hoping it will work. I looked at a proper transmission line setup using RS-485, but then I'd need electronics at both ends. I could do that if ultimately necessarily, but if the 10' cable can work, that is much simpler. Remember, I have 6 AC units.
Also, do I really need an IC for my situation? I'm happy to use an IC if it provides more reliability or other benefits, but I don't want to make things unnecessarily complex.
Sending 5V
After connecting grounds, I could connect my ESP32 TX directly to the AC RX. The AC expects 5V, but the 3.3V should still be high enough for 5V logic high. Would it be better to send 5V over the 10' cable? If so, maybe I don't want to use this solution.
If I understand correctly, the ESP32 TX is driven actively by default. The ESP32 supports open drain output via pinMode(pin, OUTPUT_OPEN_DRAIN)
. Is it possible to use that with the Arduino Serial
class? If so, I could pull the ESP32 output up to 5V so I have 5V over the 10' cable. I think I would need a diode to protect the ESP32. This is getting over my head, but I'm happy to learn. Is a Schottky diode the right choice?
Receiving 3.3V
This seems easy: since the AC TX is open drain, I can just pull it up to 3.3V with a 10K resistor (diagram). Again this means I'm using 3.3V over the 10' cable and I don't know how much more susceptible to noise that is than 5V.
Optocouplers
I read optocouplers can be used to isolate UART, sometimes, but I don't know what parts would be acceptable for 9600 baud. I have some LTV-846S (datasheet) on hand, would that work? How does this look?
I like the optocoupler solution because it's simple, there's no chance of a ground loop, and I have 5V over the 10' cable.
Sorry this got long!