i2c.writeto(address, register, stop=False), too many argumen

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
leonardd
 
Posts: 3
Joined: Tue Aug 21, 2012 11:55 am

i2c.writeto(address, register, stop=False), too many argumen

Post by leonardd »

Playing with an i2c device (DFRobotics, URM09 ultrasonic distance sensor) on a PICO running CircuitPython 7.1.1. I am (using both Thonny and Mu editors) and I can read from all seven registers using:
....
i2c.writeto(device, bytes([register]))
i2c.readfrom_into(device, result)
....
That's great but I also want to write some data to the configuration register 7 but I don't seem to be able to do that.
I tried i2c.writeto(device, 0x07, bytes([0xa0]) ) which is similar to the MicroPython writeto_mem command but obviously this doesn't work, TypeError: extra positional arguments given. I have hunted around trying to find the CircuitPython equivalent for the write to an i2c register command but keep coming up short.

User avatar
tannewt
 
Posts: 3315
Joined: Thu Oct 06, 2016 8:48 pm

Re: i2c.writeto(address, register, stop=False), too many arg

Post by tannewt »

writeto doesn't know about a register at all. You probably just want to pack it into the first byte of the payload. Something like `i2c.writeto(device, bytes([0x07, 0xa0]) )`

leonardd
 
Posts: 3
Joined: Tue Aug 21, 2012 11:55 am

Re: i2c.writeto(address, register, stop=False), too many arg

Post by leonardd »

Wow, that is compact, I will try that. Anywhere out there in the wild that I might find documentation such as this? I just love this stuff! Thanks again.

User avatar
tannewt
 
Posts: 3315
Joined: Thu Oct 06, 2016 8:48 pm

Re: i2c.writeto(address, register, stop=False), too many arg

Post by tannewt »

The API is documented here: https://docs.circuitpython.org/en/lates ... #busio.I2C

We also have the essentials guide: https://learn.adafruit.com/circuitpytho ... python-i2c

I think the important point here is that I2C is just reading and writing bytes. Any additional meaning is given by the device, not the protocol. That's why we don't have a special mem function. The trickiest piece is usually the writeto_then_readfrom which does a write, repeated start and then a read.

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”