i2c smbus2 BlockingIOError: [Errno 11] Resource temporarily unavailable

July 9, 2024, 05:14

neng1

i was trying to control mini oled screen sh1106 using my raspberry pi 5 but i encounter this error does anyone has idea what does this means
 File "/home/nengyi/.local/lib/python3.12/site-packages/luma/oled/device/__init__.py", line 79, in __init__
    self.command(
  File "/home/nengyi/.local/lib/python3.12/site-packages/luma/core/device.py", line 48, in command
    self._serial_interface.command(*cmd)
  File "/home/nengyi/.local/lib/python3.12/site-packages/luma/core/interface/serial.py", line 93, in command
    self._bus.write_i2c_block_data(self._addr, self._cmd_mode,
  File "/home/nengyi/.local/lib/python3.12/site-packages/smbus2/smbus2.py", line 643, in write_i2c_block_data
    ioctl(self.fd, I2C_SMBUS, msg)
BlockingIOError: [Errno 11] Resource temporarily unavailable 

oops.se

I think you have a blocking condition.

neng1

how to fix it, seems like i couldnt run any of the smbus2 sample code

neng1

all the code throw the same error

neng1

like this code from smbus2 documentation
from smbus2 import SMBus, i2c_msg

# Single transaction writing two bytes then read two at address 80
write = i2c_msg.write(80, [40, 50])
read = i2c_msg.read(80, 2)
with SMBus(1) as bus:
    bus.i2c_rdwr(write, read)

neng1

Traceback (most recent call last):
  File "/home/example.py", line 62, in <module>
    bus.i2c_rdwr(write, read)
  File "/home/.local/lib/python3.12/site-packages/smbus2/smbus2.py", line 658, in i2c_rdwr
    ioctl(self.fd, I2C_RDWR, ioctl_data)
BlockingIOError: [Errno 11] Resource temporarily unavailable

oops.se

Oh your using a Raspberry Pi 5, that has a different hardware that previous models, check if your libraries has been updated to Raspberry Pi 5 hardware.

neng1

the smbus2 library?

neng1

i already updated

neng1

the code was working perfectly untill one day I didnt shut down the raspberry pi properly it just doesnt work anymore since then

oops.se

Perhaps you should have mentioned that from start.

neng1

ooow so sth is broken?

oops.se

A poweroff can cause a corupted filesystem, perhaps you should check that first.

neng1

oooh okay

neng1

which file is used in this case

neng1

after running this command
sudo dmesg | grep i2c

neng1

i get a ton of this
[22341.795707] i2c_designware 1f00074000.i2c: i2c_dw_handle_tx_abort: lost arbitration