- Edited
HjalteBestedMoeller I need to interface several I2C adresses. Do I need to instantiate one I2c object for each I2C address ?
yes, if you are inheriting from our I2c
virtual class.
HjalteBestedMoeller I following the I2C_MPR121, but in the writeRegister(uint8_t reg, uint8_t value) method, no I2C address is used, which is why I'm wondering... I'm not very into I2C yet...
This class expects you to have one different object per address. You set the I2C address in the call to initI2C_RW()
. If you look at Bela/include/I2c.h
, you will see that there is a line there that sets the address for the open file descriptor:
if (ioctl(i2C_file, I2C_SLAVE, i2C_address) < 0){
If you were to change address for the same object, you'd have to call this line every time you change the address, in advance of calling writeRegister()
.
(also note that the last argument to initI2C_RW()
is there for legacy reasons and it is ignored).