markbeee / bh1750fvi Goto Github PK
View Code? Open in Web Editor NEWArduino/ ESP8266 library for the ambient light sensor BH1750FVI
Arduino/ ESP8266 library for the ambient light sensor BH1750FVI
In the function "getAmbientLight()" you can remove the Wire.beginTransmission() and Wire.endTransmission(). They should only be used when writing data.
Hi,
I removed Wire.beginTransmission(i2cAddress); and Wire.endTransmission(); from your code
uint16_t BH1750FVI::getAmbientLight(void){
uint16_t ambientLightValue;
//Wire.beginTransmission(i2cAddress);
Wire.requestFrom(i2cAddress, 2);
ambientLightValue = Wire.read();
ambientLightValue <<= 8;
ambientLightValue |= Wire.read();
//Wire.endTransmission();
ambientLightValue = ambientLightValue/1.2; // s. page 7 of datasheet for calculation
return ambientLightValue;
}
My code looks like
#include <Arduino.h>
#include "i2cdetect.h"
#include <Wire.h> // I2C Arduino library
#include <BH1750FVI.h> // BH1750FVI Light sensor library
BH1750FVI LightSensor;
uint16_t lux;
const uint8_t first = 0x03;
const uint8_t last = 0x77;
void setup() {
Wire.begin();
Serial.begin(115200);
Serial.println("\ni2cdetect \n");
Serial.printf("Scanning address range %02x-%02x\n\n", first, last);
i2cdetect(first, last);
delay(2000);
LightSensor.begin();
LightSensor.setMode(Continuously_High_Resolution_Mode);
Serial.println("Light sensor BH1750FVI found and running");
}
void loop() {
lux = LightSensor.getAmbientLight();
Serial.print("Ambient light intensity: ");
Serial.print(lux);
Serial.println(" lux");
delay(2000);
}
Output:
i2cdetect
Scanning address range 03-77
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- 23 -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
Light sensor BH1750FVI found and running
Ambient light intensity: 0 lux
Ambient light intensity: 54612 lux
Ambient light intensity: 54612 lux
Ambient light intensity: 54612 lux
Ambient light intensity: 54612 lux
Ambient light intensity: 54612 lux
But the value of LightSensor.getAmbientLight(); is constantly the same. Even when I disconnect the power from the BH12750 this value is "read" from the sensor.
I'm using a ESP8266-12e and BH1750FVI (3.3V or 5V) at D1 & D2.
Any idea on how to get this thing flying?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.