mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.3.1 BH1750FVI_RT
This commit is contained in:
parent
b24851e77a
commit
d072dafec9
3
libraries/BH1750FVI_RT/.github/FUNDING.yml
vendored
3
libraries/BH1750FVI_RT/.github/FUNDING.yml
vendored
@ -1,4 +1,5 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: RobTillaart
|
||||
github: RobTillaart
|
||||
custom: "https://www.paypal.me/robtillaart"
|
||||
|
||||
|
@ -1,12 +1,12 @@
|
||||
|
||||
name: Arduino-lint
|
||||
|
||||
on: [push, pull_request]
|
||||
jobs:
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 5
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
- uses: arduino/arduino-lint-action@v1
|
||||
with:
|
||||
library-manager: update
|
||||
|
@ -1,4 +1,3 @@
|
||||
---
|
||||
name: Arduino CI
|
||||
|
||||
on: [push, pull_request]
|
||||
@ -6,9 +5,10 @@ on: [push, pull_request]
|
||||
jobs:
|
||||
runTest:
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 20
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
- uses: ruby/setup-ruby@v1
|
||||
with:
|
||||
ruby-version: 2.6
|
||||
|
@ -9,10 +9,11 @@ on:
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 5
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
- name: json-syntax-check
|
||||
uses: limitusus/json-syntax-check@v1
|
||||
uses: limitusus/json-syntax-check@v2
|
||||
with:
|
||||
pattern: "\\.json$"
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
//
|
||||
// FILE: BH1750FVI.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.3.0
|
||||
// VERSION: 0.3.1
|
||||
// PURPOSE: library for BH1750FVI lux sensor Arduino
|
||||
// URL: https://github.com/RobTillaart/BH1750FVI
|
||||
// URL: https://github.com/RobTillaart/BH1750FVI_RT
|
||||
|
||||
|
||||
#include "BH1750FVI.h"
|
||||
@ -65,7 +65,7 @@ bool BH1750FVI::isReady()
|
||||
|
||||
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)
|
||||
{
|
||||
lux *= 0.5f; // P11
|
||||
lux *= 0.5f; // P11
|
||||
}
|
||||
return lux;
|
||||
}
|
||||
@ -225,13 +225,13 @@ float BH1750FVI::setTemperature(int temp)
|
||||
float BH1750FVI::setAngle(int degrees)
|
||||
{
|
||||
_angle = constrain(degrees, -89, 89);
|
||||
// Lamberts Law.
|
||||
// Lambert's Law.
|
||||
_angleFactor = 1.0f / cos(_angle * (PI / 180.0f));
|
||||
return _angleFactor;
|
||||
}
|
||||
|
||||
|
||||
// interpolation tables uses more RAM (versus progmem)
|
||||
// interpolation tables uses more RAM (versus PROGMEM)
|
||||
float BH1750FVI::setWaveLength(int waveLength)
|
||||
{
|
||||
_waveLength = constrain(waveLength, 400, 715);
|
||||
@ -258,7 +258,7 @@ uint16_t BH1750FVI::readData()
|
||||
if (_wire->requestFrom(_address, (uint8_t) 2) != 2)
|
||||
{
|
||||
_error = BH1750FVI_ERROR_WIRE_REQUEST;
|
||||
return _data; // last value
|
||||
return _data; // last value
|
||||
}
|
||||
_data = _wire->read();
|
||||
_data <<= 8;
|
||||
@ -275,5 +275,5 @@ void BH1750FVI::command(uint8_t value)
|
||||
}
|
||||
|
||||
|
||||
// --- END OF FILE ---
|
||||
// --- END OF FILE ---
|
||||
|
||||
|
@ -2,10 +2,9 @@
|
||||
//
|
||||
// FILE: BH1750FVI.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.3.0
|
||||
// VERSION: 0.3.1
|
||||
// PURPOSE: Arduino library for BH1750FVI (GY-30) lux sensor
|
||||
// HISTORY: see changelog.md
|
||||
//
|
||||
// URL: https://github.com/RobTillaart/BH1750FVI_RT
|
||||
|
||||
|
||||
// breakout BH1750FVI / GY-30
|
||||
@ -28,7 +27,7 @@
|
||||
#include "Arduino.h"
|
||||
|
||||
|
||||
#define BH1750FVI_LIB_VERSION (F("0.3.0"))
|
||||
#define BH1750FVI_LIB_VERSION (F("0.3.1"))
|
||||
|
||||
|
||||
#define BH1750FVI_DEFAULT_ADDRESS 0x23
|
||||
@ -52,11 +51,11 @@ public:
|
||||
|
||||
BH1750FVI(const uint8_t address, TwoWire *wire = &Wire);
|
||||
// returns true if isConnected()
|
||||
bool begin(); // resets to constructor defaults. (use with care)
|
||||
bool isConnected(); // returns true if address is on I2C bus
|
||||
bool begin(); // resets to constructor defaults. (use with care)
|
||||
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();
|
||||
int getError();
|
||||
|
||||
@ -87,11 +86,11 @@ public:
|
||||
// read datasheet P11 about details of the correction or sensitivity factor
|
||||
// to be used for very high and very low brightness
|
||||
// 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
|
||||
uint8_t setCorrectionFactor(float factor = 1); // 0.45 .. 3.68
|
||||
uint8_t setCorrectionFactor(float factor = 1); // 0.45 .. 3.68
|
||||
// returns percentage set.
|
||||
float getCorrectionFactor();
|
||||
|
||||
@ -130,13 +129,13 @@ private:
|
||||
uint8_t _sensitivityFactor;
|
||||
uint8_t _mode;
|
||||
|
||||
uint32_t _requestTime = 0;
|
||||
float _angleFactor = 1;
|
||||
int _angle = 0;
|
||||
float _tempFactor = 1;
|
||||
int _temp = 20;
|
||||
float _waveLengthFactor = 1;
|
||||
int _waveLength = 580;
|
||||
uint32_t _requestTime = 0;
|
||||
float _angleFactor = 1;
|
||||
int _angle = 0;
|
||||
float _tempFactor = 1;
|
||||
int _temp = 20;
|
||||
float _waveLengthFactor = 1;
|
||||
int _waveLength = 580;
|
||||
|
||||
TwoWire* _wire;
|
||||
};
|
||||
|
@ -1,4 +1,4 @@
|
||||
# Change Log AD520X
|
||||
# Change Log BH1750FVI
|
||||
|
||||
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/).
|
||||
|
||||
|
||||
##[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
|
||||
- simplify constructor / begin()
|
||||
- update examples
|
||||
|
@ -1,6 +1,6 @@
|
||||
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
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -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.
|
||||
|
||||
|
||||
#### 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
|
||||
|
||||
Library was tested with a breakout board.
|
||||
@ -67,7 +83,7 @@ Note: the breakout board was 5 volt tolerant.
|
||||
#include "BH1750FVI.h"
|
||||
```
|
||||
|
||||
### Constructor
|
||||
#### Constructor
|
||||
|
||||
- **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.
|
||||
@ -75,13 +91,13 @@ Note: the breakout board was 5 volt tolerant.
|
||||
- **bool isConnected()** returns true if address is on I2C bus.
|
||||
|
||||
|
||||
### Base
|
||||
#### Base
|
||||
|
||||
- **float getRaw()** reads the lux sensor.
|
||||
- **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.
|
||||
- **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.
|
||||
|
||||
|
||||
### Mode operators
|
||||
#### Mode operators
|
||||
|
||||
- **uint8_t getMode()** gets the mode set by one of the set functions.
|
||||
See table above.
|
||||
@ -101,7 +117,7 @@ See table above.
|
||||
- **void setOnceLowRes()** single shot mode in LOW resolution.
|
||||
|
||||
|
||||
### CorrectionFactor
|
||||
#### CorrectionFactor
|
||||
|
||||
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.
|
||||
|
||||
|
||||
### Angle sensitivity
|
||||
#### Angle sensitivity
|
||||
|
||||
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.
|
||||
|
||||
|
||||
### Temperature Compensation
|
||||
#### Temperature Compensation
|
||||
|
||||
The reference temperature of the sensor = 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.
|
||||
|
||||
|
||||
### Spectral Compensation ! EXPERIMENTAL !
|
||||
#### Spectral Compensation ! EXPERIMENTAL !
|
||||
|
||||
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
|
||||
@ -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
|
||||
following six points.
|
||||
|
||||
| WaveLength | Perc % |
|
||||
|:-----------|:------:|
|
||||
| 400 | 1 |
|
||||
| 440 | 10 |
|
||||
| 510 | 90 |
|
||||
| 545 | 80 |
|
||||
| 580 | 100 |
|
||||
| 700 | 07 |
|
||||
| 715 | 1 |
|
||||
| WaveLength | Colour | Perc % |
|
||||
|:-----------|:--------:|:--------:|
|
||||
| 400 | violet | 1 |
|
||||
| 440 | blue | 10 |
|
||||
| 510 | green | 90 |
|
||||
| 545 | green | 80 |
|
||||
| 580 | yellow | 100 |
|
||||
| 700 | red | 07 |
|
||||
| 715 | red | 1 |
|
||||
|
||||
Colour is indicative.
|
||||
|
||||
Values outside the range will be mapped upon 400 or 715.
|
||||
Default wavelength will be 580 as that gives 100%.
|
||||
|
||||
|
||||
## Operation
|
||||
|
||||
See samples...
|
||||
|
||||
|
||||
## Future
|
||||
|
||||
#### Must
|
||||
|
||||
|
||||
#### Should
|
||||
|
||||
|
||||
#### Could
|
||||
|
||||
- **Intelligent isReady()**
|
||||
After a **getLux()** call one can clean the data register explicitly with
|
||||
**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**
|
||||
To investigate, sort of external reset?
|
||||
- move code to .cpp
|
||||
|
@ -1,9 +1,8 @@
|
||||
//
|
||||
// FILE: BH1750FVI_angle_measurement.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.1
|
||||
// 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);
|
||||
|
||||
val = map(val, ref2, ref1, 0, ref1); // does not constrain...
|
||||
val = map(val, ref2, ref1, 0, ref1); // does not constrain...
|
||||
|
||||
// prevent NAN
|
||||
float f = val / ref1; // map to 0..1
|
||||
if (f > 1) f = 1; // constrain upper
|
||||
if (f < -1) f = -1; // constrain lower
|
||||
// prevent NAN
|
||||
float f = val / ref1; // map to 0..1
|
||||
if (f > 1) f = 1; // constrain upper
|
||||
if (f < -1) f = -1; // constrain lower
|
||||
|
||||
Serial.print(val, 1);
|
||||
Serial.print("\t");
|
||||
|
@ -2,7 +2,7 @@
|
||||
// FILE: BH1750FVI_async.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: demo of BH1750FVI lux scanner library
|
||||
// DATE: 2020-08-20
|
||||
// URL: https://github.com/RobTillaart/BH1750FVI_RT
|
||||
|
||||
|
||||
#include "BH1750FVI.h"
|
||||
@ -50,12 +50,12 @@ void loop()
|
||||
|
||||
// note correction factor are steps of 1/69 internally, see datasheet
|
||||
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;
|
||||
Serial.println();
|
||||
}
|
||||
myLux.setCorrectionFactor(correctionFactor); // 0.45 .. 3.68
|
||||
myLux.setCorrectionFactor(correctionFactor); // 0.45 .. 3.68
|
||||
|
||||
count++;
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
// FILE: BH1750FVI_cont_high_res.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// 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
|
||||
// using mylux.getRaw() instead of myLux.getLux(); line 38
|
||||
|
@ -2,7 +2,7 @@
|
||||
// FILE: BH1750FVI_cont_high_res_Wire1.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// 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
|
||||
// e.g. ESP32 and RPIpico
|
||||
|
@ -2,7 +2,7 @@
|
||||
// FILE: BH1750FVI_cont_low_res.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: demo of BH1750FVI lux scanner library
|
||||
// DATE: 2020-02-02
|
||||
// URL: https://github.com/RobTillaart/BH1750FVI_RT
|
||||
|
||||
|
||||
#include "BH1750FVI.h"
|
||||
|
@ -2,7 +2,7 @@
|
||||
// FILE: BH1750FVI_setAngle.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: demo of BH1750FVI lux scanner library
|
||||
// DATE: 2020-08-31
|
||||
// URL: https://github.com/RobTillaart/BH1750FVI_RT
|
||||
|
||||
|
||||
#include "BH1750FVI.h"
|
||||
|
@ -2,7 +2,7 @@
|
||||
// FILE: setCorrectionFactor.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: demo of BH1750FVI lux scanner library
|
||||
// DATE: 2020-02-02
|
||||
// URL: https://github.com/RobTillaart/BH1750FVI_RT
|
||||
|
||||
|
||||
#include "BH1750FVI.h"
|
||||
|
@ -2,7 +2,7 @@
|
||||
// FILE: BH1750FVI_setTemperature.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: demo of BH1750FVI lux scanner library
|
||||
// DATE: 2020-09-04
|
||||
// URL: https://github.com/RobTillaart/BH1750FVI_RT
|
||||
|
||||
|
||||
#include "BH1750FVI.h"
|
||||
|
@ -2,7 +2,7 @@
|
||||
// FILE: BH1750FVI_setWaveLength.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: demo of BH1750FVI lux scanner library
|
||||
// DATE: 2020-09-04
|
||||
// URL: https://github.com/RobTillaart/BH1750FVI_RT
|
||||
|
||||
|
||||
#include "BH1750FVI.h"
|
||||
|
@ -2,7 +2,7 @@
|
||||
// FILE: BH1750FVI_single_shot_3_res.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: demo of BH1750FVI lux scanner library
|
||||
// DATE: 2020-08-20
|
||||
// URL: https://github.com/RobTillaart/BH1750FVI_RT
|
||||
|
||||
|
||||
#include "BH1750FVI.h"
|
||||
|
@ -6,19 +6,23 @@ BH1750FVI KEYWORD1
|
||||
|
||||
# Methods and Functions (KEYWORD2)
|
||||
|
||||
begin KEYWORD2
|
||||
isConnected KEYWORD2
|
||||
|
||||
getRaw KEYWORD2
|
||||
getLux KEYWORD2
|
||||
getError KEYWORD2
|
||||
reset KEYWORD2
|
||||
isConnected KEYWORD2
|
||||
|
||||
powerOn KEYWORD2
|
||||
powerOff KEYWORD2
|
||||
reset KEYWORD2
|
||||
|
||||
getMode KEYWORD2
|
||||
|
||||
setContHighRes KEYWORD2
|
||||
setContHigh2Res KEYWORD2
|
||||
setContLowRes KEYWORD2
|
||||
|
||||
setOnceHighRes KEYWORD2
|
||||
setOnceHigh2Res KEYWORD2
|
||||
setOnceLowRes KEYWORD2
|
||||
@ -30,6 +34,7 @@ getCorrectionFactor KEYWORD2
|
||||
|
||||
setAngle KEYWORD2
|
||||
getAngle KEYWORD2
|
||||
|
||||
setTemperature KEYWORD2
|
||||
getTemperature KEYWORD2
|
||||
setWaveLength KEYWORD2
|
||||
|
@ -15,7 +15,7 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/BH1750FVI_RT.git"
|
||||
},
|
||||
"version": "0.3.0",
|
||||
"version": "0.3.1",
|
||||
"license": "MIT",
|
||||
"frameworks": "*",
|
||||
"platforms": "*",
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=BH1750FVI_RT
|
||||
version=0.3.0
|
||||
version=0.3.1
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Arduino library for BH1750FVI (GY-30) lux sensor
|
||||
|
Loading…
Reference in New Issue
Block a user