How can I simultaneously connect a UART device and an I2C device to a Raspberry Pi via a Cat6 cable?
I have been researching related questions to this one for a while but decided I needed to ask this myself, as no one seems to be having quite the same issue and I am not knowledgeable enough yet to extrapolate an answer based on related discussions on this (and other) forums.
I am trying to use my RPi 3B to receive data from a I2C device (BME280 mudule) and a UART device (MH-Z19B). Due to logistical constraints, these two devices must be located in the same spot, approximately 25 ft away from the Pi. I have purchased a 50-foot (15.2 m) cat6 ethernet cable and a pair of surface mount boxes (see links below) for the purpose of connecting the two devices to the Pi.
What I’ve read so far seems to indicate that both I2C and UART struggle to send data reliably over a distance of more than a few inches, and that if I want to send them over this 50-foot cable, I will need a P82B715 bus extender for I2C and a RS232 (or RS485) for UART.
SO my question is, what is the best way for me to wire both of these devices, as well as the necessary drivers/extenders, through my cat6 cable? I am aware that one must be careful which signals are assigned to twisted pairs, so as to avoid crosstalk.
Equipment I’ve purchased:
-Surface mount boxes (x2): https://www.amazon.com/gp/product/B005E2Y9WY/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=1i2cuartShareEditFollowClose 1Flagasked yesterdayFishInTheDesert1122 bronze badges New contributor
- #FishInTheDesert, Welcome and nice to meet you. Ah let me see. Your question is interesting and well presented. Some two years ago, I played with Rpi3B+ and more than a couple of UART/serial and I2C sensors and actuators. For UART/serial at 9k68n1, 5V TTL, using dsub 9 pin, double sealed cables, usually you can do up to 30 meters without any problem. (2) For I2C, at 100kHz, usually you can easily talk reliably up to 2 meters. I did use P82B715 and CAT5 to do “a little bit” longer, if not overloading the I2C bus with too many devices, exceeding 400pF impedance limit. (3) / to continue, …. – tlfong01 yesterday
- You can search rpi.org.forum for more details: (4) Search query “I2C, tlfong01” found 180 matches: raspberrypi.org/forums/search.php?keywords=I2C+tlfong01 (5) Search query “P82B715, tlfong01” found 18 matches: raspberrypi.org/forums/search.php?keywords=P82B715+tlfong01 – tlfong01 yesterday
- You can also search RpiSE forum my other answers for I2C sensors. For example, (6) Rpi3 BMP180 Barometer Sensor Interface Problem – SO, Asked 11 months ago Active 8 months ago Viewed 757 times stackoverflow.com/questions/60274562/… (7) How can Rpi interface BME180/BMP280 pressure and humidity sensor? – Rpi SE, Asked 7 months ago Active 7 months ago Viewed 533 times raspberrypi.stackexchange.com/questions/113646/…. Have a nice project. Cheers. – tlfong01 yesterday
- 1Thanks for your response! What is 9k68n1? – FishInTheDesert 10 hours ago
- Ah, sorry, I should have said 9k6bd8n1, meaning 9,600 baud, 8 bits, no parity, 1 stop bit. This is the most popular default serial standard. – tlfong01 1 min ago Edit
I²C is designed to operate over short distances, typically on the same board.
Attempting to use over long distances is unlikely to succeed.
The application to UART is rather less clear.
The RS232 specification uses ±15V bipolar and is supposed to work over 1000′, although this was very conservative. No modern systems actually implement this; ±12V was common in the 1980s, but most modern systems (if you can find one that implements serial) use 0/5V unipolar.
These work over reasonable distances, as does the 0/3.3V unipolar on the Pi (which also differs in polarity from RS232).
The problem with serial is that it requires a common Gnd (this is more critical with unipolar) and is dependent on layout. You could get away with 50-foot (subject to layout) but I would use buffers to drive the signals.
I used to use 20mA current loop (which has its ancestry in telex) and can operate over thousands of km (with 50V drive) and is easily implemented with opto-isolators to avoid Gnd problems.
Probably the easiest and most reliable would be to use Ethernet, which is inherently galvanically isolated and uses balanced common mode signalling.ShareEditFollowFlagedited yesterdayanswered yesterdayMilliways47k2121 gold badges7777 silver badges153153 bronze badges
- 1Thanks for your answer! This may be a simple/vague question, but what do you mean by “use Ethernet”? I plan to use an Ethernet cable to connect my sensors to my RPi, but are you referring to some specific protocol or some specific way of wiring the cable? – FishInTheDesert 10 hours ago