BH1750 icon indicating copy to clipboard operation
BH1750 copied to clipboard

[BH1750] Device is not configured!

Open dhanushmk opened this issue 7 years ago • 36 comments

i am getting this in serial monitor t: 0 lx BH1750 Test [BH1750] Device is not configured!

dhanushmk avatar Jan 08 '18 04:01 dhanushmk

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 avatar Jan 08 '18 09:01 claws

@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);

}

image

Amy1610 avatar Jan 09 '18 15:01 Amy1610

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?:

arduino 1 arduino 2 arduino 3

Amy1610 avatar Jan 09 '18 16:01 Amy1610

I just found that the 12C scanner cannot find the device

Amy1610 avatar Jan 09 '18 19:01 Amy1610

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.

claws avatar Jan 10 '18 11:01 claws

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.

Amy1610 avatar Jan 10 '18 12:01 Amy1610

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:

image

BTW this is my code:

image

Thank you in advance for your response

EdrickeAPM avatar Jan 29 '18 15:01 EdrickeAPM

@EdrickeAPM I have the exact same issue .. have you fixed it yet? :)

priema avatar Feb 07 '18 12:02 priema

@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);

coelner avatar Mar 10 '18 15:03 coelner

I have the exact same issue .. have you a better fix? thx

dvbahder avatar Apr 04 '18 21:04 dvbahder

@dvbahder No. Has your sensor worked in the past?

coelner avatar Apr 05 '18 17:04 coelner

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

dvbahder avatar Apr 05 '18 21:04 dvbahder

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 image image

dvbahder avatar Apr 06 '18 09:04 dvbahder

what is the purpose for adding readLightLevel (true)?

Xj98 avatar Jun 13 '18 06:06 Xj98

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.

coelner avatar Jun 13 '18 13:06 coelner

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 avatar Jun 20 '18 17:06 Alacika

@Alacika

  1. Do you use the same sensor for each wemos board?
  2. Did the ESPeasy firmware work on all your wemos boards, including D1 Pro and D1 lite?
  3. Post your sketch

coelner avatar Jun 21 '18 06:06 coelner

  1. Yes! (But I tried another BH1750 sensors too, and the problem is the same.)
  2. I tested ESPeasy firmware with only D1 Pro
  3. Uhh, my sketch is not so professional. :-) Sketch

Alacika avatar Jun 21 '18 06:06 Alacika

  1. At least one sensor is working. Some of your boards not. --> Some boards are broken/not usable.
  2. Different pin out? Wrong pin settings in the arduino toolchain? I don't have those boards, only a guess
  3. 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.

coelner avatar Jun 21 '18 10:06 coelner

  1. 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.
  2. 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().
  3. 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.

Alacika avatar Jun 21 '18 10:06 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!

Alacika avatar Jun 21 '18 18:06 Alacika

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.

coelner avatar Jun 21 '18 19:06 coelner

I somewhat managed to fix this by wire.begin(D1, D2) I get not error but just blank serial monitor...

quintendewilde avatar Dec 20 '18 10:12 quintendewilde

@quintendewilde Some more infos about the board, wiring and sketch?

coelner avatar Dec 20 '18 12:12 coelner

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?

chengzee avatar Mar 28 '20 17:03 chengzee

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.

coelner avatar Mar 28 '20 18:03 coelner

Thanks for your answer!

  1. I download the ZIP and use examples/BH1750test. sorry, I don't know which version I used. could you help me find out?
  2. 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.

chengzee avatar Mar 29 '20 07:03 chengzee

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.

IoTThinks avatar Mar 29 '20 07:03 IoTThinks

@chengzee

  1. You use the latest version, it is fine.
  2. 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)?
  3. 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);

}

coelner avatar Mar 29 '20 08:03 coelner

@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! 90988386_525005348207828_8162284178646237184_n 90765274_857237214688861_6172368767473942528_n image

chengzee avatar Mar 29 '20 12:03 chengzee