Two DFRobot I2C sensors incompatible? Ambient Light (SEN0390) & SHT31 (SEN0385)

I purchased the following two sensors from you recently;
I’m using them with an Adafruit Feather M4 Express.
I can make each of the sensors work independently, but not together. They both claim to be I2C and the SHT31 device is working fine on the SCL/SDA pins of my M4. I am using the Adafruit library with it (Adafruit_SHT31) as the DFRobot one wouldn’t compile.
When I added the Light Sensor in parallel on the SDA/SCL pins neither sensor worked. I am using the DFRobot Library (GitHub - DFRobot/DFRobot_B_LUX_V30B) with this sensor as I can’t find out what chip its using to see if there is another option. I do have the Light Sensors EN pulled high too.
I then had a close look at the DFRobot_B_LUX_V30B library and can see it seems to be capable of using two seperate software driven pins for SDA/SCL, so I did that and again if I just run the code for Light sensor and comment out the code for the SHT31 or vice versa, I can make both sensors work…just not at same time.
Best I can tell it’s when I run the following in my setup()
I can no longer get readings from the SHT31 further down in my code. As soon as I comment that line out, SHT31 is all good again. It feels like the SW is the issue, I think connectivity is fine given both sensors work with no wiring change if I only have code for one at a time.
I can’t easily post my code but suspect you could very quickly see this issue yourselves if you use the two basic examples from each lib.

1 Like

Similar issue for this person.
The DFRobot/DFRobot_B_LUX_V30B library does not play nicely with others I suspect?

1 Like

Hey Paul,

Welcome to the forum!

They quickly discuss it in the forum post you liked but to talk to multiple I2C sensors with the same board you have to make sure that the addresses are different. I would try running this sketch here just to double check: Arduino Playground - I2cScanner

I had a look through the libraries for both of the sensors and it looks like they use 0x45 and 0x95 so you should be good on that front.

Taking a look at the DFrobot site you shouldnt have to use the Lux.begin() line if you are polling the sensor periodically(this might be hogging I2C communications).


Hi Liam,

Thanks for looking at my post.

I ran the i2c_scanner (with both sensors connected to my M4’s SDA/SCL) and confirmed the SHT31 is by default on 0x44 and the Ambient Light is 0x4A. So that’s all cool.

I have got it working though and it was two issues that needed to be addressed, and they are somewhat related.

1. Typos in the DFRobot Library
I too had another look at the DFRobot library for the Ambient Light Sensor (GitHub - DFRobot/DFRobot_B_LUX_V30B) and noticed a couple of errors in their code.
In that library in DFRobot_B_LUX_V30B.cpp they seem to very manually toggle or bit bang the I2C protocol onto the pins. Seems odd but anyway, in two of the functions they incorrectly reference the pins, they use “SDA” instead of “_SDA”, so they are messing with pins referenced outside their library. So to fix that you need to change any instance of “SDA” in their library to “_SDA”.
This alone did not fix the issue, see item 2 below.

2. Keep the Ambient Light Sensor on dedicated SDA/SCL pins
The DFRobot library has the ability to let the user specify which pins are used for SDA and SCL (as it seems intent on bit banging the I2C Proto).
For example you can tell it to use pin 6 for SCL and pin 5 for SDA with the following (ignore the 13 for now)
DFRobot_B_LUX_V30B myLux(13,6,5);
If you do that, and wire it there appropriately, then everything works. I can read from the SHT31 and the Ambient light sensor in the same sketch. I’m sure just a better library for the Ambient Light Sensor would allow it to coexist on the main I2C but that’s beyond my skill level.


Note: I have the Ambient Light Sensors SDA and SCL connected to pins 5 & 6 respectively on my Feather M4 now, and have the SHT31 still using the built in SDA/SCL pins.


Hey Paul,

Glad to hear you figured it out!!

Really cool work around modifying the library and using different pins for the ambient light sensor.