Closed ahostn closed 4 years ago
loop
function up into the setup
function, leaving the loop
function empty. Was this intentional?Hello. I'm pretty sure now that I have a hardware problem, your code is good. If I connect the GY-30 sensor, ESP8266 doesn't even connect to WiFi even if I use external power for the sensor. If I attach the sensor (+3.3V line) after wifi is connected, it works fine... until reset/sleep. i2c bus is not stuck, so it must be something with the sensor. Even your example code now works only if I connect power to the sensor after booting up, but it worked for the first time when I tried it.. :)
BH1750 lightMeter;
void setup() { Serial.begin(9600);
Wire.begin();
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); }
This is my code, I always get an error as "[BH1750] Device is not configured! Light: -2.00 lx" , how can i fixed that error. I can't ger proper output. ![Uploading Screenshot (58).png…]()
If you’re using deepSleep, you should move all your code in setup block, not main loop.
`/*
Advanced BH1750 library usage example
This example has some comments about advanced usage features.
Connection:
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
include
define durationSleep 10
/* BH1750 can be physically configured to use two I2C addresses:
0x5C (if ADD pin had > 0.7VCC voltage)
Library uses 0x23 address as default, but you can define any other address. If you had troubles with default value - try to change it to 0x5C.
*/ BH1750 lightMeter(0x23);
void setup() {
Serial.begin(115200);
// Initialize the I2C bus (BH1750 library doesn't do this automatically) Wire.begin(D7, D8); // On esp8266 you can select SCL and SDA pins using Wire.begin(D4, D3);
/*
*/
// 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")); }
float lux = lightMeter.readLightLevel(); Serial.print("Light: "); Serial.print(lux); Serial.println(" lx"); delay(1000);
ESP.deepSleep(durationSleep * 1000000); }
void loop() {
}`
Any ideas why deepSleep breaks the library ?