Python Forum
Probs with leading zeros falling away :-)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Probs with leading zeros falling away :-)
#1
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
Reply
#2
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.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#3
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'
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Removing leading whitespaces palladium 1 717 Mar-24-2023, 04:15 PM
Last Post: bowlofred
  Removing leading\trailing spaces azizrasul 8 2,685 Oct-23-2022, 11:06 PM
Last Post: azizrasul
  How to retrieve records in a DataFrame (Python/Pandas) that contains leading or trail mmunozjr 3 1,752 Sep-05-2022, 11:56 AM
Last Post: Pedroski55
  -i option changes sys.path (removes leading empty string '') markanth 6 1,981 Aug-26-2022, 09:27 PM
Last Post: markanth
  remove zeros at the end of a number Frankduc 7 2,150 Feb-25-2022, 03:48 PM
Last Post: Frankduc
  Solving for zeros of an equation! fmitchell17 0 1,831 Apr-05-2021, 07:49 PM
Last Post: fmitchell17
  Dataframe Removes Zeros JoeDainton123 2 4,382 Sep-17-2020, 12:47 PM
Last Post: scidam
  How to keep leading zeros with pandas? eeps24 1 6,554 May-20-2020, 07:51 PM
Last Post: deanhystad
  Cancelling 'open directory' leading to crash Fairbz_ 1 2,185 May-08-2020, 03:14 PM
Last Post: DPaul
  leading zero number formatting RedSkeleton007 3 3,938 Jan-27-2019, 04:56 PM
Last Post: RedSkeleton007

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020