Python Forum

Full Version: Probs with leading zeros falling away :-)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello all,

I need to write to an I2C bus

The problem is that i really need to send 0x000017 with this command to a device

<<bus_device.write(bytes([A_DEVICE_REGISTER]), stop=True)>>

When i set A_DEVICE_REGISTER to 0x000017 0x17 is send.
That's not what is needed for the device i want to send it to, the leading zero's must be send also

Anyone any idea how to solve this

Warm regards
0x000017 are 3 bytes.

Have you tried to do following:

bus.write_byte_data(0x00, 0x00, 0x17)
EDIT: Write which implementation you're using. The function has may be a different name.

Plain Python: https://pypi.org/project/smbus2/
CFFI: https://pypi.org/project/smbus-cffi/
C: http://www.lm-sensors.org/browser/i2c-to.../py-smbus/ (dead link)

And maybe you can refer to documentation of the device you want to talk to.
I2Cdevice

from adafruit_bus_device.i2c_device import I2CDevice

I don't think there is a write_byte_data

AttributeError: 'I2CDevice' object has no attribute 'write_byte_data'