mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.1.3 TSL235R
This commit is contained in:
parent
753172446a
commit
11f2399cb9
@ -1,3 +1,18 @@
|
||||
platforms:
|
||||
rpipico:
|
||||
board: rp2040:rp2040:rpipico
|
||||
package: rp2040:rp2040
|
||||
gcc:
|
||||
features:
|
||||
defines:
|
||||
- ARDUINO_ARCH_RP2040
|
||||
warnings:
|
||||
flags:
|
||||
|
||||
packages:
|
||||
rp2040:rp2040:
|
||||
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
|
||||
|
||||
compile:
|
||||
# Choosing to run compilation tests on 2 different Arduino platforms
|
||||
platforms:
|
||||
@ -7,5 +22,6 @@ compile:
|
||||
# - leonardo
|
||||
- m4
|
||||
- esp32
|
||||
# - esp8266
|
||||
- esp8266
|
||||
# - mega2560
|
||||
- rpipico
|
||||
|
25
libraries/TSL235R/CHANGELOG.md
Normal file
25
libraries/TSL235R/CHANGELOG.md
Normal file
@ -0,0 +1,25 @@
|
||||
# Change Log TSL235R
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
|
||||
## [0.1.3] - 2022-11-26
|
||||
- Add RP2040 support to build-CI.
|
||||
- Add CHANGELOG.md
|
||||
- update readme.md
|
||||
- renamed **calcWLF()** to **calculateWaveLengthFactor()** more descriptive.
|
||||
|
||||
## [0.1.2] - 2021-12-29
|
||||
- update library.json
|
||||
- update readme.md
|
||||
- update license
|
||||
- minor edits
|
||||
|
||||
## [0.1.1] - 2020-06-03
|
||||
- add irradiance_HS()
|
||||
|
||||
## [0.1.0] - 2020-05-29
|
||||
- initial version
|
@ -13,50 +13,61 @@ Arduino library for the TSL235R light to frequency convertor.
|
||||
|
||||
## Description
|
||||
|
||||
This library does not measure the frequency but has some functions to compensate e.g.
|
||||
for wavelength and voltage used.
|
||||
This library does not measure the frequency.
|
||||
That should be done with an interrupt function (user code).
|
||||
The library provides functions to calculate the radiation and
|
||||
has functions to compensate e.g. for wavelength and voltage used.
|
||||
|
||||
The library is not tested extensively yet.
|
||||
|
||||
The sensor operating voltage is between 2.7 and 5.5 max.
|
||||
This can be set in the constructor, or runtime adjusted.
|
||||
|
||||
For measurements below 1uW/cm2 one bests measures for multiple seconds
|
||||
For measurements below 1 uW/cm2 one should measure for multiple seconds.
|
||||
Above 1 uW/cm2 1 second or shorter is OK.
|
||||
|
||||
Note that for longer and shorter measurements than 1 second one must convert the
|
||||
value to Hz, which is the number of pulses in 1 second.
|
||||
Note that for longer and shorter measurements than 1 second one must
|
||||
convert the value to Hz, which is the number of pulses in 1 second.
|
||||
The library provides functions **irradiance()** to do that for you.
|
||||
|
||||
|
||||
## Connection
|
||||
|
||||
Always check the datasheet.
|
||||
|
||||
```
|
||||
// PIN 1 - GND
|
||||
// PIN 2 - VDD 2.7 V .. 5.5 V
|
||||
// PIN 3 - SIGNAL 1 Hz .. 800 KHz
|
||||
// PIN 1 - GND
|
||||
// PIN 2 - VDD 2.7 V .. 5.5 V
|
||||
// PIN 3 - SIGNAL 1 Hz .. 800 KHz
|
||||
```
|
||||
|
||||
|
||||
## Interface
|
||||
|
||||
- **TSL235R(float voltage = 5.0)** constructor, optionally one can give the operational voltage
|
||||
to add a small correction (< 1.5%)
|
||||
to add a small correction (< 1.5%).
|
||||
Default voltage is 5.0 Volts.
|
||||
- **float irradiance(uint32_t Hz)** returns the irradiance in uW/cm2.
|
||||
Note that Hz implies the measured pulses for 1 second.
|
||||
- **float irradiance(uint32_t pulses, uint32_t milliseconds)** returns the irradiance in uW/cm2
|
||||
- **float irradiance(uint32_t pulses, uint32_t milliseconds)** returns the irradiance in uW/cm2.
|
||||
This formula is used for other duration than 1 second.
|
||||
To get irradiance in W/m2 one must divide by 100.
|
||||
- **float irradiance_HS(uint32_t pulses, uint32_t microseconds)** returns the irradiance in uW/cm2
|
||||
This formula is used when the time is measured in microseconds. This is the most accurate measurement.
|
||||
- **float irradiance_HS(uint32_t pulses, uint32_t microseconds)** returns the irradiance in uW/cm2.
|
||||
This formula is used when the time is measured in microseconds.
|
||||
This is the most accurate measurement.
|
||||
- **float getFactor()** returns the inner conversion factor from Hz to Watt/cm2.
|
||||
- **void setWavelength(uint16_t wavelength = 635)** sets the wavelength so the formulas can use a
|
||||
correction factor. At the default wavelength of 635 nm the wavelength correction factor == 1.0
|
||||
- **uint16_t getWavelength()** returns the set wavelength. Convenience function.
|
||||
correction factor.
|
||||
At the default wavelength of 635 nm the wavelength correction factor == 1.0.
|
||||
- **uint16_t getWavelength()** returns the set wavelength.
|
||||
- **float getWaveLengthFactor()** returns the wavelength correction factor.
|
||||
As the sensor is most sensitive around 750 nm this value helps to normalize the signal.
|
||||
This works only for (almost) monochromatic light.
|
||||
- **void setVoltage(float voltage)** sets the voltage so the formulas can use a correction factor.
|
||||
This voltage correction factor is rather small < 1.5%
|
||||
- **float getVoltage()** returns the set voltage. Convenience function.
|
||||
This voltage correction factor is rather small < 1.5%.
|
||||
Note: this voltage can be changed runtime.
|
||||
- **float getVoltage()** returns the set voltage, by constructor or by **setVoltage()**.
|
||||
Default voltage is 5.0 Volts.
|
||||
|
||||
|
||||
## Operations
|
||||
@ -66,9 +77,19 @@ See examples for typical usage.
|
||||
|
||||
## Future
|
||||
|
||||
#### must
|
||||
- improve documentation
|
||||
- test test test
|
||||
- investigate hardware solutions for e.g. divide by 100 or so
|
||||
|
||||
#### should
|
||||
- default voltage should be a #define so people who use 3.3V processor
|
||||
can change the library with minimal effort.
|
||||
- irradiance(pulses, millis) can be given a default of 1000 millis.
|
||||
makes irradiance(Hz) obsolete.
|
||||
- move code from .h to .cpp
|
||||
|
||||
#### could
|
||||
- investigate hardware solutions for e.g. divide by 100 or 1000 or so.
|
||||
- investigate correction factor for white light and mixed light sources.
|
||||
- investigate calibration factor for timing of processor used.
|
||||
-
|
||||
|
||||
|
@ -1,13 +1,8 @@
|
||||
//
|
||||
// FILE: TSL235R.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.2
|
||||
// VERSION: 0.1.3
|
||||
// PURPOSE: library for the TSL235R light to frequency convertor
|
||||
//
|
||||
// HISTORY:
|
||||
// 0.1.0 2020-05-29 initial version
|
||||
// 0.1.1 2020-06-03 add irradiance_HS()
|
||||
// 0.1.2 2021-12-29 update build-CI, readme, library.json, license, minor edits
|
||||
|
||||
|
||||
#include "TSL235R.h"
|
||||
@ -53,24 +48,24 @@ void TSL235R::setVoltage(float voltage)
|
||||
|
||||
void TSL235R::calculateFactor()
|
||||
{
|
||||
// figure 1 datasheet
|
||||
// 1 KHz crosses the line at 35/230 between 1 and 10.
|
||||
// so the correction factor is 10^0.15217 = 1.419659 = 1.42 (as all math has 3 decimals)
|
||||
// as the graph is in kHz we need to correct a factor 1000
|
||||
// as the irradiance function gets Hz
|
||||
// figure 1 datasheet
|
||||
// 1 KHz crosses the line at 35/230 between 1 and 10.
|
||||
// so the correction factor is 10^0.15217 = 1.419659 = 1.42 (as all math has 3 decimals)
|
||||
// as the graph is in kHz we need to correct a factor 1000
|
||||
// as the irradiance function gets Hz
|
||||
const float cf = 0.00142;
|
||||
_waveLengthFactor = calcWLF(_waveLength);
|
||||
_waveLengthFactor = calculateWaveLengthFactor(_waveLength);
|
||||
|
||||
_voltageFactor = 0.988 + (_voltage - 2.7) * (0.015 / 2.8);
|
||||
_factor = cf * _waveLengthFactor * _voltageFactor;
|
||||
}
|
||||
|
||||
|
||||
float TSL235R::calcWLF(uint16_t _waveLength)
|
||||
float TSL235R::calculateWaveLengthFactor(uint16_t _waveLength)
|
||||
{
|
||||
// figure 2 datasheet
|
||||
// 635 nm is reference 1.000
|
||||
// remaining is linear interpolated between points in the graph
|
||||
// figure 2 datasheet
|
||||
// 635 nm is reference 1.000
|
||||
// remaining is linear interpolated between points in the graph
|
||||
float in[] = { 300, 350, 400, 500, 600, 635, 700, 750, 800, 850, 900, 1000, 1100};
|
||||
float out[] = { 0.1, 0.35, 0.5, 0.75, 0.93, 1.00, 1.15, 1.20, 1.15, 1.10, 0.95, 0.40, 0.10};
|
||||
return 1.0 / multiMap(_waveLength, in, out, 13);
|
||||
@ -79,23 +74,23 @@ float TSL235R::calcWLF(uint16_t _waveLength)
|
||||
|
||||
float TSL235R::multiMap(float value, float * _in, float * _out, uint8_t size)
|
||||
{
|
||||
// take care the value is within range
|
||||
// value = constrain(value, _in[0], _in[size-1]);
|
||||
// take care the value is within range
|
||||
// value = constrain(value, _in[0], _in[size-1]);
|
||||
if (value <= _in[0]) return _out[0];
|
||||
if (value >= _in[size-1]) return _out[size-1];
|
||||
|
||||
// search right interval
|
||||
// search right interval
|
||||
uint8_t pos = 1; // _in[0] already tested
|
||||
while(value > _in[pos]) pos++;
|
||||
|
||||
// this will handle all exact "points" in the _in array
|
||||
// this will handle all exact "points" in the _in array
|
||||
if (value == _in[pos]) return _out[pos];
|
||||
|
||||
// interpolate in the right segment for the rest
|
||||
// interpolate in the right segment for the rest
|
||||
uint8_t pos1 = pos - 1;
|
||||
return (value - _in[pos1]) * (_out[pos] - _out[pos1]) / (_in[pos] - _in[pos1]) + _out[pos1];
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -2,11 +2,11 @@
|
||||
//
|
||||
// FILE: TSL235R.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.2
|
||||
// VERSION: 0.1.3
|
||||
// PURPOSE: library for the TSL235R light to frequency convertor
|
||||
|
||||
|
||||
#define TSL235R_LIB_VERSION (F("0.1.2"))
|
||||
#define TSL235R_LIB_VERSION (F("0.1.3"))
|
||||
|
||||
#include "Arduino.h"
|
||||
|
||||
@ -17,8 +17,8 @@ public:
|
||||
|
||||
TSL235R(float voltage = 5.0);
|
||||
|
||||
float irradiance(uint32_t Hz);
|
||||
float irradiance(uint32_t pulses, uint32_t milliseconds); // obsolete?
|
||||
float irradiance(uint32_t Hz); // Hz == pulses in one second.
|
||||
float irradiance(uint32_t pulses, uint32_t milliseconds); // obsolete?
|
||||
float irradiance_HS(uint32_t pulses, uint32_t microseconds);
|
||||
float getFactor() { return _factor; };
|
||||
|
||||
@ -39,10 +39,10 @@ private:
|
||||
float _factor = 1.2;
|
||||
|
||||
void calculateFactor();
|
||||
float calcWLF(uint16_t _waveLength);
|
||||
float calculateWaveLengthFactor(uint16_t _waveLength);
|
||||
float multiMap(float value, float * _in, float * _out, uint8_t size);
|
||||
};
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/TSL235R.git"
|
||||
},
|
||||
"version": "0.1.2",
|
||||
"version": "0.1.3",
|
||||
"license": "MIT",
|
||||
"frameworks": "*",
|
||||
"platforms": "*",
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=TSL235R
|
||||
version=0.1.2
|
||||
version=0.1.3
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Library for the TSL235R light to frequency convertor.
|
||||
|
Loading…
Reference in New Issue
Block a user