CircuitPython i2c write value to register

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
User avatar
rwbaugher
 
Posts: 9
Joined: Mon Aug 31, 2015 3:24 pm

CircuitPython i2c write value to register

Post by rwbaugher »

I have a magnetometer sensor and need to send the value 0x70 to register address 0x00 at device address 0x20. boardio has a write method i2c.writeto(device address, register address), but I see no way to send a value. MicroPython has a writeto_mem method that does this. Is there a similar capability in CircuitPython?

User avatar
adafruit_support_carter
 
Posts: 29151
Joined: Tue Nov 29, 2016 2:45 pm

Re: CircuitPython i2c write value to register

Post by adafruit_support_carter »

Do you mean busio? (instead of boardio). Docs are here:
https://circuitpython.readthedocs.io/en ... 2C.writeto

The first parameter is the device address. The second parameter is a buffer which can contain more than one value and can be thought of as being general purpose. The exact way you would write/read a register can vary depending on the device. The details would be in the datasheet.

User avatar
rwbaugher
 
Posts: 9
Joined: Mon Aug 31, 2015 3:24 pm

Re: CircuitPython i2c write value to register

Post by rwbaugher »

Thanks for the help. Yes, I meant busio as you suggest.

According to the Register Map for the device, to send the value 0x70 to register address 0x00 at device address 0x20, the CircuitPython code would be i2c.writeto(0x20,bytes([0x00,0x70])), I believe.

In looking at the Arduino-compatible library for the sensor, it appears that the library had two sequential write commands, one for the address and one for the value which appears to be another way to accomplish this task.

User avatar
adafruit_support_carter
 
Posts: 29151
Joined: Tue Nov 29, 2016 2:45 pm

Re: CircuitPython i2c write value to register

Post by adafruit_support_carter »

That looks correct for a common usage case. The various CircuitPython driver libraries might also help to provide code examples.

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

Return to “Adafruit CircuitPython”