0.3.1 BH1750FVI_RT

This commit is contained in:
Rob Tillaart 2024-04-09 16:41:53 +02:00
parent b24851e77a
commit d072dafec9
22 changed files with 106 additions and 78 deletions

View File

@ -1,4 +1,5 @@
# These are supported funding model platforms # These are supported funding model platforms
github: RobTillaart github: RobTillaart
custom: "https://www.paypal.me/robtillaart"

View File

@ -1,12 +1,12 @@
name: Arduino-lint name: Arduino-lint
on: [push, pull_request] on: [push, pull_request]
jobs: jobs:
lint: lint:
runs-on: ubuntu-latest runs-on: ubuntu-latest
timeout-minutes: 5
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v4
- uses: arduino/arduino-lint-action@v1 - uses: arduino/arduino-lint-action@v1
with: with:
library-manager: update library-manager: update

View File

@ -1,4 +1,3 @@
---
name: Arduino CI name: Arduino CI
on: [push, pull_request] on: [push, pull_request]
@ -6,9 +5,10 @@ on: [push, pull_request]
jobs: jobs:
runTest: runTest:
runs-on: ubuntu-latest runs-on: ubuntu-latest
timeout-minutes: 20
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1 - uses: ruby/setup-ruby@v1
with: with:
ruby-version: 2.6 ruby-version: 2.6

View File

@ -9,10 +9,11 @@ on:
jobs: jobs:
test: test:
runs-on: ubuntu-latest runs-on: ubuntu-latest
timeout-minutes: 5
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v4
- name: json-syntax-check - name: json-syntax-check
uses: limitusus/json-syntax-check@v1 uses: limitusus/json-syntax-check@v2
with: with:
pattern: "\\.json$" pattern: "\\.json$"

View File

@ -1,9 +1,9 @@
// //
// FILE: BH1750FVI.cpp // FILE: BH1750FVI.cpp
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 0.3.0 // VERSION: 0.3.1
// PURPOSE: library for BH1750FVI lux sensor Arduino // PURPOSE: library for BH1750FVI lux sensor Arduino
// URL: https://github.com/RobTillaart/BH1750FVI // URL: https://github.com/RobTillaart/BH1750FVI_RT
#include "BH1750FVI.h" #include "BH1750FVI.h"
@ -65,7 +65,7 @@ bool BH1750FVI::isReady()
float BH1750FVI::getRaw(void) float BH1750FVI::getRaw(void)
{ {
return readData() * 0.833333333333f; // == 1 / 1.2; return readData() * 0.833333333333f; // == 1 / 1.2;
} }
@ -96,7 +96,7 @@ float BH1750FVI::getLux(void)
} }
if (_mode == BH1750FVI_MODE_HIGH2) if (_mode == BH1750FVI_MODE_HIGH2)
{ {
lux *= 0.5f; // P11 lux *= 0.5f; // P11
} }
return lux; return lux;
} }
@ -225,13 +225,13 @@ float BH1750FVI::setTemperature(int temp)
float BH1750FVI::setAngle(int degrees) float BH1750FVI::setAngle(int degrees)
{ {
_angle = constrain(degrees, -89, 89); _angle = constrain(degrees, -89, 89);
// Lamberts Law. // Lambert's Law.
_angleFactor = 1.0f / cos(_angle * (PI / 180.0f)); _angleFactor = 1.0f / cos(_angle * (PI / 180.0f));
return _angleFactor; return _angleFactor;
} }
// interpolation tables uses more RAM (versus progmem) // interpolation tables uses more RAM (versus PROGMEM)
float BH1750FVI::setWaveLength(int waveLength) float BH1750FVI::setWaveLength(int waveLength)
{ {
_waveLength = constrain(waveLength, 400, 715); _waveLength = constrain(waveLength, 400, 715);
@ -258,7 +258,7 @@ uint16_t BH1750FVI::readData()
if (_wire->requestFrom(_address, (uint8_t) 2) != 2) if (_wire->requestFrom(_address, (uint8_t) 2) != 2)
{ {
_error = BH1750FVI_ERROR_WIRE_REQUEST; _error = BH1750FVI_ERROR_WIRE_REQUEST;
return _data; // last value return _data; // last value
} }
_data = _wire->read(); _data = _wire->read();
_data <<= 8; _data <<= 8;
@ -275,5 +275,5 @@ void BH1750FVI::command(uint8_t value)
} }
// --- END OF FILE --- // --- END OF FILE ---

View File

