Raspberry Pi Intermittent I2c OSError

Moderators: adafruit_support_bill, adafruit

Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/
Locked
User avatar
ilikecake
 
Posts: 15
Joined: Thu Dec 19, 2019 12:30 am

Raspberry Pi Intermittent I2c OSError

Post by ilikecake »

I am working on a project that involves a Raspberry Pi zero W and the HT16K33 LED display driver. The application is a wall clock. The project uses Python, and code basically wakes every second, checks if the time on the display needs to be updated, and if so, updates the time. I have noticed recently that I occasionally get an OSError when this code tries to update the display:

Code: Select all

Traceback (most recent call last):
  File "/home/pi/software/wall_clock.py", line 325, in <module>
    main()
  File "/home/pi/software/wall_clock.py", line 268, in main
    UpdateDisplay(now)
  File "/home/pi/software/wall_clock.py", line 234, in UpdateDisplay
    display[2] = TimeString[2]
  File "/usr/local/lib/python3.9/dist-packages/adafruit_ht16k33/segments.py", line 168, in __setitem__
    self.show()
  File "/usr/local/lib/python3.9/dist-packages/adafruit_ht16k33/ht16k33.py", line 112, in show
    self.i2c_device.write(self._buffer)
  File "/usr/local/lib/python3.9/dist-packages/adafruit_bus_device/i2c_device.py", line 84, in write
    self.i2c.writeto(self.device_address, buf, start=start, end=end)
  File "/usr/local/lib/python3.9/dist-packages/busio.py", line 165, in writeto
    return self._i2c.writeto(address, memoryview(buffer)[start:end], stop=stop)
  File "/usr/local/lib/python3.9/dist-packages/adafruit_blinka/microcontroller/generic_linux/i2c.py", line 49, in writeto
    self._i2c_bus.write_bytes(address, buffer[start:end])
  File "/usr/local/lib/python3.9/dist-packages/Adafruit_PureIO/smbus.py", line 314, in write_bytes
    self._device.write(buf)
OSError: [Errno 121] Remote I/O error
There are other things on the I2C bus, but so far, I have only seen this issue when updating the time. I used the try-except functions in Python to gracefully handle the error, and it seems to work.

Code: Select all

def UpdateDisplay(CurrentTime):
    TimeoutCount = 0
    while TimeoutCount<10:
        try:
            if AMPM:
                #Use AM/PM
                TimeString = CurrentTime.strftime("%I%M")
                if TimeString[0] == '0':
                    display[0] = ' '
                else:
                    display[0] = TimeString[0]
            else:
                #24 hour time
                TimeString = CurrentTime.strftime("%H%M")
                display[0] = TimeString[0]
            
            display[1] = TimeString[1]
            display[2] = TimeString[2]
            display[3] = TimeString[3]
            display.colon = True
            break
        except OSError:
            print(CurrentTime.strftime("%H:%M"), ": OS Error", TimeoutCount)
            
        TimeoutCount = TimeoutCount + 1
Running with that code, I see an I2C error roughly once per hour (about every 60*5 I2C transactions to the display). Is this normal? I have seen some threads online that indicate that intermittent errors like this are the result of bad wiring, but I have double checked my wiring, and I see no obvious errors.

User avatar
ilikecake
 
Posts: 15
Joined: Thu Dec 19, 2019 12:30 am

Re: Raspberry Pi Intermittent I2c OSError

Post by ilikecake »

Well, I think I figured out this issue. I am powering the HT16K33 driver with 5V. However, my I2C bus is at 3.3V levels so that I don't destroy the other devices on the bus with a 5V high level. Closely reading the HT16K33 datasheet, shows that the driver considers a 'high' signal on the I2C bus to be >.7*Vcc. At Vcc=5V, that comes out to 3.5V, which is greater than the 3.3V high level on the bus.

Can you please either add a level translator to the HT16K33 backpacks or mention something up front in the documentation?

User avatar
Franklin97355
 
Posts: 23912
Joined: Mon Apr 21, 2008 2:33 pm

Re: Raspberry Pi Intermittent I2c OSError

Post by Franklin97355 »

I'll let the authors know.

User avatar
adafruit2
 
Posts: 22148
Joined: Fri Mar 11, 2005 7:36 pm

Re: Raspberry Pi Intermittent I2c OSError

Post by adafruit2 »

yah this is coming up on the pi probably because the pi power supplies edge towards 5.5V - you can use a diode to drop down the 5V to more like 4.8V (which is what the arduino power supply this was originally designed for)

Locked
Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/

Return to “Adafruit Raspberry Pi® accessories”