Hello everyone!
I've been trying to get my BH1750FVI sensor working on my Wemos D1 R2 board.
At first the code did not see the sensor, neither did the I2C scanner. But after some rewiring I got the
ESP8266 I2C scanner to pick him up. It returns the following:
I2C Scanner
Scanning...
I2C device found at address 0x23 !
The address it find corresponds with the address it should be. (Note: I did not connect the ADDR pin to GND)
After I2c picked it up, I used the BH1750 library to test the sensor, but when I run the following code:
/*
Example of BH1750 library usage.
This example initialises the BH1750 object using the default high resolution
continuous mode and then makes a light level reading every second.
Connection:
VCC -> 3V3 or 5V
GND -> GND
SCL -> SCL (A5 on Arduino Uno, Leonardo, etc or 21 on Mega and Due, on esp8266 free selectable)
SDA -> SDA (A4 on Arduino Uno, Leonardo, etc or 20 on Mega and Due, on esp8266 free selectable)
ADD -> (not connected) or GND
ADD pin is used to set sensor I2C address. If it has voltage greater or equal to
0.7VCC voltage (e.g. you've connected it to VCC) the sensor address will be
0x5C. In other case (if ADD voltage less than 0.7 * VCC) the sensor address will
be 0x23 (by default).
*/
#include <Wire.h>
#include <BH1750.h>
BH1750 lightMeter;
void setup(){
Serial.begin(9600);
// Initialize the I2C bus (BH1750 library doesn't do this automatically)
Wire.begin();
// On esp8266 you can select SCL and SDA pins using Wire.begin(D4, D3);
if (lightMeter.begin()) {
Serial.println(F("BH1750 initialised"));
}
else {
Serial.println(F("Error initialising BH1750"));
}
Serial.println(F("BH1750 Test begin"));
}
void loop() {
uint16_t lux = lightMeter.readLightLevel();
Serial.print("Light: ");
Serial.print(lux);
Serial.println(" lx");
delay(1000);
}
I returns this:
[BH1750] ERROR: received NACK on transmit of address
[BH1750] ERROR: received NACK on transmit of data
[BH1750] ERROR: other error
[BH1750] ERROR: undefined error
Error initialising BH1750
BH1750 Test begin
[BH1750] Device is not configured!
Light: 0 lx
This would mean he can't find the sensor on the I2C, even though he can pick it up with the scanner!
Does anyone have any idea how to fix this, or which tests to run/perform to find what's wrong?
Wiring:
VCC -> 3.3v
GND -> GND
SCL -> D1 (SCL pin on ESP8266)
SDA -> D2 (SDA pin on ESP8266)