@ -2,10 +2,9 @@
// //
// FILE: BH1750FVI.h // FILE: BH1750FVI.h
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 0.3.0 // VERSION: 0.3.1
// PURPOSE: Arduino library for BH1750FVI (GY-30) lux sensor // PURPOSE: Arduino library for BH1750FVI (GY-30) lux sensor
// HISTORY: see changelog.md // URL: https://github.com/RobTillaart/BH1750FVI_RT
//
// breakout BH1750FVI / GY-30 // breakout BH1750FVI / GY-30
@ -28,7 +27,7 @@
#include "Arduino.h" #include "Arduino.h"
#define BH1750FVI_LIB_VERSION (F("0.3.0")) #define BH1750FVI_LIB_VERSION (F("0.3.1"))
#define BH1750FVI_DEFAULT_ADDRESS 0x23 #define BH1750FVI_DEFAULT_ADDRESS 0x23
@ -52,11 +51,11 @@ public:
BH1750FVI(const uint8_t address, TwoWire *wire = &Wire); BH1750FVI(const uint8_t address, TwoWire *wire = &Wire);
// returns true if isConnected() // returns true if isConnected()
bool begin(); // resets to constructor defaults. (use with care) bool begin(); // resets to constructor defaults. (use with care)
bool isConnected(); // returns true if address is on I2C bus bool isConnected(); // returns true if address is on I2C bus
float getRaw(); // no HIGH2 mode + no sensitivity factor. float getRaw(); // no HIGH2 mode + no sensitivity factor.
float getLux(); float getLux();
int getError(); int getError();
@ -87,11 +86,11 @@ public:
// read datasheet P11 about details of the correction or sensitivity factor // read datasheet P11 about details of the correction or sensitivity factor
// to be used for very high and very low brightness // to be used for very high and very low brightness
// or to correct for e.g. transparency // or to correct for e.g. transparency
void changeTiming(uint8_t time = BH1750FVI_REFERENCE_TIME); // 69 is default void changeTiming(uint8_t time = BH1750FVI_REFERENCE_TIME); // 69 is default
// returns changeTiming() parameter // returns changeTiming() parameter
uint8_t setCorrectionFactor(float factor = 1); // 0.45 .. 3.68 uint8_t setCorrectionFactor(float factor = 1); // 0.45 .. 3.68
// returns percentage set. // returns percentage set.
float getCorrectionFactor(); float getCorrectionFactor();
@ -130,13 +129,13 @@ private:
uint8_t _sensitivityFactor; uint8_t _sensitivityFactor;
uint8_t _mode; uint8_t _mode;
uint32_t _requestTime = 0; uint32_t _requestTime = 0;
float _angleFactor = 1; float _angleFactor = 1;
int _angle = 0; int _angle = 0;
float _tempFactor = 1; float _tempFactor = 1;
int _temp = 20; int _temp = 20;
float _waveLengthFactor = 1; float _waveLengthFactor = 1;
int _waveLength = 580; int _waveLength = 580;
TwoWire* _wire; TwoWire* _wire;
}; };

View File

