TroubleshootingArduino

SEN0390 ambient light lux sensor with multiple I2C

userHead Duncan.Wilson 2023-06-18 17:56:53 504 Views7 Replies

When using a single SEN0390 with a MKR1010 board I get good readings from the sensor. When I also connect an HDC1080 sensor via I2C I am getting a lux value of -1 and the default non reading on the HDC1080. If I use the HDC1080 by itself it works fine.
 

When I do an I2C scan using https://playground.arduino.cc/Main/I2cScanner/ the address for the SEN0390 seems to be 0x4A (I thought it would be 0x94 based on library on GitHub (line 35 of DFROBOT_B_LUX_V30B.h) at https://github.com/DFRobot/DFRobot_B_LUX_V30B

 

Not sure what else to try - any suggestions?

 

Code I am trying on MKR1010 is below:

 

#include <DFRobot_B_LUX_V30B.h>

#include <Wire.h> // used for HDC1080 temp / hum sensor

#include "Adafruit_HDC1000.h"

DFRobot_B_LUX_V30B myLux(13);

Adafruit_HDC1000 hdc = Adafruit_HDC1000();

 

void setup() {

 Serial.begin(115200); 

 myLux.begin();

 if (!hdc.begin()) {

  Serial.println("Couldn't find sensor!");

  while (1);

 }

}

 

void loop() {

 Serial.print("Light: ");

 Serial.print(myLux.lightStrengthLux());

 Serial.print(" - Temperature: ");

 Serial.print(hdc.readTemperature());

 Serial.print(" - Humidity: ");

 Serial.println(hdc.readHumidity());

 delay(1000);

}


 

2024-06-24 17:59:54

It seems like you're encountering an issue where the HDC1080 sensor works fine by itself but doesn't function correctly when connected alongside the SEN0390 lux sensor on your MKR1010 board. Let's address this step by step:

### Addressing the I2C Address Discrepancy

1. **I2C Address of SEN0390**: According to the DFROBOT_B_LUX_V30B library you're using, the I2C address should be 0x94. However, during your I2C scan, it shows up as 0x4A. This discrepancy could arise due to different addressing schemes (sometimes addresses are shifted left by 1 bit to include the read/write bit in the LSB position).

  - **0x4A vs. 0x94**: These addresses could be representing the same physical address. In I2C communication, addresses are 7-bit values (shifted left by 1 bit for the actual address), so 0x4A (binary 01001010) and 0x94 (binary 10010100) could both refer to 0x4A.

2. **Ensure Proper Initialization Order**:
  - The order in which you initialize your sensors is crucial, especially in I2C communication where each device needs to be properly initialized before use.
  - Make sure to call `Wire.begin()` in your `setup()` function before initializing any I2C devices.

### Potential Issues and Solutions

1. **Power Supply**: Ensure that your MKR1010 board can supply sufficient current to both sensors. I2C devices are sensitive to power fluctuations. If the combined current draw exceeds what the board can supply, it might lead to unreliable operation.

2. **I2C Pull-up Resistors**: Check if your setup includes appropriate pull-up resistors (usually 4.7kΩ to 10kΩ) on the SDA and SCL lines of the I2C bus. Lack of pull-up resistors can cause communication issues, especially when adding multiple devices.

3. **Address Conflict or Bus Contention**:
  - Ensure that there is no address conflict on the I2C bus. If two devices have the same address, or if there is noise or interference on the bus, it can lead to communication failures.
  - Use an oscilloscope or logic analyzer if available to check for proper I2C communication signals on the bus.

4. **Library Compatibility**: Ensure that both libraries (`DFRobot_B_LUX_V30B` and `Adafruit_HDC1000`) are compatible with each other and with the MKR1010 board. Conflicting libraries or incorrect library versions can lead to unexpected behavior.

### Adjusted Code Suggestions

Here’s an adjusted version of your code with some additional considerations:

