Addressing Multiple GY-30 BH1750 light intensity sensors on Arduino Uno

Hi, im struggling to get two separate output values for the sensors. even though i have connected the one to ground and the other to Vcc. any ideas on how to correct the following code?

#include <Wire.h> //BH1750 IIC Mode
#include <math.h>
int BH1750address1 = 0x23; //setting i2c address
int BH1750address2 = 0x5C;

byte buff[4];

void setup() {
// put your setup code here, to run once:
Wire.begin();
Serial.begin(9600);
}

void loop() {
// put your main code here, to run repeatedly:
int i;
uint16_t val1,val2;
BH1750_Init(BH1750address1);
BH1750_Init2(BH1750address2);

delay(200);

while(2==BH1750_Read(BH1750address1)| 4==BH1750_Read(BH1750address2) )
{
if (Serial.read() == 0x23)
{
val1=((buff[0]<<8 )|buff[1])/1.2;
Serial.print(val1,DEC);
Serial.println(" 1 : [lx]");
}

else
{
val2=((buff[0]<<8 )|buff[1])/1.2;
Serial.print(val2,DEC);
Serial.println(" 2 : [lx]");
}

delay(500);

}

delay(150);

}
int BH1750_Read(int address)
{
int i=0;
Wire.beginTransmission(address);
Wire.requestFrom(address, 2);
while(Wire.available())
{
buff = Wire.read(); // receive one byte

  • i++;*
  • }*
  • Wire.endTransmission(); *
  • return i;*
    }

void BH1750_Init(int address)
{

  • Wire.beginTransmission(address);*
  • Wire.write(0x10); //1lx reolution 120ms*
  • Wire.endTransmission();*
    }
    void BH1750_Init2(int address)
    {
  • Wire.beginTransmission(address);*
  • Wire.write(0x05); //1lx reolution 120ms*
  • Wire.endTransmission();*
    }

Hi, im struggling to get two separate output values for the sensors. even though i have connected the one to ground and the other to Vcc.

Presumably, you mean that you connected some pin that defines the address of the sensor to VCC or Ground. A schematic would be useful. A link to the device in question would be useful, too.

 while(2==BH1750_Read(BH1750address1)| 4==BH1750_Read(BH1750address2) )

The OR operator is ||, not |.

Spacesareagoodthing.

void BH1750_Init(int address)
{
   Wire.beginTransmission(address);
   Wire.write(0x10); //1lx reolution 120ms
   Wire.endTransmission();
}
void BH1750_Init2(int address)
{
   Wire.beginTransmission(address);
   Wire.write(0x05); //1lx reolution 120ms
   Wire.endTransmission();
}

How can 0x10 and 0x05 mean the same thing? What does reolution mean, anyway?

Why do you need two functions? One function that took a second argument would be simpler.

Why do you call those functions on every pass through loop()?