kplindegaard / smbus2

A drop-in replacement for smbus-cffi/smbus-python in pure Python
MIT License
243 stars 68 forks source link

Trouble writing i2c messages #79

Open jjshoe opened 2 years ago

jjshoe commented 2 years ago

Trying to switch monitor inputs. I can accomplish this using ddccontrol or ddcutil on ubuntu linux.

For example: ddccontrol -r 0x60 -w 18 dev:/dev/i2c-4

This will change my monitor's input.

I have the following python code:

from smbus2 import SMBus, i2c_msg

with SMBus(4) as bus:
  message = i2c_msg.write(0x60, [0x12])
  bus.i2c_rdwr(message)

But I receive the following error:

Traceback (most recent call last):
  File "/home/jjshoe/buttons!/switch.py", line 5, in <module>
    bus.i2c_rdwr(message)
  File "/usr/local/lib/python3.10/dist-packages/smbus2/smbus2.py", line 658, in i2c_rdwr
    ioctl(self.fd, I2C_RDWR, ioctl_data)
OSError: [Errno 5] Input/output error

Thoughts on what I'm doing wrong?

kplindegaard commented 2 years ago

Skimming quickly through the decontrol source, I can't see what's wrong with your approach. Sorry :/ But since it's been so long since you asked, I hope you have figured it out already? If you have it would be cool to hear what the issue was.