mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.1.4 TSL235R
This commit is contained in:
parent
76a45dc61a
commit
9e2ad31141
@ -6,7 +6,7 @@ jobs:
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
- uses: arduino/arduino-lint-action@v1
|
||||
with:
|
||||
library-manager: update
|
||||
|
@ -8,7 +8,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
- uses: ruby/setup-ruby@v1
|
||||
with:
|
||||
ruby-version: 2.6
|
||||
|
@ -10,7 +10,7 @@ jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
- name: json-syntax-check
|
||||
uses: limitusus/json-syntax-check@v1
|
||||
with:
|
||||
|
@ -6,6 +6,16 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
|
||||
## [0.1.4] - 2023-02-18
|
||||
- updated cf value in **calculateFactor()**
|
||||
- add **#define TSL235_DEFAULT_VOLTAGE** to allow set voltage from command line.
|
||||
- update readme.md
|
||||
- move code to .cpp
|
||||
- update GitHub actions
|
||||
- update license 2023
|
||||
- minor edits
|
||||
|
||||
|
||||
## [0.1.3] - 2022-11-26
|
||||
- Add RP2040 support to build-CI.
|
||||
- Add CHANGELOG.md
|
||||
|
@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2020-2022 Rob Tillaart
|
||||
Copyright (c) 2020-2023 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
|
||||
|
@ -28,7 +28,15 @@ 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.
|
||||
The library provides functions **irradiance()** to do that for you.
|
||||
The library provides two **irradiance()** functions to do that for you.
|
||||
|
||||
|
||||
#### Related
|
||||
|
||||
- https://github.com/RobTillaart/TSL235R pulse based irradiance variant.
|
||||
- https://github.com/RobTillaart/TSL260R analog IR irradiance variant.
|
||||
- https://github.com/RobTillaart/AnalogUVSensor
|
||||
- https://github.com/RobTillaart/ML8511 UV sensor
|
||||
|
||||
|
||||
## Connection
|
||||
@ -44,9 +52,19 @@ Always check the datasheet.
|
||||
|
||||
## Interface
|
||||
|
||||
- **TSL235R(float voltage = 5.0)** constructor, optionally one can give the operational voltage
|
||||
```cpp
|
||||
#include "TSL235R.h"
|
||||
```
|
||||
|
||||
#### Constructor
|
||||
|
||||
- **TSL235R(float voltage = TSL235_DEFAULT_VOLTAGE)** constructor, optionally one can give the operational voltage
|
||||
to add a small correction (< 1.5%).
|
||||
Default voltage is 5.0 Volts.
|
||||
Default voltage is 5.0 Volts, this define can be overruled from command line.
|
||||
|
||||
|
||||
#### Irradiance
|
||||
|
||||
- **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.
|
||||
@ -55,6 +73,9 @@ 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.
|
||||
|
||||
#### Configuration
|
||||
|
||||
- **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.
|
||||
@ -63,7 +84,7 @@ At the default wavelength of 635 nm the wavelength correction factor == 1.0.
|
||||
- **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.
|
||||
- **void setVoltage(float voltage = TSL235_DEFAULT_VOLTAGE)** sets the voltage so the formulas can use a correction factor.
|
||||
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()**.
|
||||
@ -77,19 +98,22 @@ See examples for typical usage.
|
||||
|
||||
## Future
|
||||
|
||||
#### must
|
||||
#### Must
|
||||
|
||||
- improve documentation
|
||||
- test test test
|
||||
|
||||
#### 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
|
||||
#### Should
|
||||
|
||||
#### Could
|
||||
|
||||
#### 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.
|
||||
|
||||
#### Wont
|
||||
|
||||
- irradiance(pulses, millis) can be given a default of 1000 millis.
|
||||
- makes irradiance(Hz) obsolete.
|
||||
- performance is less!
|
||||
|
||||
|
@ -1,8 +1,10 @@
|
||||
//
|
||||
// FILE: TSL235R.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.3
|
||||
// VERSION: 0.1.4
|
||||
// DATE: 2020-05-29
|
||||
// PURPOSE: library for the TSL235R light to frequency convertor
|
||||
// URL: https://github.com/RobTillaart/TSL235R
|
||||
|
||||
|
||||
#include "TSL235R.h"
|
||||
@ -10,7 +12,10 @@
|
||||
|
||||
TSL235R::TSL235R(float voltage)
|
||||
{
|
||||
_voltage = voltage;
|
||||
_waveLength = 635;
|
||||
_waveLengthFactor = 1.0;
|
||||
_voltageFactor = 1.0;
|
||||
_voltage = voltage;
|
||||
calculateFactor();
|
||||
}
|
||||
|
||||
@ -26,12 +31,19 @@ float TSL235R::irradiance(uint32_t pulses, uint32_t milliseconds)
|
||||
return (pulses * 1000.0 * _factor) / milliseconds;
|
||||
}
|
||||
|
||||
|
||||
float TSL235R::irradiance_HS(uint32_t pulses, uint32_t microseconds)
|
||||
{
|
||||
return (pulses * 1000000.0 * _factor) / microseconds;
|
||||
}
|
||||
|
||||
|
||||
float TSL235R::getFactor()
|
||||
{
|
||||
return _factor;
|
||||
}
|
||||
|
||||
|
||||
void TSL235R::setWavelength(uint16_t wavelength)
|
||||
{
|
||||
_waveLength = wavelength;
|
||||
@ -39,6 +51,18 @@ void TSL235R::setWavelength(uint16_t wavelength)
|
||||
}
|
||||
|
||||
|
||||
uint16_t TSL235R::getWavelength()
|
||||
{
|
||||
return _waveLength;
|
||||
}
|
||||
|
||||
|
||||
float TSL235R::getWaveLengthFactor()
|
||||
{
|
||||
return _waveLengthFactor;
|
||||
}
|
||||
|
||||
|
||||
void TSL235R::setVoltage(float voltage)
|
||||
{
|
||||
_voltage = voltage;
|
||||
@ -46,14 +70,26 @@ void TSL235R::setVoltage(float voltage)
|
||||
}
|
||||
|
||||
|
||||
float TSL235R::getVoltage()
|
||||
{
|
||||
return _voltage;
|
||||
}
|
||||
|
||||
|
||||
float TSL235R::getVoltageFactor()
|
||||
{
|
||||
return _voltageFactor;
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
// so the correction factor is 10^0.15217 = 1.419659
|
||||
// as the graph is in kHz we need to correct a factor 1000
|
||||
// as the irradiance function gets Hz
|
||||
const float cf = 0.00142;
|
||||
const float cf = 0.001419659;
|
||||
_waveLengthFactor = calculateWaveLengthFactor(_waveLength);
|
||||
|
||||
_voltageFactor = 0.988 + (_voltage - 2.7) * (0.015 / 2.8);
|
||||
@ -72,6 +108,7 @@ float TSL235R::calculateWaveLengthFactor(uint16_t _waveLength)
|
||||
}
|
||||
|
||||
|
||||
// from https://github.com/RobTillaart/MultiMap
|
||||
float TSL235R::multiMap(float value, float * _in, float * _out, uint8_t size)
|
||||
{
|
||||
// take care the value is within range
|
||||
@ -80,7 +117,7 @@ float TSL235R::multiMap(float value, float * _in, float * _out, uint8_t size)
|
||||
if (value >= _in[size-1]) return _out[size-1];
|
||||
|
||||
// search right interval
|
||||
uint8_t pos = 1; // _in[0] already tested
|
||||
uint8_t pos = 1; // _in[0] already tested
|
||||
while(value > _in[pos]) pos++;
|
||||
|
||||
// this will handle all exact "points" in the _in array
|
||||
|
@ -2,41 +2,48 @@
|
||||
//
|
||||
// FILE: TSL235R.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.3
|
||||
// VERSION: 0.1.4
|
||||
// DATE: 2020-05-29
|
||||
// PURPOSE: library for the TSL235R light to frequency convertor
|
||||
// URL: https://github.com/RobTillaart/TSL235R
|
||||
|
||||
|
||||
#define TSL235R_LIB_VERSION (F("0.1.3"))
|
||||
#define TSL235R_LIB_VERSION (F("0.1.4"))
|
||||
|
||||
#include "Arduino.h"
|
||||
|
||||
#if not defined(TSL235_DEFAULT_VOLTAGE)
|
||||
#define TSL235_DEFAULT_VOLTAGE 5.0
|
||||
#endif
|
||||
|
||||
class TSL235R
|
||||
{
|
||||
public:
|
||||
|
||||
TSL235R(float voltage = 5.0);
|
||||
TSL235R(float voltage = TSL235_DEFAULT_VOLTAGE);
|
||||
|
||||
float irradiance(uint32_t Hz); // Hz == pulses in one second.
|
||||
float irradiance(uint32_t pulses, uint32_t milliseconds); // obsolete?
|
||||
// Hz == pulses in one second.
|
||||
// could be calculated from shorter/longer measurement.
|
||||
float irradiance(uint32_t Hz);
|
||||
float irradiance(uint32_t pulses, uint32_t milliseconds);
|
||||
float irradiance_HS(uint32_t pulses, uint32_t microseconds);
|
||||
float getFactor() { return _factor; };
|
||||
float getFactor();
|
||||
|
||||
void setWavelength(uint16_t wavelength = 635);
|
||||
uint16_t getWavelength() { return _waveLength; }
|
||||
float getWaveLengthFactor() { return _waveLengthFactor; }
|
||||
uint16_t getWavelength();
|
||||
float getWaveLengthFactor();
|
||||
|
||||
void setVoltage(float voltage = 5.0);
|
||||
float getVoltage() { return _voltage; };
|
||||
float getVoltageFactor() { return _voltageFactor; };
|
||||
void setVoltage(float voltage = TSL235_DEFAULT_VOLTAGE);
|
||||
float getVoltage();
|
||||
float getVoltageFactor();
|
||||
|
||||
|
||||
private:
|
||||
uint16_t _waveLength = 635;
|
||||
float _waveLengthFactor = 1.0;
|
||||
float _voltage = 5.0;
|
||||
float _voltageFactor = 1.0;
|
||||
float _factor = 1.2;
|
||||
float _voltage;
|
||||
float _factor;
|
||||
|
||||
void calculateFactor();
|
||||
float calculateWaveLengthFactor(uint16_t _waveLength);
|
||||
|
@ -15,7 +15,7 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/TSL235R.git"
|
||||
},
|
||||
"version": "0.1.3",
|
||||
"version": "0.1.4",
|
||||
"license": "MIT",
|
||||
"frameworks": "*",
|
||||
"platforms": "*",
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=TSL235R
|
||||
version=0.1.3
|
||||
version=0.1.4
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Library for the TSL235R light to frequency convertor.
|
||||
|
@ -48,14 +48,21 @@ unittest_teardown()
|
||||
}
|
||||
|
||||
|
||||
unittest(test_constants)
|
||||
{
|
||||
assertEqualFloat(5.0, TSL235_DEFAULT_VOLTAGE, 0.001);
|
||||
}
|
||||
|
||||
|
||||
unittest(test_constructor)
|
||||
{
|
||||
TSL235R mysensor;
|
||||
|
||||
assertEqual(635, mysensor.getWavelength() );
|
||||
assertEqualFloat(1.0, mysensor.getWaveLengthFactor(), 0.001);
|
||||
assertEqualFloat(5.0, mysensor.getVoltage(), 0.001);
|
||||
assertEqualFloat(1.0, mysensor.getVoltageFactor(), 0.001);
|
||||
assertEqualFloat(0.00142, mysensor.getFactor(), 0.001);
|
||||
assertEqualFloat(0.001419659, mysensor.getFactor(), 0.001);
|
||||
|
||||
fprintf(stderr, "%1.6f\n", mysensor.getFactor() );
|
||||
}
|
||||
@ -64,6 +71,7 @@ unittest(test_constructor)
|
||||
unittest(test_wavelength)
|
||||
{
|
||||
TSL235R mysensor;
|
||||
|
||||
assertEqual(635, mysensor.getWavelength() );
|
||||
assertEqualFloat(1.0, mysensor.getWaveLengthFactor(), 0.001);
|
||||
fprintf(stderr,"\n");
|
||||
@ -90,6 +98,7 @@ unittest(test_wavelength)
|
||||
unittest(test_voltage)
|
||||
{
|
||||
TSL235R mysensor(2.7);
|
||||
|
||||
assertEqualFloat(2.7, mysensor.getVoltage(), 0.001);
|
||||
assertEqualFloat(0.988, mysensor.getVoltageFactor(), 0.001);
|
||||
fprintf(stderr,"\n");
|
||||
@ -116,6 +125,7 @@ unittest(test_voltage)
|
||||
unittest(test_conversion1)
|
||||
{
|
||||
TSL235R mysensor;
|
||||
|
||||
assertEqualFloat(1.0, mysensor.getVoltageFactor(), 0.001);
|
||||
assertEqualFloat(1.0, mysensor.getWaveLengthFactor(), 0.001);
|
||||
|
||||
@ -125,7 +135,7 @@ unittest(test_conversion1)
|
||||
for (uint32_t Hz = 10; Hz < 1000000; Hz *= 2)
|
||||
{
|
||||
float rad = mysensor.irradiance(Hz);
|
||||
assertEqualFloat(0.00142 * Hz, mysensor.irradiance(Hz), 0.001 * Hz); // we must have a relative error here!
|
||||
assertEqualFloat(0.001419659 * Hz, mysensor.irradiance(Hz), 0.001 * Hz); // we must have a relative error here!
|
||||
}
|
||||
}
|
||||
|
||||
@ -133,6 +143,7 @@ unittest(test_conversion1)
|
||||
unittest(test_conversion2)
|
||||
{
|
||||
TSL235R mysensor;
|
||||
|
||||
assertEqualFloat(1.0, mysensor.getVoltageFactor(), 0.001);
|
||||
assertEqualFloat(1.0, mysensor.getWaveLengthFactor(), 0.001);
|
||||
fprintf(stderr,"\n");
|
||||
@ -151,4 +162,5 @@ unittest(test_conversion2)
|
||||
unittest_main()
|
||||
|
||||
|
||||
// --------
|
||||
// -- END OF FILE --
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user