@ -1,4 +1,4 @@
# Change Log AD520X # Change Log BH1750FVI
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
@ -6,6 +6,14 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/). and this project adheres to [Semantic Versioning](http://semver.org/).
##[0.3.1] - 2024-04-09
- update GitHub actions
- update URL in examples
- update keywords.txt
- fix CHANGELOG.md
- minor edits
##[0.3.0] - 2023-10-18 ##[0.3.0] - 2023-10-18
- simplify constructor / begin() - simplify constructor / begin()
- update examples - update examples

View File

@ -1,6 +1,6 @@
MIT License MIT License
Copyright (c) 2020-2023 Rob Tillaart Copyright (c) 2020-2024 Rob Tillaart
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View File

@ -37,6 +37,22 @@ Note that the typical integration time will differ if the correction factor is c
The **isReady()** an **getLux()** functions keep track of the adjustment needed. The **isReady()** an **getLux()** functions keep track of the adjustment needed.
#### Related
- https://github.com/RobTillaart/BH1750FVI_RT
- https://github.com/RobTillaart/Max44007
- https://github.com/RobTillaart/Max44009
- https://github.com/RobTillaart/TSL235R pulse based irradiance variant.
UV sensors
- https://github.com/RobTillaart/AnalogUVSensor
- https://github.com/RobTillaart/ML8511
IR sensor
- https://github.com/RobTillaart/TSL260R analog IR irradiance variant.
## Interface hardware ## Interface hardware
Library was tested with a breakout board. Library was tested with a breakout board.
@ -67,7 +83,7 @@ Note: the breakout board was 5 volt tolerant.
#include "BH1750FVI.h" #include "BH1750FVI.h"
``` ```
### Constructor #### Constructor
- **BH1750FVI(uint8_t address, uint8_t dataPin, uint8_t clockPin)** ESP constructor with I2C parameters. - **BH1750FVI(uint8_t address, uint8_t dataPin, uint8_t clockPin)** ESP constructor with I2C parameters.
- **BH1750FVI(uint8_t address, TwoWire \*wire = &Wire)** constructor for other platforms. - **BH1750FVI(uint8_t address, TwoWire \*wire = &Wire)** constructor for other platforms.
@ -75,13 +91,13 @@ Note: the breakout board was 5 volt tolerant.
- **bool isConnected()** returns true if address is on I2C bus. - **bool isConnected()** returns true if address is on I2C bus.
### Base #### Base
- **float getRaw()** reads the lux sensor. - **float getRaw()** reads the lux sensor.
- **float getLux()** reads the lux sensor and corrects for correctionFactor, mode, temperature and angle. - **float getLux()** reads the lux sensor and corrects for correctionFactor, mode, temperature and angle.
### Management #### Management
- **int getError()** get the latest error code, mainly for debugging. - **int getError()** get the latest error code, mainly for debugging.
- **void powerOn()** wakes up the sensor. - **void powerOn()** wakes up the sensor.
@ -89,7 +105,7 @@ Note: the breakout board was 5 volt tolerant.
- **void reset()** resets the data register to 0, effectively removing last measurement. - **void reset()** resets the data register to 0, effectively removing last measurement.
### Mode operators #### Mode operators
- **uint8_t getMode()** gets the mode set by one of the set functions. - **uint8_t getMode()** gets the mode set by one of the set functions.
See table above. See table above.
@ -101,7 +117,7 @@ See table above.
- **void setOnceLowRes()** single shot mode in LOW resolution. - **void setOnceLowRes()** single shot mode in LOW resolution.
### CorrectionFactor #### CorrectionFactor
Please read datasheet P11 about details of the correction factor. Please read datasheet P11 about details of the correction factor.
@ -116,7 +132,7 @@ Returns changeTiming() parameter.
Note this can differ as it is stores as an integer internally. Note this can differ as it is stores as an integer internally.
### Angle sensitivity #### Angle sensitivity
Note: experimental - use carefully Note: experimental - use carefully
@ -138,7 +154,7 @@ Returns the angle correction factor.
- **int getAngle()** returns set angle in degrees, 0 by default is perpendicular. - **int getAngle()** returns set angle in degrees, 0 by default is perpendicular.
### Temperature Compensation #### Temperature Compensation
The reference temperature of the sensor = 20°C. The reference temperature of the sensor = 20°C.
The effect of temperature is small, about 3% per 60°C ==> 1% per 20°C The effect of temperature is small, about 3% per 60°C ==> 1% per 20°C
@ -149,7 +165,7 @@ Returns the temperature correction factor.
- **int getTemperature()** returns temperature set, default = 20°C. - **int getTemperature()** returns temperature set, default = 20°C.
### Spectral Compensation ! EXPERIMENTAL ! #### Spectral Compensation ! EXPERIMENTAL !
Spectral compensation is experimental and not tested. It is a compensation based upon the Spectral compensation is experimental and not tested. It is a compensation based upon the
graph figure 1, page 3 of the datasheet. If one has light of a known wavelength one can graph figure 1, page 3 of the datasheet. If one has light of a known wavelength one can
@ -164,37 +180,36 @@ Returns the wavelength correction factor.
As the graph (figure 1) is not linear it is approximated by linear interpolation with the As the graph (figure 1) is not linear it is approximated by linear interpolation with the
following six points. following six points.
| WaveLength | Perc % | | WaveLength | Colour | Perc % |
|:-----------|:------:| |:-----------|:--------:|:--------:|
| 400 | 1 | | 400 | violet | 1 |
| 440 | 10 | | 440 | blue | 10 |
| 510 | 90 | | 510 | green | 90 |
| 545 | 80 | | 545 | green | 80 |
| 580 | 100 | | 580 | yellow | 100 |
| 700 | 07 | | 700 | red | 07 |
| 715 | 1 | | 715 | red | 1 |
Colour is indicative.
Values outside the range will be mapped upon 400 or 715. Values outside the range will be mapped upon 400 or 715.
Default wavelength will be 580 as that gives 100%. Default wavelength will be 580 as that gives 100%.
## Operation
See samples...
## Future ## Future
#### Must #### Must
#### Should #### Should
#### Could #### Could
- **Intelligent isReady()** - **Intelligent isReady()**
After a **getLux()** call one can clean the data register explicitly with After a **getLux()** call one can clean the data register explicitly with
**reset()**. Then a call to **isReady()** fetches data and as long as **reset()**. Then a call to **isReady()** fetches data and as long as
data equals zero the sensor is not ready. data equals zero the sensor is not ready (or in pitch dark?)
- **DVI interface** - **DVI interface**
To investigate, sort of external reset? To investigate, sort of external reset?
- move code to .cpp - move code to .cpp

View File

@ -1,9 +1,8 @@
// //
// FILE: BH1750FVI_angle_measurement.ino // FILE: BH1750FVI_angle_measurement.ino
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 0.1.1
// PURPOSE: demo of BH1750FVI lux scanner library // PURPOSE: demo of BH1750FVI lux scanner library
// DATE: 2020-08-31 // URL: https://github.com/RobTillaart/BH1750FVI_RT
// //
/* /*
@ -77,12 +76,12 @@ void loop()
{ {
float val = measure(1, false); float val = measure(1, false);
val = map(val, ref2, ref1, 0, ref1); // does not constrain... val = map(val, ref2, ref1, 0, ref1); // does not constrain...
// prevent NAN // prevent NAN
float f = val / ref1; // map to 0..1 float f = val / ref1; // map to 0..1
if (f > 1) f = 1; // constrain upper if (f > 1) f = 1; // constrain upper
if (f < -1) f = -1; // constrain lower if (f < -1) f = -1; // constrain lower
Serial.print(val, 1); Serial.print(val, 1);
Serial.print("\t"); Serial.print("\t");

View File

@ -2,7 +2,7 @@
// FILE: BH1750FVI_async.ino // FILE: BH1750FVI_async.ino
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// PURPOSE: demo of BH1750FVI lux scanner library // PURPOSE: demo of BH1750FVI lux scanner library
// DATE: 2020-08-20 // URL: https://github.com/RobTillaart/BH1750FVI_RT
#include "BH1750FVI.h" #include "BH1750FVI.h"
@ -50,12 +50,12 @@ void loop()
// note correction factor are steps of 1/69 internally, see datasheet // note correction factor are steps of 1/69 internally, see datasheet
correctionFactor += 0.05; correctionFactor += 0.05;
if (correctionFactor > 3.68) // 0.45 - 3.68 = 45 steps of 0.05 if (correctionFactor > 3.68) // 0.45 - 3.68 = 45 steps of 0.05
{ {
correctionFactor = 0.45; correctionFactor = 0.45;
Serial.println(); Serial.println();
} }
myLux.setCorrectionFactor(correctionFactor); // 0.45 .. 3.68 myLux.setCorrectionFactor(correctionFactor); // 0.45 .. 3.68
count++; count++;
} }

View File

@ -2,7 +2,7 @@
// FILE: BH1750FVI_cont_high_res.ino // FILE: BH1750FVI_cont_high_res.ino
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// PURPOSE: demo of BH1750FVI lux scanner library // PURPOSE: demo of BH1750FVI lux scanner library
// DATE: 2020-02-02 // URL: https://github.com/RobTillaart/BH1750FVI_RT
// //
// This is a minimal version, which can be optimized by // This is a minimal version, which can be optimized by
// using mylux.getRaw() instead of myLux.getLux(); line 38 // using mylux.getRaw() instead of myLux.getLux(); line 38

View File

@ -2,7 +2,7 @@
// FILE: BH1750FVI_cont_high_res_Wire1.ino // FILE: BH1750FVI_cont_high_res_Wire1.ino
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// PURPOSE: demo of BH1750FVI lux scanner library // PURPOSE: demo of BH1750FVI lux scanner library
// DATE: 2023-10-18 // URL: https://github.com/RobTillaart/BH1750FVI_RT
// //
// This sketch only works on platforms with a Wire1 // This sketch only works on platforms with a Wire1
// e.g. ESP32 and RPIpico // e.g. ESP32 and RPIpico

View File

@ -2,7 +2,7 @@
// FILE: BH1750FVI_cont_low_res.ino // FILE: BH1750FVI_cont_low_res.ino
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// PURPOSE: demo of BH1750FVI lux scanner library // PURPOSE: demo of BH1750FVI lux scanner library
// DATE: 2020-02-02 // URL: https://github.com/RobTillaart/BH1750FVI_RT
#include "BH1750FVI.h" #include "BH1750FVI.h"

View File

@ -2,7 +2,7 @@
// FILE: BH1750FVI_setAngle.ino // FILE: BH1750FVI_setAngle.ino
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// PURPOSE: demo of BH1750FVI lux scanner library // PURPOSE: demo of BH1750FVI lux scanner library
// DATE: 2020-08-31 // URL: https://github.com/RobTillaart/BH1750FVI_RT
#include "BH1750FVI.h" #include "BH1750FVI.h"

View File

@ -2,7 +2,7 @@
// FILE: setCorrectionFactor.ino // FILE: setCorrectionFactor.ino
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// PURPOSE: demo of BH1750FVI lux scanner library // PURPOSE: demo of BH1750FVI lux scanner library
// DATE: 2020-02-02 // URL: https://github.com/RobTillaart/BH1750FVI_RT
#include "BH1750FVI.h" #include "BH1750FVI.h"

View File

@ -2,7 +2,7 @@
// FILE: BH1750FVI_setTemperature.ino // FILE: BH1750FVI_setTemperature.ino
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// PURPOSE: demo of BH1750FVI lux scanner library // PURPOSE: demo of BH1750FVI lux scanner library
// DATE: 2020-09-04 // URL: https://github.com/RobTillaart/BH1750FVI_RT
#include "BH1750FVI.h" #include "BH1750FVI.h"

View File

@ -2,7 +2,7 @@
// FILE: BH1750FVI_setWaveLength.ino // FILE: BH1750FVI_setWaveLength.ino
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// PURPOSE: demo of BH1750FVI lux scanner library // PURPOSE: demo of BH1750FVI lux scanner library
// DATE: 2020-09-04 // URL: https://github.com/RobTillaart/BH1750FVI_RT
#include "BH1750FVI.h" #include "BH1750FVI.h"

View File

@ -2,7 +2,7 @@
// FILE: BH1750FVI_single_shot_3_res.ino // FILE: BH1750FVI_single_shot_3_res.ino
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// PURPOSE: demo of BH1750FVI lux scanner library // PURPOSE: demo of BH1750FVI lux scanner library
// DATE: 2020-08-20 // URL: https://github.com/RobTillaart/BH1750FVI_RT
#include "BH1750FVI.h" #include "BH1750FVI.h"

View File

@ -6,19 +6,23 @@ BH1750FVI KEYWORD1
# Methods and Functions (KEYWORD2) # Methods and Functions (KEYWORD2)
begin KEYWORD2
isConnected KEYWORD2
getRaw KEYWORD2 getRaw KEYWORD2
getLux KEYWORD2 getLux KEYWORD2
getError KEYWORD2 getError KEYWORD2
reset KEYWORD2
isConnected KEYWORD2
powerOn KEYWORD2 powerOn KEYWORD2
powerOff KEYWORD2 powerOff KEYWORD2
reset KEYWORD2 reset KEYWORD2
getMode KEYWORD2
setContHighRes KEYWORD2 setContHighRes KEYWORD2
setContHigh2Res KEYWORD2 setContHigh2Res KEYWORD2
setContLowRes KEYWORD2 setContLowRes KEYWORD2
setOnceHighRes KEYWORD2 setOnceHighRes KEYWORD2
setOnceHigh2Res KEYWORD2 setOnceHigh2Res KEYWORD2
setOnceLowRes KEYWORD2 setOnceLowRes KEYWORD2
@ -30,6 +34,7 @@ getCorrectionFactor KEYWORD2
setAngle KEYWORD2 setAngle KEYWORD2
getAngle KEYWORD2 getAngle KEYWORD2
setTemperature KEYWORD2 setTemperature KEYWORD2
getTemperature KEYWORD2 getTemperature KEYWORD2
setWaveLength KEYWORD2 setWaveLength KEYWORD2

View File

@ -15,7 +15,7 @@
"type": "git", "type": "git",
"url": "https://github.com/RobTillaart/BH1750FVI_RT.git" "url": "https://github.com/RobTillaart/BH1750FVI_RT.git"
}, },
"version": "0.3.0", "version": "0.3.1",
"license": "MIT", "license": "MIT",
"frameworks": "*", "frameworks": "*",
"platforms": "*", "platforms": "*",

View File

@ -1,5 +1,5 @@
name=BH1750FVI_RT name=BH1750FVI_RT
version=0.3.0 version=0.3.1
author=Rob Tillaart <rob.tillaart@gmail.com> author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com> maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for BH1750FVI (GY-30) lux sensor sentence=Arduino library for BH1750FVI (GY-30) lux sensor