2

I am trying to read analog data from a potentiometer using I2C connection between the pi and adc board using python code. Below is my code so far:

import time
import smbus
bus = smbus.SMBus(1)
bus.write_byte_data(address,0x07,0x00)
bus.write_byte_data(address,0x07,0x01)
bus.write_byte_data(address,0x07,0x00)
time.sleep(0.5)

while True:
      data = bus.read_i2c_block_data(address,0x00,7)
      print("ADC data : %d" %data)
      time.sleep(0.05)

When I run this code, I get the following output:

Traceback (most recent call last):
  File "readADC_i2c_v2.py", line 8, in <module>
     bus.write_byte_data(address,0x07,0x01)
IOError: [Errno 121] Remote I/O error

So far I have tested i2cdetect -y 1 and I get 0x53. I then tested i2cget -y 1 0x53 0 and got 0x2a and i2cget -y 1 0x53 4 and got 0xff. I also tested voltages across SCL and GRD and it showed -3.3 and SCK and GRD which also showed -3.3. I am not sure how to proceed further.

EDIT: Some clarification - I am using the Navio2 device which is connected to a raspberry pi 3+ and which has an I2C port with connection cable provided.

tlfong01
  • 4,665
  • 3
  • 10
  • 24
Yukti Kathuria
  • 43
  • 1
  • 1
  • 8

1 Answers1

0

Question

IOError: [Errno 121] Remote I/O error

i2cdetect -y 1 get 0x53 OK. i2cget -y 1 0x53 0 got 0x2a OK, i2cget -y 1 0x53 4 got 0xff OK. Voltages across SCL and GRD showed -3.3, SCK and GRD which also showed -3.3

How to proceed further?

Answer

Ah, I have been playing with I2C for almost one hobbyist year now, and I always get the above "Error 121 Remote I/O Error" message. Now first let me list some common causes.

Common Causes

  1. "i2cdetect -y 1" is a helpful, but preliminary, and very forgiving test. It only confirms that your hardware setup is "more or less" OK. (I guess it just pings, or reads, and not writes.)

  2. "i2cget ..." is reading something OK, but have you also tried "i2cset" to write something and then read it back (to make sure if you actually have written something successfully?).

  3. If you are using a multimeter to check the power and signal line idle voltages, showing roughly around 3V, it means again only "more or less" OK. If you use a scope to display the wave forms when repeatedly reading and writing at say, I2C 100kHz, you may find the signals distorted, for many reasons, including those listed below.

  4. Rpi I2C signal/data pins built in pullup is 1k8. Most sensors/converters almost always have their own pull ups, usually 4k7, but may be as weak as 10k. The problem is that even 10k, not to mention 4k7, in parallel, would strength 1k7 to even stronger, causing problems such as GPIO pin over current (3V/1k is already 3mA, which Rpi might not like that much). If you place more sensors on the I2C bus, then the problem worsens, see more details below.

  5. If your connecting wires are longer than 15cm, then they are antennas picking up nearby 50/60Hz mains EMI waves, which might also cause trouble.

  6. There are perhaps a couple of more trouble making causes I forgot. Perhaps I would update later.

Quick and dirty, but not perfect remedies

Some experiences to share:

  1. I almost never use Rpi's built in SCL/SDA signals. I use TXS/TXB/02/04/08 logical level converter to level shift, but at the same time buffer/boost/isolate. Those TXS/B chips are designed to help strengthen weak I2C signals, so they are good, though not perfect, especially if you are using long wires (me over 1m), where you need I2C extenders (Google SparkFun's suggestions).

  2. Even using TXS buffers, you still have the I2C pullup overloading problem. What I usually do when first using any I2C device, is remove the device's built in pullups. This is almost an immediately cure, when I got the Error 121, remote IO error. You may like to google around to see the pictures of how other happy guys removing their I2C chips built in pull ups and problem solved.

There are more things I did but forgot now, perhaps I would update later.

PS - Not too long ago I was trying to place 4 I2C ADS1115 ADC chips on the bus. I immediately got the 121 remote io error. The lazy hobbyist knew where was the problem, so removed one pullup, but the error did not go away. So the lazy guy removed one more, and then one more, until all pullups were removed, then everybody was happy, and the error 121 remote IO error disappeared. But the error kept coming back intermittently. The lazy guy finally found that just using one sensor is best, two is still OK, more than three then error comes up often.

I am still struggling with this nasty I2C 121 error problems, so my quick and dirty answer might not that helpful. But I have been googling hard these couple of months without much luck, because problem is a bit subtle, ... :(

removing pullup

i2c detect

/ to continue, ...

References

A Guide to Voltage Translation With TXS-Type Translators - Application Report SCEA044 – 2010jun

Effects of External Pullup and Pulldown Resistors on TXS and TXB Devices - SCEA054A – 2018mar

TXS0108E 8-Bit Bi-directional, Level-Shifting, Voltage Translator for Open-Drain and Push-Pull Applications TXS0108E SCES642E – 2018feb

TXS0104E 4-Bit Bidirectional Voltage-Level Translator for Open-Drain and Push-Pull Applications - SCES651H – 2018may

Maximum I2C Bus Length? - electronics.stackexchange.com

NXP SMSbus Guide

nxp smsbus guide

The I2C Address List by Lady Ada -  last updated on Apr 28, 2019.

The I2C Address List by Lady Ada -  hightlighted by tlfong, 2019apr28 2019.

Using I2C extender to entertain more I2C devices

I2C extender example 1

I2C extender example 2

tlfong01
  • 4,665
  • 3
  • 10
  • 24
  • 1
    I made a few changes to the code and by removing 2 of the write commands (writing 0x01 and 0x00 the second time), I was able to get things to print. I am not sure what it is printing yet. But that is another problem. – Yukti Kathuria Apr 28 '19 at 03:23
  • How nice to hear the good news. Add oil and good luck! – tlfong01 Apr 28 '19 at 03:35
  • 1
    Thank you, and another one for the advice! I will keep it in mind for future issues. – Yukti Kathuria Apr 28 '19 at 03:49
  • You are welcome. I have updated my answers with more references. You might find them helpful. – tlfong01 Apr 28 '19 at 03:55
  • 1
    @tlfong01, I'm having some OError: [Errno 121] errors. It is only sporadically and already found the source of the error. I have a servo being powered by my circuit and each time I'm sending commands to drive it, it interferes with the I2C connection. I know I should power the servo with a dedicated power source. Even so, do think using a TXS logic level will help with the interference? – Miguel Sep 05 '21 at 16:42
  • Just a quick comment. Yes, ext pwr for servo, and lvl shifter to 5V logic helps. You might also consider optocoupling (EL817c eg). Good luck. Cheers. – tlfong01 Sep 06 '21 at 01:15