IP Configuration
This commit is contained in:
1
lib/BH1750/.gitignore
vendored
Normal file
1
lib/BH1750/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
.DS_Store
|
||||
27
lib/BH1750/.travis.yml
Normal file
27
lib/BH1750/.travis.yml
Normal file
@@ -0,0 +1,27 @@
|
||||
language: cpp
|
||||
env:
|
||||
global:
|
||||
- ARDUINO_PACKAGE_VERSION=1.8.5
|
||||
- DISPLAY=:1.0
|
||||
|
||||
before_install:
|
||||
# arduino requires an X server even with command line
|
||||
- /sbin/start-stop-daemon --start --quiet --pidfile /tmp/xvfb_$TRAVIS_JOB_NUMBER.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :1 -ac -screen 0 1280x1024x16
|
||||
|
||||
install:
|
||||
- wget -q -O- http://downloads.arduino.cc/arduino-$ARDUINO_PACKAGE_VERSION-linux64.tar.xz | tar -Jxf -
|
||||
- sudo mv arduino-$ARDUINO_PACKAGE_VERSION /usr/local/share/arduino
|
||||
- sudo ln -s /usr/local/share/arduino/arduino /usr/local/bin/arduino
|
||||
# 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
|
||||
# link project directory into Arduino libraries area.
|
||||
- ln -s $PWD /usr/local/share/arduino/libraries/BH1750
|
||||
|
||||
script:
|
||||
# uno
|
||||
- arduino --verify --board arduino:avr:uno $PWD/examples/BH1750test/BH1750test.ino
|
||||
- arduino --verify --board arduino:avr:uno $PWD/examples/BH1750advanced/BH1750advanced.ino
|
||||
# esp8266
|
||||
# - arduino --verify --board esp8266:esp8266:generic $PWD/examples/BH1570test/BH1750test.ino
|
||||
# - arduino --verify --board esp8266:esp8266:generic $PWD/examples/BH1570advanced/BH1750advanced.ino
|
||||
207
lib/BH1750/BH1750.cpp
Normal file
207
lib/BH1750/BH1750.cpp
Normal file
@@ -0,0 +1,207 @@
|
||||
/*
|
||||
|
||||
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.
|
||||
|
||||
Written by Christopher Laws, March, 2013.
|
||||
|
||||
Modified by Dan Ogorchock on 2018-07-04 for ST_Anything compatability
|
||||
|
||||
*/
|
||||
|
||||
#include "BH1750.h"
|
||||
|
||||
// Define milliseconds delay for ESP8266 platform
|
||||
#if defined(ESP8266)
|
||||
|
||||
#include <pgmspace.h>
|
||||
#define _delay_ms(ms) delayMicroseconds((ms) * 1000)
|
||||
|
||||
// Use _delay_ms from utils for AVR-based platforms
|
||||
#elif defined(__avr__)
|
||||
#include <util/delay.h>
|
||||
|
||||
// Use Wiring's delay for compability with another platforms
|
||||
#else
|
||||
#define _delay_ms(ms) delay(ms)
|
||||
#endif
|
||||
|
||||
|
||||
// Legacy Wire.write() function fix
|
||||
#if (ARDUINO >= 100)
|
||||
#define __wire_write(d) Wire.write(d)
|
||||
#else
|
||||
#define __wire_write(d) Wire.send(d)
|
||||
#endif
|
||||
|
||||
|
||||
// Legacy Wire.read() function fix
|
||||
#if (ARDUINO >= 100)
|
||||
#define __wire_read() Wire.read()
|
||||
#else
|
||||
#define __wire_read() Wire.receive()
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @params addr Sensor address (0x23 or 0x5C, see datasheet)
|
||||
*
|
||||
* Default for BH1750 is 0x23
|
||||
*/
|
||||
BH1750::BH1750(byte addr) {
|
||||
|
||||
BH1750_I2CADDR = addr;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Configure sensor
|
||||
* @param mode Measurement mode
|
||||
*/
|
||||
bool BH1750::begin(Mode mode) {
|
||||
|
||||
// I2C is expected to be initialized outside this library
|
||||
//DGO Revision for ST_Anything compatability - all other I2C sensor initialize I2C.
|
||||
// This one was the exception, but I have modified it to be like the others.
|
||||
Wire.begin();
|
||||
// Configure sensor in specified mode
|
||||
return configure(mode);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Configure BH1750 with specified mode
|
||||
* @param mode Measurement mode
|
||||
*/
|
||||
bool BH1750::configure(Mode mode) {
|
||||
|
||||
// default transmission result to a value out of normal range
|
||||
byte ack = 5;
|
||||
|
||||
// Check measurement mode is valid
|
||||
switch (mode) {
|
||||
|
||||
case BH1750::CONTINUOUS_HIGH_RES_MODE:
|
||||
case BH1750::CONTINUOUS_HIGH_RES_MODE_2:
|
||||
case BH1750::CONTINUOUS_LOW_RES_MODE:
|
||||
case BH1750::ONE_TIME_HIGH_RES_MODE:
|
||||
case BH1750::ONE_TIME_HIGH_RES_MODE_2:
|
||||
case BH1750::ONE_TIME_LOW_RES_MODE:
|
||||
|
||||
// Send mode to sensor
|
||||
Wire.beginTransmission(BH1750_I2CADDR);
|
||||
__wire_write((uint8_t)BH1750_MODE);
|
||||
ack = Wire.endTransmission();
|
||||
|
||||
// Wait a few moments to wake up
|
||||
_delay_ms(10);
|
||||
break;
|
||||
|
||||
default:
|
||||
// Invalid measurement mode
|
||||
Serial.println(F("[BH1750] ERROR: Invalid mode"));
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
// Check result code
|
||||
switch (ack) {
|
||||
case 0:
|
||||
BH1750_MODE = mode;
|
||||
return true;
|
||||
case 1: // too long for transmit buffer
|
||||
Serial.println(F("[BH1750] ERROR: too long for transmit buffer"));
|
||||
case 2: // received NACK on transmit of address
|
||||
Serial.println(F("[BH1750] ERROR: received NACK on transmit of address"));
|
||||
case 3: // received NACK on transmit of data
|
||||
Serial.println(F("[BH1750] ERROR: received NACK on transmit of data"));
|
||||
case 4: // other error
|
||||
Serial.println(F("[BH1750] ERROR: other error"));
|
||||
default:
|
||||
Serial.println(F("[BH1750] ERROR: undefined error"));
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Read light level from sensor
|
||||
* @return Light level in lux (0 ~ 65535)
|
||||
*/
|
||||
uint16_t BH1750::readLightLevel(bool maxWait) {
|
||||
|
||||
if (BH1750_MODE == UNCONFIGURED) {
|
||||
Serial.println(F("[BH1750] Device is not configured!"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Measurement result will be stored here
|
||||
uint16_t level=65535;
|
||||
|
||||
// Send mode to sensor
|
||||
Wire.beginTransmission(BH1750_I2CADDR);
|
||||
__wire_write((uint8_t)BH1750_MODE);
|
||||
Wire.endTransmission();
|
||||
|
||||
// Wait for measurement to be taken.
|
||||
// Measurements have a maximum measurement time and a typical measurement
|
||||
// time. The maxWait argument determines which measurement wait time is
|
||||
// used when a one-time mode is being used. The typical (shorter)
|
||||
// measurement time is used by default and if maxWait is set to True then
|
||||
// the maximum measurement time will be used. See data sheet pages 2, 5
|
||||
// and 7 for more details.
|
||||
// A continuous mode measurement can be read immediately after re-sending
|
||||
// the mode command.
|
||||
|
||||
switch (BH1750_MODE) {
|
||||
|
||||
case BH1750::ONE_TIME_LOW_RES_MODE:
|
||||
case BH1750::ONE_TIME_HIGH_RES_MODE:
|
||||
case BH1750::ONE_TIME_HIGH_RES_MODE_2:
|
||||
|
||||
if (BH1750_MODE == BH1750::ONE_TIME_LOW_RES_MODE) {
|
||||
maxWait ? _delay_ms(24) : _delay_ms(16);
|
||||
}
|
||||
else {
|
||||
maxWait ? _delay_ms(180) :_delay_ms(120);
|
||||
}
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
// Read two bytes from the sensor, which are low and high parts of the sensor
|
||||
// value
|
||||
Wire.requestFrom(BH1750_I2CADDR, 2);
|
||||
if (Wire.available() == 2) {
|
||||
level = __wire_read();
|
||||
level <<= 8;
|
||||
level |= __wire_read();
|
||||
}
|
||||
|
||||
// Print raw value if debug enabled
|
||||
#ifdef BH1750_DEBUG
|
||||
Serial.print(F("[BH1750] Raw value: "));
|
||||
Serial.println(level);
|
||||
#endif
|
||||
|
||||
// Convert raw value to lux
|
||||
level /= 1.2;
|
||||
|
||||
// Print converted value if debug enabled
|
||||
#ifdef BH1750_DEBUG
|
||||
Serial.print(F("[BH1750] Converted value: "));
|
||||
Serial.println(level);
|
||||
#endif
|
||||
|
||||
return level;
|
||||
|
||||
}
|
||||
76
lib/BH1750/BH1750.h
Normal file
76
lib/BH1750/BH1750.h
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
|
||||
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
|
||||
|
||||
Written by Christopher Laws, March, 2013.
|
||||
|
||||
Modified by Dan Ogorchock on 2018-07-04 for ST_Anything compatability
|
||||
*/
|
||||
|
||||
#ifndef BH1750_h
|
||||
#define BH1750_h
|
||||
|
||||
#if (ARDUINO >= 100)
|
||||
#include <Arduino.h>
|
||||
#else
|
||||
#include <WProgram.h>
|
||||
#endif
|
||||
|
||||
#include "Wire.h"
|
||||
|
||||
// Uncomment, to enable debug messages
|
||||
// #define BH1750_DEBUG
|
||||
|
||||
// No active state
|
||||
#define BH1750_POWER_DOWN 0x00
|
||||
|
||||
// Wating for measurement command
|
||||
#define BH1750_POWER_ON 0x01
|
||||
|
||||
// Reset data register value - not accepted in POWER_DOWN mode
|
||||
#define BH1750_RESET 0x07
|
||||
|
||||
//I2C Addresses
|
||||
#define BH1750_ADDR_LOW 0x23
|
||||
#define BH1750_ADDR_HIGH 0x5C
|
||||
|
||||
class BH1750 {
|
||||
|
||||
public:
|
||||
|
||||
enum Mode
|
||||
{
|
||||
UNCONFIGURED = 0,
|
||||
// Measurement at 1lx resolution. Measurement time is approx 120ms.
|
||||
CONTINUOUS_HIGH_RES_MODE = 0x10,
|
||||
// Measurement at 0.5lx resolution. Measurement time is approx 120ms.
|
||||
CONTINUOUS_HIGH_RES_MODE_2 = 0x11,
|
||||
// Measurement at 4lx resolution. Measurement time is approx 16ms.
|
||||
CONTINUOUS_LOW_RES_MODE = 0x13,
|
||||
// Measurement at 1lx resolution. Measurement time is approx 120ms.
|
||||
ONE_TIME_HIGH_RES_MODE = 0x20,
|
||||
// Measurement at 0.5lx resolution. Measurement time is approx 120ms.
|
||||
ONE_TIME_HIGH_RES_MODE_2 = 0x21,
|
||||
// Measurement at 1lx resolution. Measurement time is approx 120ms.
|
||||
ONE_TIME_LOW_RES_MODE = 0x23
|
||||
};
|
||||
|
||||
BH1750(byte addr = BH1750_ADDR_LOW);
|
||||
bool begin(Mode mode = CONTINUOUS_HIGH_RES_MODE);
|
||||
bool configure(Mode mode);
|
||||
uint16_t readLightLevel(bool maxWait = false);
|
||||
|
||||
private:
|
||||
int BH1750_I2CADDR;
|
||||
Mode BH1750_MODE = UNCONFIGURED;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
21
lib/BH1750/LICENSE
Normal file
21
lib/BH1750/LICENSE
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2018 claws
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
142
lib/BH1750/README.md
Normal file
142
lib/BH1750/README.md
Normal file
@@ -0,0 +1,142 @@
|
||||
# BH1750
|
||||
|
||||
[](https://travis-ci.org/claws/BH1750)<br>
|
||||
|
||||
This package contains an Arduino library for digital light sensor breakout boards containing the
|
||||
BH1750FVI IC.
|
||||
|
||||
The BH1750 board uses I2C for communication which requires two pins to
|
||||
communicate with the device. Configuring the I2C bus must be done in user code
|
||||
(not library code). This approach has been adopted so it can be done once and
|
||||
will better support the various options for different platforms.
|
||||
|
||||
A common module containing the BH1750 component is the GY-30 shown below.
|
||||
|
||||

|
||||
|
||||
|
||||
## Overview
|
||||
|
||||
The BH1750 has six different measurement modes which are divided in two groups;
|
||||
continuous and one-time measurements. In continuous mode the sensor
|
||||
continuously measures lightness value. In one-time mode, the sensor makes only
|
||||
one measurement and then goes into Power Down mode.
|
||||
|
||||
Each mode has three different precisions:
|
||||
|
||||
- Low Resolution Mode - (4 lx precision, 16ms measurement time)
|
||||
- High Resolution Mode - (1 lx precision, 120ms measurement time)
|
||||
- High Resolution Mode 2 - (0.5 lx precision, 120ms measurement time)
|
||||
|
||||
By default, this library uses Continuous High Resolution Mode, but you can
|
||||
change this to a different mode by passing the mode argument to
|
||||
BH1750.begin().
|
||||
|
||||
When the One-Time mode is used your sensor will go into Power Down mode when
|
||||
it completes the measurement and you've read it. When the sensor is powered up
|
||||
again it returns to the default mode which means it needs to be reconfigured
|
||||
back into One-Time mode. This library has been implemented to automatically
|
||||
reconfigure the sensor when you next attempt a measurement so you should not
|
||||
have to worry about such low level details.
|
||||
|
||||
The datasheet for the BH1750 chip can be obtained [here](http://www.elechouse.com/elechouse/images/product/Digital%20light%20Sensor/bh1750fvi-e.pdf)
|
||||
|
||||
|
||||
## Installation
|
||||
|
||||
Click "Clone or download" -> "Download ZIP" button.
|
||||
|
||||
- **(For Arduino >= 1.5.x)** Use the way above, or Library Manager. Open Arduino
|
||||
IDE, click `Sketch -> Include library -> Add .ZIP library ` and select the
|
||||
downloaded archive.
|
||||
|
||||
- **(For Arduino < 1.5.x)** Extract the archive to
|
||||
``<Your User Directory>/My Documents/Arduino/libraries/`` folder and rename it
|
||||
to `BH1750`. Restart IDE.
|
||||
|
||||
The following YouTube [video](https://youtu.be/ACTMQvPVMLs) (specifically from
|
||||
7:20 onwards) provides a good overview of installing this library and loading
|
||||
an example using the Arduino IDE.
|
||||
|
||||
[](https://youtu.be/ACTMQvPVMLs?t=437)
|
||||
|
||||
Additional info, about library installation process - https://www.arduino.cc/en/Guide/Libraries
|
||||
|
||||
|
||||
## Example
|
||||
|
||||
An example using the BH1750 library in conjunction with the GY-30 board
|
||||
(which contains the BH1750 component) is presented below. The example
|
||||
code uses the BH1750 library in the default continuous high precision
|
||||
mode when making light measurements.
|
||||
|
||||
### Wiring
|
||||
|
||||
Connections:
|
||||
|
||||
- VCC -> 3V3 or 5V
|
||||
- GND -> GND
|
||||
- SCL -> SCL (A5 on Arduino Nano, Uno, Leonardo, etc or 21 on Mega and Due, on esp8266 free selectable)
|
||||
- SDA -> SDA (A4 on Arduino Nano, Uno, Leonardo, etc or 20 on Mega and Due, on esp8266 free selectable)
|
||||
- ADD -> NC/GND or VCC (see below)
|
||||
|
||||
The ADD pin is used to set the sensor I2C address. By default (if ADD voltage
|
||||
less than 0.7 * VCC) the sensor address will be 0x23. 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.
|
||||
|
||||
Wiring up the GY-30 sensor board to an Arduino is shown in the diagram below.
|
||||
|
||||

|
||||
|
||||
*The image above was created using [Fritzing](http://fritzing.org/home/) and
|
||||
the GY-30 module was obtained from [here](http://omnigatherum.ca/wp/?p=6)*.
|
||||
|
||||
### Code
|
||||
|
||||
Upload the BH1750 test code to your Arduino.
|
||||
|
||||
``` c++
|
||||
#include <Wire.h>
|
||||
#include <BH1750.h>
|
||||
|
||||
BH1750 lightMeter;
|
||||
|
||||
void setup(){
|
||||
|
||||
Serial.begin(9600);
|
||||
|
||||
// Initialize the I2C bus (BH1750 library doesn't do this automatically)
|
||||
// On esp8266 devices you can select SCL and SDA pins using Wire.begin(D4, D3);
|
||||
Wire.begin();
|
||||
|
||||
lightMeter.begin();
|
||||
Serial.println(F("BH1750 Test"));
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
uint16_t lux = lightMeter.readLightLevel();
|
||||
Serial.print("Light: ");
|
||||
Serial.print(lux);
|
||||
Serial.println(" lx");
|
||||
delay(1000);
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
### Output
|
||||
|
||||
Moving the sensor to face more light results in the lux measurements increasing.
|
||||
```
|
||||
BH1750 Test
|
||||
Light: 70 lx
|
||||
Light: 70 lx
|
||||
Light: 59 lx
|
||||
Light: 328 lx
|
||||
Light: 333 lx
|
||||
Light: 335 lx
|
||||
Light: 332 lx
|
||||
```
|
||||
There are more examples in the examples directory.
|
||||
31
lib/BH1750/build-examples.bash
Normal file
31
lib/BH1750/build-examples.bash
Normal file
@@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# A simple script to automate building BH1750 examples.
|
||||
#
|
||||
# Example (MacOSX):
|
||||
# $ ARDUINO_IDE_PATH=/Applications/Arduino.app/Contents/Java ./build-examples.bash
|
||||
#
|
||||
|
||||
# Path to script directory.
|
||||
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
|
||||
LIBNAME="$(basename "$SCRIPTPATH")"
|
||||
|
||||
if [[ -z "${ARDUINO_IDE_PATH}" ]]; then
|
||||
echo "ARDUINO_IDE_PATH env var is not set"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Link BH1750 library into Arduino libraries directory
|
||||
ln -s $SCRIPTPATH $ARDUINO_IDE_PATH/libraries/
|
||||
|
||||
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
|
||||
done
|
||||
|
||||
# Unlink BH1750 library from Arduino libraries directory
|
||||
unlink $ARDUINO_IDE_PATH/libraries/$LIBNAME
|
||||
1
lib/BH1750/component.mk
Normal file
1
lib/BH1750/component.mk
Normal file
@@ -0,0 +1 @@
|
||||
COMPONENT_ADD_INCLUDEDIRS := .
|
||||
96
lib/BH1750/examples/BH1750advanced/BH1750advanced.ino
Normal file
96
lib/BH1750/examples/BH1750advanced/BH1750advanced.ino
Normal file
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
|
||||
Advanced BH1750 library usage example
|
||||
|
||||
This example has some comments about advanced usage features.
|
||||
|
||||
Connection:
|
||||
|
||||
VCC -> 3V3 or 5V
|
||||
GND -> GND
|
||||
SCL -> SCL (A5 on Arduino Uno, Leonardo, etc or 21 on Mega and Due, on esp8266 free selectable)
|
||||
SDA -> SDA (A4 on Arduino Uno, Leonardo, etc or 20 on Mega and Due, on esp8266 free selectable)
|
||||
ADD -> (not connected) or GND
|
||||
|
||||
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 <Wire.h>
|
||||
#include <BH1750.h>
|
||||
|
||||
/*
|
||||
|
||||
BH1750 can be physically configured to use two I2C addresses:
|
||||
- 0x23 (most common) (if ADD pin had < 0.7VCC voltage)
|
||||
- 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(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);
|
||||
|
||||
/*
|
||||
|
||||
BH1750 has six different measurement modes. They are divided in two groups;
|
||||
continuous and one-time measurements. In continuous mode, sensor continuously
|
||||
measures lightness value. In one-time mode the sensor makes only one
|
||||
measurement and then goes into Power Down mode.
|
||||
|
||||
Each mode, has three different precisions:
|
||||
|
||||
- Low Resolution Mode - (4 lx precision, 16ms measurement time)
|
||||
- High Resolution Mode - (1 lx precision, 120ms measurement time)
|
||||
- High Resolution Mode 2 - (0.5 lx precision, 120ms measurement time)
|
||||
|
||||
By default, the library uses Continuous High Resolution Mode, but you can
|
||||
set any other mode, by passing it to BH1750.begin() or BH1750.configure()
|
||||
functions.
|
||||
|
||||
[!] Remember, if you use One-Time mode, your sensor will go to Power Down
|
||||
mode each time, when it completes a measurement and you've read it.
|
||||
|
||||
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"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
|
||||
uint16_t lux = lightMeter.readLightLevel();
|
||||
Serial.print("Light: ");
|
||||
Serial.print(lux);
|
||||
Serial.println(" lx");
|
||||
delay(1000);
|
||||
|
||||
}
|
||||
42
lib/BH1750/examples/BH1750onetime/BH1750onetime.ino
Normal file
42
lib/BH1750/examples/BH1750onetime/BH1750onetime.ino
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
|
||||
Example of BH1750 library usage.
|
||||
|
||||
This example initialises the BH1750 object using the high resolution
|
||||
one-time mode and then makes a light level reading every second.
|
||||
|
||||
The BH1750 component starts up in default mode when it next powers up.
|
||||
The BH1750 library automatically reconfigures the one-time mode in
|
||||
preparation for the next measurement.
|
||||
|
||||
*/
|
||||
|
||||
#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(BH1750::ONE_TIME_HIGH_RES_MODE);
|
||||
|
||||
Serial.println(F("BH1750 One-Time Test"));
|
||||
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
|
||||
uint16_t lux = lightMeter.readLightLevel();
|
||||
Serial.print("Light: ");
|
||||
Serial.print(lux);
|
||||
Serial.println(" lx");
|
||||
delay(1000);
|
||||
|
||||
}
|
||||
52
lib/BH1750/examples/BH1750test/BH1750test.ino
Normal file
52
lib/BH1750/examples/BH1750test/BH1750test.ino
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
|
||||
Example of BH1750 library usage.
|
||||
|
||||
This example initialises the BH1750 object using the default high resolution
|
||||
continuous mode and then makes a light level reading every second.
|
||||
|
||||
Connection:
|
||||
|
||||
VCC -> 3V3 or 5V
|
||||
GND -> GND
|
||||
SCL -> SCL (A5 on Arduino Uno, Leonardo, etc or 21 on Mega and Due, on esp8266 free selectable)
|
||||
SDA -> SDA (A4 on Arduino Uno, Leonardo, etc or 20 on Mega and Due, on esp8266 free selectable)
|
||||
ADD -> (not connected) or GND
|
||||
|
||||
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 <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() {
|
||||
|
||||
uint16_t lux = lightMeter.readLightLevel();
|
||||
Serial.print("Light: ");
|
||||
Serial.print(lux);
|
||||
Serial.println(" lx");
|
||||
delay(1000);
|
||||
|
||||
}
|
||||
33
lib/BH1750/keywords.txt
Normal file
33
lib/BH1750/keywords.txt
Normal file
@@ -0,0 +1,33 @@
|
||||
#######################################
|
||||
# Syntax Coloring Map For BH1750
|
||||
#######################################
|
||||
|
||||
#######################################
|
||||
# Datatypes (KEYWORD1)
|
||||
#######################################
|
||||
|
||||
BH1750 KEYWORD1
|
||||
|
||||
#######################################
|
||||
# Methods and Functions (KEYWORD2)
|
||||
#######################################
|
||||
|
||||
begin KEYWORD2
|
||||
configure KEYWORD2
|
||||
readLightLevel KEYWORD2
|
||||
|
||||
|
||||
#######################################
|
||||
# Instances (KEYWORD2)
|
||||
#######################################
|
||||
|
||||
|
||||
#######################################
|
||||
# Constants (LITERAL1)
|
||||
#######################################
|
||||
BH1750_CONTINUOUS_HIGH_RES_MODE LITERAL1
|
||||
BH1750_CONTINUOUS_HIGH_RES_MODE_2 LITERAL1
|
||||
BH1750_CONTINUOUS_LOW_RES_MODE LITERAL1
|
||||
BH1750_ONE_TIME_HIGH_RES_MODE LITERAL1
|
||||
BH1750_ONE_TIME_HIGH_RES_MODE_2 LITERAL1
|
||||
BH1750_ONE_TIME_LOW_RES_MODE LITERAL1
|
||||
11
lib/BH1750/library.json
Normal file
11
lib/BH1750/library.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"name": "BH1750",
|
||||
"keywords": "light, sensor",
|
||||
"description": "Digital light sensor breakout boards containing the BH1750FVI IC",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/claws/BH1750.git"
|
||||
},
|
||||
"frameworks": "arduino",
|
||||
"platforms": ["atmelavr", "atmelsam", "espressif8266"]
|
||||
}
|
||||
10
lib/BH1750/library.properties
Normal file
10
lib/BH1750/library.properties
Normal file
@@ -0,0 +1,10 @@
|
||||
name=BH1750
|
||||
version=1.1.3
|
||||
author=Christopher Laws
|
||||
maintainer=Christopher Laws
|
||||
sentence=Digital light sensor breakout boards containing the BH1750FVI IC
|
||||
paragraph=Pretty simple and robust BH1750 library
|
||||
category=Sensors
|
||||
url=https://github.com/claws/BH1750
|
||||
architectures=*
|
||||
includes=BH1750.h
|
||||
BIN
lib/BH1750/resources/gy30-module.jpg
Normal file
BIN
lib/BH1750/resources/gy30-module.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 206 KiB |
BIN
lib/BH1750/resources/wiring-diagram-gy30-module.png
Normal file
BIN
lib/BH1750/resources/wiring-diagram-gy30-module.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 62 KiB |
Reference in New Issue
Block a user