0.1.2 TSL260R

This commit is contained in:
rob tillaart 2022-11-28 12:34:24 +01:00
parent 310a5ff00e
commit 4a9c5b453b
11 changed files with 173 additions and 49 deletions

View File

@ -6,6 +6,15 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [0.1.2] - 2022-11-27
- add getter / setter for \_aa and \_bb
- add unit tests for get/set above
- update comments
- update readme.md
- update examples
- fix space in .cpp name
## [0.1.1] - 2022-11-27
- update documentation
- add analogRead Constructor

View File

@ -17,7 +17,7 @@ The TSL260R (TSL261R, TSL262R) is a IR sensor that outputs a voltage depending o
This library does convert the output voltage to uW/cm2.
As the sensors differ by sensitivity the library has three distinct classes.
As the type sensor differ by sensitivity the library has three distinct classes.
The table below is an approximation for the max irradiation at 3.3 Volt (output).
For an Arduino UNO 3.3 V is about 650 ADC steps.
When using e.g. an external 16 bit ADS1115, one definitely has far more steps.
@ -35,9 +35,19 @@ Of course I am very interested in your experiences and feedback to improve
the library.
## Hardware Connection
#### Power supply
The maximum output voltage depends on the power supply voltage.
This implies that the output range (uW/cm2) depends on power supply voltage.
To maximize the measurement range a voltage of at leat 4.5 V is advised.
See datasheet figure 14: Maximum Output Voltage vs Supply Voltage
#### Schema
Always check datasheet
```
@ -51,7 +61,7 @@ Always check datasheet
## Interface
#### using internal ADC
#### Internal ADC
- **TSL260R(uint8_t pin, uint16_t maxADC, float voltage)** Constructor when using an
internal ADC and just one sample to measure the output voltage of the sensor.
@ -65,7 +75,7 @@ Uses the analogRead() of the internal ADC.
**Fails** by returning 0 when object is created with the other constructor.
#### using external ADC
#### External ADC
- **TSL260R()** constructor when using an external ADC or more than one internal samples
to measure the voltage.
@ -94,7 +104,17 @@ E.g. if the sensor is 0.5 x as sensitive at a given wave length the factor shoul
#### Calibration
To elaborate.
Since version 0.1.2 the following functions are added to calibrate the irradiance formula
to some extend. The formula is ```irradiance = AA * voltage + BB```.
See datasheet figure 12: Output Voltage vs Irradiance
Use with care.
- **void setAA(float aa)** set a new value for AA.
- **float getAA()** return the current value.
- **void setBB(float bb)** set a new value for BB.
- **float getBB()** return the current value.
## Operations
@ -108,15 +128,15 @@ See examples.
- improve documentation
- buy hardware (where)
- test test test test
- calibration
- getters/setters for A and B to calibrate the sensor.
#### should
- extend unit tests
- write examples
- fix the dependency of **irradiance()**
- derived class?
- optimize code.
- optimize code
-
#### could
- test with different IR LEDS (e.g. remote)

View File

@ -1,7 +1,7 @@
//
// FILE: TSL260R.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.1.1
// VERSION: 0.1.2
// DATE: 2022-11-25
// PURPOSE: library for the TSL260R IR to voltage convertor
@ -14,12 +14,9 @@ TSL260R::TSL260R(uint8_t pin, uint16_t maxADC, float voltage)
_pin = pin;
_voltagePerStep = voltage / maxADC;
// datasheet page 9 figure 12
// voltage parameters
// irradiance parameters
_aa = 10.0067;
_bb = -0.02013423;
// waveLength parameters
_waveLength = 940;
_waveLengthFactor = 1.0;
}
@ -27,7 +24,7 @@ TSL260R::TSL260R()
{
TSL260R(0, 1, 0); // prevent divide by zero
// datasheet page 9
// voltage parameters
// irradiance parameters
_aa = 10.0067;
_bb = -0.02013423;
// waveLength parameters
@ -83,6 +80,21 @@ float TSL260R::calculateWaveLengthFactor(uint16_t waveLength)
}
///////////////////////////////////////////////////////
//
// irradiance parameters
//
void TSL260R::setAA(float aa) { _aa = aa; }
float TSL260R::getAA() { return _aa; }
void TSL260R::setBB(float bb) { _bb = bb; }
float TSL260R::getBB() { return _bb; }
///////////////////////////////////////////////////////
//
// PRIVATE
//
float TSL260R::multiMap(float value, float * _in, float * _out, uint8_t size)
{
// take care the value is within range
@ -111,24 +123,18 @@ float TSL260R::multiMap(float value, float * _in, float * _out, uint8_t size)
TSL261R::TSL261R() : TSL260R()
{
// datasheet page 9
// voltage parameters
// irradiance parameters
_aa = 23.34564;
_bb = -0.03692;
// waveLength parameters
_waveLength = 940;
_waveLengthFactor = 1.0;
}
TSL261R::TSL261R(uint8_t pin, uint16_t maxADC, float voltage) : TSL260R(pin, maxADC, voltage)
{
// datasheet page 9
// voltage parameters
// irradiance parameters
_aa = 23.34564;
_bb = -0.03692;
// waveLength parameters
_waveLength = 940;
_waveLengthFactor = 1.0;
}
@ -139,28 +145,20 @@ TSL261R::TSL261R(uint8_t pin, uint16_t maxADC, float voltage) : TSL260R(pin, max
TSL262R::TSL262R() : TSL260R()
{
// datasheet page 9
// voltage parameters
// irradiance parameters
_aa = 110;
_bb = 0;
// waveLength parameters
_waveLength = 940;
_waveLengthFactor = 1.0;
}
TSL262R::TSL262R(uint8_t pin, uint16_t maxADC, float voltage) : TSL260R(pin, maxADC, voltage)
{
// datasheet page 9
// voltage parameters
// irradiance parameters
_aa = 110;
_bb = 0;
// waveLength parameters
_waveLength = 940;
_waveLengthFactor = 1.0;
}
// -- END OF FILE --

View File

@ -2,12 +2,12 @@
//
// FILE: TSL260R.h
// AUTHOR: Rob Tillaart
// VERSION: 0.1.1
// VERSION: 0.1.2
// DATE: 2022-11-25
// PURPOSE: library for the TSL260R IR to voltage convertor
#define TSL260R_LIB_VERSION (F("0.1.1"))
#define TSL260R_LIB_VERSION (F("0.1.2"))
#include "Arduino.h"
@ -36,12 +36,19 @@ public:
// useful for debugging too
float calculateWaveLengthFactor(uint16_t waveLength);
// irradiance parameters
// only change these with care.
void setAA(float aa);
float getAA();
void setBB(float aa);
float getBB();
protected:
uint8_t _pin;
float _voltagePerStep;
uint16_t _waveLength;
float _waveLengthFactor;
uint8_t _pin = 0;
float _voltagePerStep = 0;
uint16_t _waveLength = 940;
float _waveLengthFactor = 1;
// _aa and _bb are defined in constructor;
// need getter / setter to adjust values runtime
float _aa;

View File

@ -1,7 +1,7 @@
//
// FILE: TSL260R_internal_ADC.ino
// AUTHOR: Rob Tillaart
// PURPOSE: verify figure 12 datasheet page 9 voltage vs irradiance.
// PURPOSE: demo internal ADC
// DATE: 2022-11-27
//
// always check datasheet

View File

@ -0,0 +1,54 @@
//
// FILE: TSL260R_internal_ADC_average.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo average internal ADC
// DATE: 2022-11-28
//
// always check datasheet
//
// PIN 1 - GND
// PIN 2 - VDD - 5V
// PIN 3 - SIGNAL
#include "TSL260R.h"
TSL260R TSL0(A0, 1023, 5.0); // Arduino UNO
uint32_t lastMeasurement = 0;
void setup()
{
Serial.begin(115200);
Serial.println();
Serial.println(__FILE__);
Serial.print("\nTSL260R_LIB_VERSION: ");
Serial.println(TSL260R_LIB_VERSION);
Serial.println("\t TSL260\tTSL261\tTSL262");
Serial.println("uW/cm2");
Serial.println("========");
}
void loop()
{
uint32_t now = millis();
if (now - lastMeasurement >= 100)
{
lastMeasurement = now;
Serial.print(TSL0.irradiance(), 3);
Serial.print("\t");
float voltage = 0;
for (int i = 0; i < 10; i++)
{
voltage += analogRead(A0) * (5.0 / 1023);
}
Serial.println(TSL0.irradiance(voltage * 0.1), 3);
}
}
// -- END OF FILE --

View File

@ -1,7 +1,7 @@
//
// FILE: TSL260R_test.ino
// AUTHOR: Rob Tillaart
// PURPOSE: verify figure 12 datasheet page 9 voltage vs irradiance.
// PURPOSE: test wavelength
// DATE: 2022-11-27
//
// always check datasheet
@ -14,6 +14,8 @@
#include "TSL260R.h"
TSL260R TSL0(A0, 1023, 5.0);
TSL261R TSL1;
TSL262R TSL2;
uint32_t lastMeasurement = 0;
@ -28,6 +30,18 @@ void setup()
Serial.println(TSL0.getWaveLength());
Serial.println(TSL0.getWaveLengthFactor());
Serial.println(TSL0.getAA());
Serial.println(TSL0.getBB());
Serial.println(TSL1.getWaveLength());
Serial.println(TSL1.getWaveLengthFactor());
Serial.println(TSL1.getAA());
Serial.println(TSL1.getBB());
Serial.println(TSL2.getWaveLength());
Serial.println(TSL2.getWaveLengthFactor());
Serial.println(TSL2.getAA());
Serial.println(TSL2.getBB());
}

View File

@ -13,6 +13,11 @@ getWavelength KEYWORD2
getWaveLengthFactor KEYWORD2
calculateWaveLengthFactor KEYWORD2
setAA KEYWORD2
getAA KEYWORD2
setBB KEYWORD2
getBB KEYWORD2
# Constants (LITERAL1)
TSL260R_LIB_VERSION LITERAL1

View File

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

View File

@ -1,5 +1,5 @@
name=TSL260R
version=0.1.1
version=0.1.2
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for the TSL260R, TSL261R and TSL262R infrared to voltage convertor.

View File

@ -61,6 +61,14 @@ unittest(test_constructor_I)
assertEqualFloat(1.0, TSL0.getWaveLengthFactor(), 0.001);
assertEqualFloat(1.0, TSL1.getWaveLengthFactor(), 0.001);
assertEqualFloat(1.0, TSL2.getWaveLengthFactor(), 0.001);
assertEqualFloat(10.0067, TSL0.getAA(), 0.001);
assertEqualFloat(23.34564, TSL1.getAA(), 0.001);
assertEqualFloat(110, TSL2.getAA(), 0.001);
assertEqualFloat(-0.02013423, TSL0.getBB(), 0.001);
assertEqualFloat(-0.03692, TSL1.getBB(), 0.001);
assertEqualFloat(0, TSL2.getBB(), 0.001);
}
@ -73,9 +81,18 @@ unittest(test_constructor_II)
assertEqual(940, TSL0.getWaveLength() );
assertEqual(940, TSL1.getWaveLength() );
assertEqual(940, TSL2.getWaveLength() );
assertEqualFloat(1.0, TSL0.getWaveLengthFactor(), 0.001);
assertEqualFloat(1.0, TSL1.getWaveLengthFactor(), 0.001);
assertEqualFloat(1.0, TSL1.getWaveLengthFactor(), 0.001);
assertEqualFloat(10.0067, TSL0.getAA(), 0.001);
assertEqualFloat(23.34564, TSL1.getAA(), 0.001);
assertEqualFloat(110, TSL2.getAA(), 0.001);
assertEqualFloat(-0.02013423, TSL0.getBB(), 0.001);
assertEqualFloat(-0.03692, TSL1.getBB(), 0.001);
assertEqualFloat(0, TSL2.getBB(), 0.001);
}