```cpp
#include <DFRobot_B_LUX_V30B.h>
#include <Wire.h>
#include "Adafruit_HDC1000.h"

DFRobot_B_LUX_V30B myLux(0x94); // Initialize SEN0390 with address 0x94

Adafruit_HDC1000 hdc;

void setup() {
 Serial.begin(115200);
 Wire.begin(); // Initialize I2C bus

 if (!myLux.begin()) {
   Serial.println("Failed to initialize SEN0390!");
   while (1);
 }

 if (!hdc.begin(0x40)) { // Initialize HDC1080 with address 0x40
   Serial.println("Couldn't find HDC1080 sensor!");
   while (1);
 }
}

void loop() {
 Serial.print("Light: ");
 Serial.print(myLux.lightStrengthLux());
 Serial.print(" Lux - Temperature: ");
 Serial.print(hdc.readTemperature());
 Serial.print(" °C - Humidity: ");
 Serial.print(hdc.readHumidity());
 Serial.println(" %");

 delay(1000);
}
```

### Changes Made:
- **I2C Address Initialization**: Use `0x94` directly when initializing `DFRobot_B_LUX_V30B` to match the address obtained from your I2C scan.
- **Initialization Order**: Ensure `Wire.begin()` is called before initializing any I2C devices.
- **Error Handling**: Added error handling for sensor initialization to ensure the program halts and notifies if initialization fails.

### Final Steps

- Double-check your wiring and connections to ensure there are no loose connections or accidental shorts.
- Verify that both sensors work individually and then reintroduce them together, testing each step to identify where the issue might arise.

By following these steps and adjustments, you should be able to resolve the issue of the HDC1080 sensor not functioning correctly alongside the SEN0390 lux sensor on your MKR1010 board.  https://www.oemstron.com/

userHeadPic JAMES.JACK
2023-06-19 11:44:39

SEN0390 is sealed by software IIC, and can not be used with other equipment or sensors using hardware IIC. Its address is 0x94.

userHeadPic jenna
jenna wrote:

I checked the library and this function can define the sensor pins.

For example:

 

sensor ——> board

VCC——>VCC

GND——>GND

SCL——> 7(digital pin)

SDA——> 8(digital pin)

EN——> 13(digital pin)

 

 

#include <DFRobot_B_LUX_V30B.h>

#include <Wire.h> // used for HDC1080 temp / hum sensor

#include "Adafruit_HDC1000.h"

DFRobot_B_LUX_V30B myLux(13,7,8);

Adafruit_HDC1000 hdc = Adafruit_HDC1000();

 

void setup() {

 Serial.begin(115200); 

 myLux.begin();

 if (!hdc.begin()) {

  Serial.println("Couldn't find sensor!");

  while (1);

 }

}

 

void loop() {

 Serial.print("Light: ");

 Serial.print(myLux.lightStrengthLux());

 Serial.print(" - Temperature: ");

 Serial.print(hdc.readTemperature());

 Serial.print(" - Humidity: ");

 Serial.println(hdc.readHumidity());

 delay(1000);

}

2023-06-19 15:43:10
Duncan.Wilson wrote:

Ah! Thanks for the tip. That works beautifully!

2023-06-19 18:34:33
Galang.Prab wrote:

Hello jenna, i try it but not work for me..

Can u help me for this??

2024-06-15 02:00:17
3 Replies
2023-06-18 22:34:29

I think you have to look inside the "Adafruit_HDC1000.h" and  DFRobot_B_LUX_V30B.h libraries. Maybe somewhere these two libraries are conflicting.Verify that the SEN0390 and HDC1080 have different I2C addresses. The I2C address of the SEN0390 should be 0x4A based on your I2C scan, and the HDC1080 default address is 0x40. If they have conflicting addresses, you might need to change the address of one of the sensors.

userHeadPic bidrohini.bidrohini
Duncan.Wilson wrote:

Thanks - have confirmed that SEN0390 seems to be 0x4A and HDC is 0x40 - therefore I believe that means they are not conflicting. 

2023-06-19 01:12:17
1 Replies