Open dhanushmk opened 6 years ago
That error gets reported from readLightLevel
if BH1750_MODE attribute is not set. The BH1750_MODE attribute is set in configure
which is called from the begin
function. It is initialised to UNCONFIGURED and is defaulted to CONTINUOUS_HIGH_RES_MODE in the declaration of the the begin
function.
The typical usage of this library is:
#include <BH1750.h>
BH1750 lightMeter;
void setup(){
lightMeter.begin();
}
void loop() {
uint16_t lux = lightMeter.readLightLevel();
}
My best guess would be that perhaps you are not calling begin
to initialise and configure the BH1750 library.
The serial output you pasted does not look like any of the examples. Was this output from an example? Are you using the current version of the library? What platform are you running on? What is the code you are running?
@claws I am having the exact same problem...
Here is my code:
BH1750 lightMeter(0x23);
void setup(){
Serial.begin(9600);
Wire.begin();
lightMeter.begin(); Serial.println(F("test"));
}
void loop() {
uint16_t lux = lightMeter.readLightLevel(); Serial.print("Light: "); Serial.print(lux); Serial.println(" lx"); delay(1000);
}
I downloaded the library yesterday and need to use it for a uni project due soon,
could it be the way I have set up my arduino?:
I just found that the 12C scanner cannot find the device
It looks like you have wired it up correctly from the pictures.
The BH1750 library returns a boolean value from begin
to indicate whether the device was configured successfully. You could print that out to check what it says. Modify your setup
function to initialise the lightMeter like this:
if (lightMeter.begin()) {
Serial.println(F("BH1750 initialised"));
}
else {
Serial.println(F("Error initialising BH1750"));
}
When I run the i2c_scanner you mentioned I see the following output:
I2C Scanner
Scanning...
I2C device found at address 0x23 !
done
I'm going to guess that perhaps your sensor device is faulty. Do you have access to another to test this out?
I have just run all three of the examples on 2 separate sensor devices and they work as I expect. When I run the simple example without plugging in the light sensor board I observed the following output:
BH1750 Test begin
[BH1750] Device is not configured!
Light: 0 lx
You could remove the wire connect ADD to GND. It is not required. The library uses the i2c address of 0x23 by default. I see you were explicitly defining the device address as 0x23 and wiring the ADD line to ground. That is fine and explicit. The same configuration would be achieved by not wiring the ADD line at all and not explicitly passing 0x23 when instantiating the lightMeter - such as in the simple example.
I modified my setup function to initialise the lightmeter as you have stated and it returns: "[BH1750] Device is not configured! Light: 0 lx" still rather than either printing "BH1750 initialised" or "Error initialising BH1750"
Yeah, the light sensor is probably faulty. I have ordered another one which should arrive Friday. Meanwhile I will have to hope that the code i have written, to include the device in my project, is correct as I have no way of testing it until the sensor arrives :-/
Thanks for your help and the speedy reply!
Would you be willing to look over my project code to see if it makes sense? It would be really helpful as I am very new to using arduino. Although I understand if you don't want to or do not have time to.
Hi! I'm Working on my BH1750 Light Sensor. I tried running the codes from this forum but there are no readings from my sensor the Serial monitor just displays:
BTW this is my code:
Thank you in advance for your response
@EdrickeAPM I have the exact same issue .. have you fixed it yet? :)
@priema @EdrickeAPM Do you tried another I2C device? Maybe the cable are not in a good shape.
Change following:
uint16_t lux = lightMeter.readLightLevel();
--> uint16_t lux = lightMeter.readLightLevel(true);
I have the exact same issue .. have you a better fix? thx
@dvbahder No. Has your sensor worked in the past?
no, I bought the sensor three weeks ago. OneWire DS18B20 works, wire DHT22 works, Display I2C works, as a single sensor BH1750 does not work, I read from a scanner for I2C and want to try it tomorrow. I'll let you know. thx to coelner
The scanner says the address is correct (0x23 GND default), (0x5c high). PIN SCL SDA was swapped, correct SDA / SCL (D4, D3) ... is runnig :) thx
what is the purpose for adding readLightLevel (true)?
https://github.com/claws/BH1750/blob/68afd5820169fd422e535773865153725eb38612/BH1750.h#L63
It activates a different delay value for the measurement. This value is maximum wait value and the sensor will have a new measurement ready to deliver.
The code works: Wemos D1 mini The code does not work: Wemos D1 Pro and Wemos D1 Lite I do not know why. I tried everything.
Then I uploaded the ESPeasy firmware and sensor works fine, print lux info in serial console. I2C scanner sketch says: Found address: 35 (0x23), but it does not work I tried 0x5C address (ADDR to VCC), but it does not work. I have 2 Wemos D1 Mini which goes well, and I have 3 other Wemos D1 Mini that do not work anyway.
Sorry for my poor english!
@Alacika
Some new test logs:
Wemos D1 Pro (ESPEasy) 250 : INIT : Booting version: v2.0-20180316 250 : INIT : Cold Boot 251 : FS : Mounting... 276 : FS : Mount successful, used 75802 bytes of 957314 395 : INIT : Free RAM:22488 395 : INIT : I2C 395 : INIT : SPI not enabled 1288 : WIFI : Connecting SSID attempt #1 5206 : WD : Uptime 0 ConnectFailures 0 FreeMem 19680 5363 : BH1750 Address: 0x23 Mode: 0x99 : Light intensity: 27.50 16026 : BH1750 Address: 0x23 Mode: 0x99 : Light intensity: 28.32 26651 : BH1750 Address: 0x23 Mode: 0x99 : Light intensity: 33.33 37288 : BH1750 Address: 0x23 Mode: 0x99 : Light intensity: 33.33
Wemos D1 Pro (BH1750test.ino example sketch from this library) [BH1750] ERROR: received NACK on transmit of address [BH1750] ERROR: received NACK on transmit of data [BH1750] ERROR: other error [BH1750] ERROR: undefined error BH1750 Test begin [BH1750] Device is not configured! Light: 0 lx [BH1750] Device is not configured! Light: 0 lx [BH1750] Device is not configured!
There is a problem with i2c in a generic way. wrong settings in the ide, wrong parameter in the toolchain, It is not a problem of this library. You could use a logic analyzer to research this issue. @Alacika Are you on the master branch of esp8266? Currently I get this problem too, but it occurs rarely.
I somewhat managed to fix this by wire.begin(D1, D2) I get not error but just blank serial monitor...
@quintendewilde Some more infos about the board, wiring and sketch?
hi, I have the similar issue and try above method but not work for me. My device is mega2560. This is the code I used
#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);
lightMeter.begin();
Serial.println(F("BH1750 Test begin"));
}
void loop() {
float lux = lightMeter.readLightLevel();
Serial.print("Light: ");
Serial.print(lux);
Serial.println(" lx");
delay(1000);
}
I only connect a GY-302 (BH1750) sensor. This is how I connect the wire : VCC -> 3V3 or 5V (I have tried each of them) GND -> GND SCL -> SCL SDA -> SDA ADD -> not connected
and this is the result
BH1750 Test begin [BH1750] Device is not configured! Light: -2.00 lx [BH1750] Device is not configured! Light: -2.00 lx [BH1750] Device is not configured! Light: -2.00 lx [BH1750] Device is not configured! Light: -2.00 lx [BH1750] Device is not configured! Light: -2.00 lx
Could you help me please?
Which version of this library do you use? Did you verify the wiring with another library or atl east a i2c scan? you could check the return value from lightMeter.begin() and reconfigure the sensor.
Thanks for your answer!
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: XX XX XX XX XX XX XX XX XX XX XX XX XX
10: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
20: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
30: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
40: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
50: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
60: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
70: XX XX XX XX XX XX XX XX
[BH1750] ERROR: other error [BH1750] Device is not configured! Light: -2.00 lx
I'm Sorry with so many question and very thanks for your help again. Thanks.
My esp32 works fine with this library.
Make very SURE that the pins are soldered properly. If the pins are loosen when the board boots, it will show "Device not configured" forever.
@chengzee
#include <Wire.h>
#include <BH1750.h>
bool BH1750Check = false; 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);
BH1750Check = lightMeter.begin(); if (BH1750Check) { Serial.println(F("BH1750 Test begin")); } else { Serial.println(F("BH1750 Initialization FAILED")); while (true) //flow trap {} }
}
void loop() {
if (BH1750Check) { float lux = lightMeter.readLightLevel(); Serial.print("Light: "); Serial.print(lux); Serial.println(" lx"); } delay(1000);
}
@coelner @IoTThinks Thanks for your answers!!!!! I learn a lot from you guys, thank you. And it works!! I found it just like @IoTThinks said. The sensor need to be very strongly connect. If it is loose, it won't have correct value and i2c would be failed. So I took a looooot of time to solder it (it's my first time...btw, I burned the first one BH1750). Finally, it works very well. I'm very appreciate you guys. Thank you!
In my case it was very weird. I had the same issue but connecting ir to 5v instead of 3.3v do the trick. I used a arduino nano and a GY-302 The only diference it's that i didn't use ADDR conection since i was using only one sensor.
[Solved] After changing new wires the example worked fine. Thanks for your code. It took me hours to figure out
@jafidiesel
In my case it was very weird. I had the same issue but connecting ir to 5v instead of 3.3v do the trick. Oh man, thanks for that. This was the problem also for me when migrating my code from a wemos D1 where things worked fine with the BH1750 powered with 3.3.V to an ESP32. Moving the sensor to 5V on the ESP32 did the trick indeed. What a relief :)
I used to also get the same issue on my Arduino Uno. But I solved it... pin setting which gave me an error: VCC - 3.3V GND - GND SCL - A5 SDA - A4 ADD - GND ( also the combination where i did not connect this pin)
But putting VCC to 5V and also Having ADD to GND helped me.
Yep, you usually need the same VCC. The VCC defines the level thresholds of thr i2c bus and if you do not use a level shifter you are limited to a common VCC. (Voltage at the common collector ) The ADD line is related to GND depending on the specific pcb. Sometimes the pull-down resistor is missing which leads ADD floating
[Solved] I see BH1750advanced.ino that code:
Full mode list:
BH1750_CONTINUOUS_LOW_RES_MODE BH1750_CONTINUOUS_HIGH_RES_MODE (default) BH1750_CONTINUOUS_HIGH_RES_MODE_2
BH1750_ONE_TIME_LOW_RES_MODE BH1750_ONE_TIME_HIGH_RES_MODE BH1750_ONE_TIME_HIGH_RES_MODE_2
// begin returns a boolean that can be used to detect setup problems. if (lightMeter.begin(BH1750::CONTINUOUS_HIGH_RES_MODE)) { Serial.println(F("BH1750 Advanced begin")); } else { Serial.println(F("Error initialising BH1750")); }
I think we have to use MODE in lightMeter.begin() .
And, in case WEMOS D1 R1 board (Arduino type) I use SDA/D4 SCL/D3
but, I use GPIO pins numbers in the sketch. So:
Wire.begin(4, 5);
Because at the WEMOS D1 R1 board (Arduino type) SDA/D4 = GPIO4 SCL/D3 = GPIO5
i am getting this in serial monitor t: 0 lx BH1750 Test [BH1750] Device is not configured!