Hi,
I removed Wire.beginTransmission(i2cAddress); and Wire.endTransmission(); from your code
uint16_t BH1750FVI::getAmbientLight(void){
uint16_t ambientLightValue;
//Wire.beginTransmission(i2cAddress);
Wire.requestFrom(i2cAddress, 2);
ambientLightValue = Wire.read();
ambientLightValue <<= 8;
ambientLightValue |= Wire.read();
//Wire.endTransmission();
ambientLightValue = ambientLightValue/1.2; // s. page 7 of datasheet for calculation
return ambientLightValue;
}
My code looks like
#include <Arduino.h>
#include "i2cdetect.h"
#include <Wire.h> // I2C Arduino library
#include <BH1750FVI.h> // BH1750FVI Light sensor library
BH1750FVI LightSensor;
uint16_t lux;
const uint8_t first = 0x03;
const uint8_t last = 0x77;
void setup() {
Wire.begin();
Serial.begin(115200);
Serial.println("\ni2cdetect \n");
Serial.printf("Scanning address range %02x-%02x\n\n", first, last);
i2cdetect(first, last);
delay(2000);
LightSensor.begin();
LightSensor.setMode(Continuously_High_Resolution_Mode);
Serial.println("Light sensor BH1750FVI found and running");
}
void loop() {
lux = LightSensor.getAmbientLight();
Serial.print("Ambient light intensity: ");
Serial.print(lux);
Serial.println(" lux");
delay(2000);
}
Output:
i2cdetect
Scanning address range 03-77
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- 23 -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
Light sensor BH1750FVI found and running
Ambient light intensity: 0 lux
Ambient light intensity: 54612 lux
Ambient light intensity: 54612 lux
Ambient light intensity: 54612 lux
Ambient light intensity: 54612 lux
Ambient light intensity: 54612 lux
But the value of LightSensor.getAmbientLight(); is constantly the same. Even when I disconnect the power from the BH12750 this value is "read" from the sensor.
I'm using a ESP8266-12e and BH1750FVI (3.3V or 5V) at D1 & D2.
Any idea on how to get this thing flying?
Hi,
I removed Wire.beginTransmission(i2cAddress); and Wire.endTransmission(); from your code
My code looks like
Output:
But the value of LightSensor.getAmbientLight(); is constantly the same. Even when I disconnect the power from the BH12750 this value is "read" from the sensor.
I'm using a ESP8266-12e and BH1750FVI (3.3V or 5V) at D1 & D2.
Any idea on how to get this thing flying?