One sensor two I2C addresses

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
gerrikoio
 
Posts: 26
Joined: Wed Sep 24, 2014 7:48 pm

One sensor two I2C addresses

Post by gerrikoio »

Just getting to grips with CircuitPython and I have a sensor, which uses two I2C addresses. I was wondering what is best practice here as the address is registered when you assign an I2C device:

Code: Select all

 self.i2c_device = i2c_device.I2CDevice(i2c_bus, address)
Is this the one and only method available, ie

Code: Select all

self.i2c_device1_address1 = i2c_device.I2CDevice(i2c_bus, address1)
self.i2c_device1_address2 = i2c_device.I2CDevice(i2c_bus, address2)

User avatar
dastels
 
Posts: 15655
Joined: Tue Oct 20, 2015 3:22 pm

Re: One sensor two I2C addresses

Post by dastels »

Care to give somewhat more context?

Dave

User avatar
gerrikoio
 
Posts: 26
Joined: Wed Sep 24, 2014 7:48 pm

Re: One sensor two I2C addresses

Post by gerrikoio »

dastels wrote: Mon Mar 27, 2023 7:28 pm Care to give somewhat more context?
What sort of context are you looking for? I was looking at ST25DV nfc tags. Has an unusual case of multi I2C addresses.

Anyhow, this was merely an academic question as was wondering about the amount of memory used having two i2c objects. Wondered how else one would do it.

User avatar
adafruit_support_bill
 
Posts: 88088
Joined: Sat Feb 07, 2009 10:11 am

Re: One sensor two I2C addresses

Post by adafruit_support_bill »

The device type is an essential bit of context. Although it is not unusual for a device to have multiple i2c addresses, how they are used tends to be rather device specific. And that influences the design decisions and implementation of the driver/library.

In the case of the ST25DV nfc tags, the addresses are fixed, so there is no reason to supply them to the constructor.

User avatar
gerrikoio
 
Posts: 26
Joined: Wed Sep 24, 2014 7:48 pm

Re: One sensor two I2C addresses

Post by gerrikoio »

adafruit_support_bill wrote: Tue Mar 28, 2023 6:56 am In the case of the ST25DV nfc tags, the addresses are fixed, so there is no reason to supply them to the constructor.
Could you provide an example please, as this answers part of my question.

I'm looking at the CircuitPython documentation reference guide and I cannot work out how to apply a different address to an I2C read or write method without applying to the constructor:

https://docs.circuitpython.org/projects ... n_readinto

EDIT...

Ah @adafruit_support_bill, I see it now. Yes, I can define my "I2C device" within my application specific read or write function rather than in the constructor. Thanks for your comment as the penny hadn't quite dropped when I first read it.

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

Return to “Adafruit CircuitPython”