Comments (36)
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.
from bh1750.
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.
from bh1750.
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
from bh1750.
@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!
from bh1750.
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 :)
from bh1750.
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.
from bh1750.
- You use the latest version, it is fine.
- You have a general problem with i2c. There should be something at 0x23 or 0x5C. Do you have an alternative sensor? especially one which works? Do you use the pins| 20 (SDA), 21 (SCL)?
- The examples are not fail save. You could use this for a better understanding:
#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);
}
from bh1750.
[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
from bh1750.
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?
from bh1750.
@claws I am having the exact same problem...
Here is my code:
#include <Wire.h>
#include <BH1750.h>
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);
}
from bh1750.
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?:
from bh1750.
I just found that the 12C scanner cannot find the device
from bh1750.
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.
from bh1750.
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
from bh1750.
@EdrickeAPM I have the exact same issue .. have you fixed it yet? :)
from bh1750.
@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);
from bh1750.
I have the exact same issue .. have you a better fix? thx
from bh1750.
@dvbahder No. Has your sensor worked in the past?
from bh1750.
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
from bh1750.
what is the purpose for adding readLightLevel (true)?
from bh1750.
Line 63 in 68afd58
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.
from bh1750.
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!
from bh1750.
- Do you use the same sensor for each wemos board?
- Did the ESPeasy firmware work on all your wemos boards, including D1 Pro and D1 lite?
- Post your sketch
from bh1750.
- Yes! (But I tried another BH1750 sensors too, and the problem is the same.)
- I tested ESPeasy firmware with only D1 Pro
- Uhh, my sketch is not so professional. :-) Sketch
from bh1750.
- At least one sensor is working. Some of your boards not. --> Some boards are broken/not usable.
- Different pin out? Wrong pin settings in the arduino toolchain? I don't have those boards, only a guess
- Did you try the example sketch from this library? And another problem: https://github.com/Seeed-Studio/Grove_BME280/blob/bcf41a39e306a9b435c1140740ff0d7fc1001c45/Seeed_BME280.cpp#L5
remove this.
from bh1750.
- Yes. MyWemos D1 Mini (v2.x) and Wemos D2 Mini (v3.x) work well with my all (4pcs) BH1750 sensors. All other NodeMCU types work well, only my Wemos D1 Pro and Wemos D1 Lite do not work with any BH1750 sensor.
- The pins are the same: Wemos versions BME280 sensor works on the same I2C bus. Ok, I will mark a comment on "Wire.begin();" line, although the bh1750 error is earlier than executing bme280.init().
- Yes, I tried your sketches too, unsuccessful. I also tried Koepel's sketch, and I remember it worked (not all modes) but tonight I try it again.
from bh1750.
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!
from bh1750.
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.
from bh1750.
I somewhat managed to fix this by wire.begin(D1, D2)
I get not error but just blank serial monitor...
from bh1750.
@quintendewilde Some more infos about the board, wiring and sketch?
from bh1750.
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?
from bh1750.
Thanks for your answer!
- I download the ZIP and use examples/BH1750test. sorry, I don't know which version I used. could you help me find out?
- It seems like it's my i2c problem. Isn't it default 0x23 without connect ADDR? How to fix it?
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.
from bh1750.
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.
from bh1750.
[Solved] After changing new wires the example worked fine. Thanks for your code. It took me hours to figure out
from bh1750.
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.
from bh1750.
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
from bh1750.
Related Issues (20)
- Usage information MTreg HOT 3
- add this library to Arduino Library Manager HOT 13
- Hello, the library dont really want to work with my esp32s, anyone? HOT 52
- Lower bits of MTreg HOT 5
- Issue calling readLightLevel immediately after setMTReg HOT 5
- [BH1750] Set address _after_ constructor HOT 1
- Frequent calls to readLightLevel prevents measurement update HOT 2
- [BH1750] Device is not configured! ESP8266 afterESP.deepSleep HOT 4
- Trouble using 2 sensors HOT 3
- The library works for STM32 HOT 2
- [TIP] Device not configured - temporary fix. HOT 5
- BH1750 does not work on ESP32 HOT 3
- BH1750 MTreg min is 31 in the datasheet, HOT 2
- Debug messages can cause the MCU stuck HOT 1
- 'Wire1' was not declared in this scope; did you mean 'Wire'? HOT 1
- BH1750 readLightLevel() eventually returns 27k value in low light environment HOT 1
- Possible arithmetic error evident with larger MTreg
- delete
- clarification on executing next OneTime measurment and getting delay time HOT 2
- Arduino Uno R4 minima HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bh1750.