Hi,
I have up to 8 serial devices to connect to an ESP32 through a 4067. The wires that come from the serial devices are 3.3V, GND, Tx and Rx. I only need the Tx for the serial data as I am not sending any data back (ie Rx into ESP32 only.) Rx on ESP32 is pin 16 (Rx2).
The other 8 MUX pins I was going to use to digitalRead() the 3.3V from the devices. That is HIGH = connected, and (pulled) LOW is disconnected. Problem to me is that when muxed, they would also go to pin 16 (Rx2) of the ESP32. Can you use the Rx2 pin to do a digitalRead()?
The reason for wanting to know how many devices are connected is that I don't wan't to be trying to Serial.read() from an unconnected device.
Thanks in advance to anyone who uses a few neurones to figure this out.
Pete
We need some explanations, like why you would digitalRead() a serial signal, well, how you would tell the difference between an open connection and a low level part of a serial signal that way... generally, a diagram would help a lot to clear things up. I hope you already have one...
Problem to me is that when muxed, they would also go to pin 16 (Rx2) of the ESP32.
Why? It's really unclear why that would be a problem... please explain and provide a clear explanation and diagram.
In connection with using a pin both with an internal peripheral and I/O, if that is a problem you could connect the signal to two different input pins on the ESP.
On most processors, when you select an internal peripheral function for a pin, it over-rides an assignment as a GPIO. Switching back and forth dynamically could be a problem, as you have already guessed.
Thanks for your response. My question relates to the MUX connecting to a single pin on the ESP32. I guess I could set pin 16 to a digital input firstly and digitalRead the 8 (or less) connected devices that MUX to pin 16. When I have a list of devices connected, change the function of pin 16 to be Rx2. If that makes sense. To do it individually, I would have to MUX the Tx's of the device through the 4067 and sacrifice 8 digital pins to read the voltage outputs of the 8 (or less) connected devices.
I am trying to avoid having the ESP32 read from a muxed pin that has no device connected
Pete
The issue here is the sequence of events, which you haven't fully explained. At what time(s) do you poll the inputs to see what is connected, and at what times not? How many times? Just once, at boot, or???....
How or why is it that a disconnected input will be "low"? Is there some circuit element that does that? What is it?
Also, serial data has "lows" in it. What guarantee do you have that when you poll it, it will not see that and falsely decide that nothing is connected?
See what an analytical mind does!
Yes you are correct, and, thankyou.
The polling for the "connected devices" happens just once, and is done in setup. Pull down resistors are on those 8 inputs. (I think the 4067 can be configured for that... I'll have to check).
Once I have a list of the "connected devices". I only need to poll the Serial transmission for those devices in loop. Each device transmits about 110 bytes at 19200 with an interval of 1 second. So the ESP32 handles that side easily.
If the user wants to connect another device, they plug it in and restart the '32 which then polls for connected devices once, and, then loops
The MUX will separate the Serial input from the digital because they are on separate MUX pins
Well, you can first configure the pin as I/O and poll. You have to differentiate a disconnected pin from a pin that just happens to be low at the time you sample it, if it is already receiving serial data. That is a timing problem to solve. After that you can re-configure it safely, as a serial port. I see no other problems.
It does seem awkward to force the user to reset every time they plug in a new device, but that depends on details I don't know...