Skip to content

Commit

Permalink
0.1.2 TSL260R
Browse files Browse the repository at this point in the history
  • Loading branch information
RobTillaart committed Nov 28, 2022
1 parent 310a5ff commit 4a9c5b4
Show file tree
Hide file tree
Showing 11 changed files with 173 additions and 49 deletions.
9 changes: 9 additions & 0 deletions libraries/TSL260R/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 28 additions & 8 deletions libraries/TSL260R/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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

```
Expand All @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
58 changes: 28 additions & 30 deletions libraries/TSL260R/TSL260R .cpp → libraries/TSL260R/TSL260R.cpp
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -14,24 +14,21 @@ 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;
_bb = -0.02013423;
}


TSL260R::TSL260R()
{
TSL260R(0, 1, 0); // prevent divide by zero
// datasheet page 9
// voltage parameters
// irradiance parameters
_aa = 10.0067;
_bb = -0.02013423;
_bb = -0.02013423;
// waveLength parameters
_waveLength = 940;
_waveLength = 940;
_waveLengthFactor = 1.0;
}

Expand Down Expand Up @@ -61,13 +58,13 @@ void TSL260R::setWaveLength(uint16_t waveLength)

uint16_t TSL260R::getWaveLength()
{
return _waveLength;
return _waveLength;
}


float TSL260R::getWaveLengthFactor()
float TSL260R::getWaveLengthFactor()
{
return _waveLengthFactor;
return _waveLengthFactor;
}


Expand All @@ -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
Expand Down Expand Up @@ -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;
}


Expand All @@ -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 --

19 changes: 13 additions & 6 deletions libraries/TSL260R/TSL260R.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -36,12 +36,19 @@ class TSL260R
// 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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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 --
16 changes: 15 additions & 1 deletion libraries/TSL260R/examples/TSL260R_test/TSL260R_test.ino
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -14,6 +14,8 @@
#include "TSL260R.h"

TSL260R TSL0(A0, 1023, 5.0);
TSL261R TSL1;
TSL262R TSL2;

uint32_t lastMeasurement = 0;

Expand All @@ -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());
}


Expand Down
5 changes: 5 additions & 0 deletions libraries/TSL260R/keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ getWavelength KEYWORD2
getWaveLengthFactor KEYWORD2
calculateWaveLengthFactor KEYWORD2

setAA KEYWORD2
getAA KEYWORD2
setBB KEYWORD2
getBB KEYWORD2


# Constants (LITERAL1)
TSL260R_LIB_VERSION LITERAL1
Expand Down
2 changes: 1 addition & 1 deletion libraries/TSL260R/library.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "*",
Expand Down
Loading

0 comments on commit 4a9c5b4

Please sign in to comment.