Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

connect sensor to 2nd I2C bus #24

Closed
borlowsky opened this issue Apr 20, 2022 · 4 comments
Closed

connect sensor to 2nd I2C bus #24

borlowsky opened this issue Apr 20, 2022 · 4 comments

Comments

@borlowsky
Copy link

Hi, thanks a lot for this excellent library. I have a project where I want to connect two SHT30-sensors to an ESP32 and wonder whether it's possible to connect an SHT30 to the 2nd I2C bus of the ESP32. Did not find out whether it's possible to pass the bus as an argument to init() or to the constructur... Thanks for any hint!

@winkj
Copy link
Member

winkj commented Apr 20, 2022

Hi there,

This is indeed possible, the init() function allows to use an optional TwoWire parameter: https://github.com/Sensirion/arduino-sht/blob/master/SHTSensor.cpp#L285.

At this point, the autodetect does not work on the second bus, but I just merged #23 which will address this. To make it work with the current version, you will have to create the SHTSensor with a sensor type, like so:

SHTSensor sht1(SHTSensor::SHT3X);
SHTSensor sht2(SHTSensor::SHT3X);

// ...
 Wire.begin();
// ...

sht1.init(<insert bus 1 here>);
sht2.init(<insert bus 2 here>);

You can start with the multiple-sht-sensors.ino example as a starting point, change both sensors to be SHT3X (assuming they are), and then add the two busses as arguments to init(...)

I will close this, feel free to reopen if you run into any issues!

Best, Johannes

@winkj winkj closed this as completed Apr 20, 2022
@borlowsky
Copy link
Author

borlowsky commented Apr 21, 2022 via email

@winkj
Copy link
Member

winkj commented Apr 21, 2022

Thanks a lot for testing!

I just pushed a new release (1.2.2) which includes the fix for autodetect, so changes are the following will work too:

SHTSensor sht1, sht2; // autodetect

// ...
 Wire.begin();
// ...

sht1.init(/* insert bus 1 here */;
sht2.init(/* insert bus 2 here */;

@borlowsky
Copy link
Author

borlowsky commented Apr 25, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants