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.
i2c.writeto(address, register, stop=False), too many argumen
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
-
- Posts: 3
- Joined: Tue Aug 21, 2012 11:55 am
- tannewt
- Posts: 3315
- Joined: Thu Oct 06, 2016 8:48 pm
Re: i2c.writeto(address, register, stop=False), too many arg
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]) )`
-
- Posts: 3
- Joined: Tue Aug 21, 2012 11:55 am
Re: i2c.writeto(address, register, stop=False), too many arg
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.
- tannewt
- Posts: 3315
- Joined: Thu Oct 06, 2016 8:48 pm
Re: i2c.writeto(address, register, stop=False), too many arg
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.
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.
Please be positive and constructive with your questions and comments.