mirror of
https://github.com/claws/BH1750.git
synced 2026-07-27 19:56:17 +00:00
cleanups
This commit is contained in:
@@ -15,6 +15,7 @@ install:
|
||||
# Add esp8266 board support
|
||||
# - arduino --pref "boardsmanager.additional.urls=http://arduino.esp8266.com/stable/package_esp8266com_index.json" --save-prefs
|
||||
# - arduino --install-boards esp8266:esp8266
|
||||
- arduino --pref "compiler.warning_level=all" --save-prefs
|
||||
# link project directory into Arduino libraries area.
|
||||
- ln -s $PWD /usr/local/share/arduino/libraries/BH1750
|
||||
|
||||
@@ -22,6 +23,10 @@ script:
|
||||
# uno
|
||||
- arduino --verify --board arduino:avr:uno $PWD/examples/BH1750test/BH1750test.ino
|
||||
- arduino --verify --board arduino:avr:uno $PWD/examples/BH1750advanced/BH1750advanced.ino
|
||||
- arduino --verify --board arduino:avr:uno $PWD/examples/BH1750onetime/BH1750onetime.ino
|
||||
- arduino --verify --board arduino:avr:uno $PWD/examples/BH1750autoadjust/BH1750autoadjust.ino
|
||||
# esp8266
|
||||
# - arduino --verify --board esp8266:esp8266:generic $PWD/examples/BH1570test/BH1750test.ino
|
||||
# - arduino --verify --board esp8266:esp8266:generic $PWD/examples/BH1570advanced/BH1750advanced.ino
|
||||
# - arduino --verify --board esp8266:esp8266:generic $PWD/examples/BH1750onetime/BH1750onetime.ino
|
||||
# - arduino --verify --board esp8266:esp8266:generic $PWD/examples/BH1750autoadjust/BH1750autoadjust.ino
|
||||
|
||||
+12
-9
@@ -166,17 +166,18 @@ bool BH1750::setMTreg(byte MTreg) {
|
||||
switch (ack) {
|
||||
case 0:
|
||||
BH1750_MTreg = MTreg;
|
||||
//Delay for specific continious mode to get valid values
|
||||
// Delay for specific continuous mode to get valid values
|
||||
switch (BH1750_MODE) {
|
||||
case BH1750::CONTINUOUS_LOW_RES_MODE:
|
||||
case BH1750::CONTINUOUS_LOW_RES_MODE:
|
||||
_delay_ms(24 * BH1750_MTreg/(byte)BH1750_DEFAULT_MTREG);
|
||||
break;
|
||||
case BH1750::CONTINUOUS_HIGH_RES_MODE:
|
||||
case BH1750::CONTINUOUS_HIGH_RES_MODE_2:
|
||||
case BH1750::CONTINUOUS_HIGH_RES_MODE:
|
||||
case BH1750::CONTINUOUS_HIGH_RES_MODE_2:
|
||||
_delay_ms(180 * BH1750_MTreg/(byte)BH1750_DEFAULT_MTREG);
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
case 1: // too long for transmit buffer
|
||||
Serial.println(F("[BH1750] ERROR: too long for transmit buffer"));
|
||||
@@ -200,7 +201,8 @@ bool BH1750::setMTreg(byte MTreg) {
|
||||
|
||||
/**
|
||||
* Read light level from sensor
|
||||
* The return value differs if the MTreg value is changed. The global maximum value is noted in the square brackets
|
||||
* The return value range differs if the MTreg value is changed. The global
|
||||
* maximum value is noted in the square brackets.
|
||||
* @return Light level in lux (0.0 ~ 54612,5 [117758,203])
|
||||
* -1 : no valid return value
|
||||
* -2 : sensor not configured
|
||||
@@ -237,9 +239,10 @@ float BH1750::readLightLevel(bool maxWait) {
|
||||
break;
|
||||
case BH1750::ONE_TIME_HIGH_RES_MODE:
|
||||
case BH1750::ONE_TIME_HIGH_RES_MODE_2:
|
||||
maxWait ? _delay_ms(180 * BH1750_MTreg/(byte)BH1750_DEFAULT_MTREG) :_delay_ms(120 * BH1750_MTreg/(byte)BH1750_DEFAULT_MTREG);
|
||||
maxWait ? _delay_ms(180 * BH1750_MTreg/(byte)BH1750_DEFAULT_MTREG) :_delay_ms(120 * BH1750_MTreg/(byte)BH1750_DEFAULT_MTREG);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
// Read two bytes from the sensor, which are low and high parts of the sensor
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
/*
|
||||
|
||||
This is a library for the BH1750FVI Digital Light Sensor
|
||||
breakout board.
|
||||
This is a library for the BH1750FVI Digital Light Sensor breakout board.
|
||||
|
||||
The BH1750 board uses I2C for communication. Two pins are required to
|
||||
interface to the device. Configuring the I2C bus is expected to be done
|
||||
in user code. The BH1750 library doesn't do this automatically.
|
||||
|
||||
Datasheet: http://rohmfs.rohm.com/en/products/databook/datasheet/ic/sensor/light/bh1750fvi-e.pdf
|
||||
Datasheet: http://www.elechouse.com/elechouse/images/product/Digital%20light%20Sensor/bh1750fvi-e.pdf
|
||||
|
||||
Written by Christopher Laws, March, 2013.
|
||||
|
||||
@@ -69,8 +68,9 @@ class BH1750 {
|
||||
private:
|
||||
byte BH1750_I2CADDR;
|
||||
byte BH1750_MTreg = (byte)BH1750_DEFAULT_MTREG;
|
||||
// Correction factor used to calculate lux. Typical value is 1.2 but can range from 0.96 to 1.44.
|
||||
// See data sheet (p.2, Measurement Accuracy) for more information.
|
||||
// Correction factor used to calculate lux. Typical value is 1.2 but can
|
||||
// range from 0.96 to 1.44. See the data sheet (p.2, Measurement Accuracy)
|
||||
// for more information.
|
||||
const float BH1750_CONV_FACTOR = 1.2;
|
||||
Mode BH1750_MODE = UNCONFIGURED;
|
||||
|
||||
|
||||
+7
-2
@@ -23,8 +23,13 @@ cd $ARDUINO_IDE_PATH
|
||||
for sketch in `find $SCRIPTPATH/examples -name '*.ino'`
|
||||
do
|
||||
echo "Compiling $sketch"
|
||||
./arduino-builder -hardware ./hardware -tools ./hardware/tools/avr -tools ./tools-builder -libraries ./libraries -fqbn arduino:avr:uno $sketch
|
||||
# ./arduino-builder -hardware ./hardware -tools ./hardware/tools/avr -tools ./tools-builder -libraries ./libraries -fqbn esp8266:esp8266:generic $sketch
|
||||
./arduino-builder -hardware ./hardware -tools ./hardware/tools/avr -tools ./tools-builder -libraries ./libraries -fqbn arduino:avr:uno --prefs "compiler.warning_level=all" $sketch
|
||||
# ./arduino-builder -hardware ./hardware -tools ./hardware/tools/avr -tools ./tools-builder -libraries ./libraries -fqbn esp8266:esp8266:generic --prefs "compiler.warning_level=all" $sketch
|
||||
if [ $? -ne 0 ]; then
|
||||
echo -e "\xe2\x9c\x96" # check icon
|
||||
else
|
||||
echo -e "\xe2\x9c\x93" # tick icon
|
||||
fi
|
||||
done
|
||||
|
||||
# Unlink BH1750 library from Arduino libraries directory
|
||||
|
||||
@@ -3,12 +3,14 @@
|
||||
Example of BH1750 library usage.
|
||||
|
||||
This example initialises the BH1750 object using the default high resolution
|
||||
one shot mode and then makes a light level reading every five second.
|
||||
one shot mode and then makes a light level reading every five seconds.
|
||||
|
||||
After the measurement the MTreg value is changed according to the result:
|
||||
lux > 40000 ==> MTreg = 32
|
||||
lux > 40000 ==> MTreg = 32
|
||||
lux < 40000 ==> MTreg = 69 (default)
|
||||
lux < 10 ==> MTreg = 138
|
||||
Remember to test your specific sensor! Maybe the MTreg value range from 32 up to 254 is not applicable to your unit.
|
||||
Remember to test your specific sensor! Maybe the MTreg value range from 32
|
||||
up to 254 is not applicable to your unit.
|
||||
|
||||
Connection:
|
||||
|
||||
@@ -39,7 +41,7 @@ void setup(){
|
||||
// On esp8266 you can select SCL and SDA pins using Wire.begin(D4, D3);
|
||||
|
||||
lightMeter.begin(BH1750::ONE_TIME_HIGH_RES_MODE);
|
||||
//lightMeter.setMTreg(69); //not needed, only mentioning it
|
||||
//lightMeter.setMTreg(69); // not needed, only mentioning it
|
||||
|
||||
Serial.println(F("BH1750 Test begin"));
|
||||
|
||||
@@ -51,9 +53,9 @@ void loop() {
|
||||
Serial.print(F("Light: "));
|
||||
Serial.print(lux);
|
||||
Serial.println(F(" lx"));
|
||||
|
||||
|
||||
if (lux < 0) {
|
||||
Serial.println(F("[DEBUG]: Error condition detected"));
|
||||
Serial.println(F("Error condition detected"));
|
||||
}
|
||||
else {
|
||||
if (lux > 40000.0) {
|
||||
@@ -62,13 +64,13 @@ void loop() {
|
||||
Serial.println(F("Setting MTReg to low value for high light environment"));
|
||||
}
|
||||
else {
|
||||
Serial.println(F("Error setting MTReg to default value for normal light environment"));
|
||||
Serial.println(F("Error setting MTReg to low value for high light environment"));
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (lux > 10.0) {
|
||||
// typical light environment
|
||||
if (lightMeter.setMTreg(69)) {
|
||||
if (lightMeter.setMTreg(69)) {
|
||||
Serial.println(F("Setting MTReg to default value for normal light environment"));
|
||||
}
|
||||
else {
|
||||
@@ -89,6 +91,6 @@ void loop() {
|
||||
}
|
||||
|
||||
}
|
||||
Serial.println(F("--------------------------------------"));
|
||||
Serial.println(F("--------------------------------------"));
|
||||
delay(5000);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user