Hello,
I want to use two sensors per i2c on arduino uno r4 wifi.
How can i call them?
#define TSL2561_Address_1 0x29
#define TSL2561_Address_2 0x39
TSL2561_CalculateLux tsl2561_1;
TSL2561_CalculateLux tsl2561_2;
// Current time
unsigned long currentTime = millis();
unsigned long previousTime = 0;
// Define timeout time in milliseconds (example: 2000ms = 2s)
const long timeoutTime = 2000;
int status = WL_IDLE_STATUS;
WiFiServer server(80);
void setup() {
Wire.begin();
Serial.begin(9600);
tsl2561_1.init(); // Initialize tsl1 to address 0x39
tsl2561_2.init();
Yes. Light Sensor ist hardcoded.
Now our library do not contain the method to use two device simultaneously, but you can use this module to expand your same I2C device: Grove - I2C Hub | Seeed Studio Wiki
1 Like
I bought already Grove multiplexer. TCA9548A.
Hello, you can test by this method:
- first I suppose you have acquired the address of two sensors
- create a new function for initalize multiple sensors, you can add a function like:
void mutliDeviceInit(int Multi_Device_Address);
into the public method of the header file in library, and add the function content into the cpp file like below:
void TSL2561_CalculateLux::mutliDeviceInit(int Multi_Device_Address)//Use like TSL2561.mutliDeviceInit(TSL2561_Address_1) to initialize
{
writeRegister(Multi_Device_Address, TSL2561_Control, 0x03); // POWER UP
writeRegister(Multi_Device_Address, TSL2561_Timing, 0x00); //No High Gain (1x), integration time of 13ms
writeRegister(Multi_Device_Address, TSL2561_Interrupt, 0x00);
writeRegister(Multi_Device_Address, TSL2561_Control, 0x00); // POWER Down
}
- the fuction above need you call it by the “TSL2561.mutliDeviceInit(TSL2561_Address_1)” in your arduino code
well, you can follow this method to adjust the library file to accommodate your needs
The multiplexer shows me only two devices: one light sensor ( I have three connected) and the hub itself with 0x70. I used the sample.ino from grove.
Hello, I feel sorry for you because of my misunderstanding, this Grove multiplexer is designed for expand your interfaces but not intended for forwarding addresses of the same I2C device. Now we do not have this kind of multiplexer.
1 Like
What can I do else? Any other technical possibilities?
Hello, the most common method to solve is using the time-sharing power supply: connect all of them well and control the power supply for each one at different time, if you wanna use A, you need to close B and C, but limited by the board so it may increases system complexity.
Meanwhile, some company have design the board to solve it, reference url is here: Gravity: Digital 1-to-8 I2C Multiplexer - DFRobot
I bought one. But I don’t get it. I2C Scanner shows port address 0x41. But no idea how to call/read the sensors.