Skip to content

Commit 4a9c5b4

Browse files
committed
0.1.2 TSL260R
1 parent 310a5ff commit 4a9c5b4

File tree

11 files changed

+173
-49
lines changed

11 files changed

+173
-49
lines changed

libraries/TSL260R/CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

88

9+
## [0.1.2] - 2022-11-27
10+
- add getter / setter for \_aa and \_bb
11+
- add unit tests for get/set above
12+
- update comments
13+
- update readme.md
14+
- update examples
15+
- fix space in .cpp name
16+
17+
918
## [0.1.1] - 2022-11-27
1019
- update documentation
1120
- add analogRead Constructor

libraries/TSL260R/README.md

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ The TSL260R (TSL261R, TSL262R) is a IR sensor that outputs a voltage depending o
1717

1818
This library does convert the output voltage to uW/cm2.
1919

20-
As the sensors differ by sensitivity the library has three distinct classes.
20+
As the type sensor differ by sensitivity the library has three distinct classes.
2121
The table below is an approximation for the max irradiation at 3.3 Volt (output).
2222
For an Arduino UNO 3.3 V is about 650 ADC steps.
2323
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
3535
the library.
3636

3737

38-
3938
## Hardware Connection
4039

40+
#### Power supply
41+
42+
The maximum output voltage depends on the power supply voltage.
43+
This implies that the output range (uW/cm2) depends on power supply voltage.
44+
To maximize the measurement range a voltage of at leat 4.5 V is advised.
45+
46+
See datasheet figure 14: Maximum Output Voltage vs Supply Voltage
47+
48+
49+
#### Schema
50+
4151
Always check datasheet
4252

4353
```
@@ -51,7 +61,7 @@ Always check datasheet
5161

5262
## Interface
5363

54-
#### using internal ADC
64+
#### Internal ADC
5565

5666
- **TSL260R(uint8_t pin, uint16_t maxADC, float voltage)** Constructor when using an
5767
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.
6575
**Fails** by returning 0 when object is created with the other constructor.
6676

6777

68-
#### using external ADC
78+
#### External ADC
6979

7080
- **TSL260R()** constructor when using an external ADC or more than one internal samples
7181
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
94104

95105
#### Calibration
96106

97-
To elaborate.
107+
Since version 0.1.2 the following functions are added to calibrate the irradiance formula
108+
to some extend. The formula is ```irradiance = AA * voltage + BB```.
109+
110+
See datasheet figure 12: Output Voltage vs Irradiance
111+
112+
Use with care.
113+
114+
- **void setAA(float aa)** set a new value for AA.
115+
- **float getAA()** return the current value.
116+
- **void setBB(float bb)** set a new value for BB.
117+
- **float getBB()** return the current value.
98118

99119

100120
## Operations
@@ -108,15 +128,15 @@ See examples.
108128
- improve documentation
109129
- buy hardware (where)
110130
- test test test test
111-
- calibration
112-
- getters/setters for A and B to calibrate the sensor.
131+
113132

114133
#### should
115134
- extend unit tests
116135
- write examples
117136
- fix the dependency of **irradiance()**
118137
- derived class?
119-
- optimize code.
138+
- optimize code
139+
-
120140

121141
#### could
122142
- test with different IR LEDS (e.g. remote)

libraries/TSL260R/TSL260R .cpp renamed to libraries/TSL260R/TSL260R.cpp

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// FILE: TSL260R.cpp
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 0.1.1
4+
// VERSION: 0.1.2
55
// DATE: 2022-11-25
66
// PURPOSE: library for the TSL260R IR to voltage convertor
77

@@ -14,24 +14,21 @@ TSL260R::TSL260R(uint8_t pin, uint16_t maxADC, float voltage)
1414
_pin = pin;
1515
_voltagePerStep = voltage / maxADC;
1616
// datasheet page 9 figure 12
17-
// voltage parameters
17+
// irradiance parameters
1818
_aa = 10.0067;
19-
_bb = -0.02013423;
20-
// waveLength parameters
21-
_waveLength = 940;
22-
_waveLengthFactor = 1.0;
19+
_bb = -0.02013423;
2320
}
2421

2522

2623
TSL260R::TSL260R()
2724
{
2825
TSL260R(0, 1, 0); // prevent divide by zero
2926
// datasheet page 9
30-
// voltage parameters
27+
// irradiance parameters
3128
_aa = 10.0067;
32-
_bb = -0.02013423;
29+
_bb = -0.02013423;
3330
// waveLength parameters
34-
_waveLength = 940;
31+
_waveLength = 940;
3532
_waveLengthFactor = 1.0;
3633
}
3734

@@ -61,13 +58,13 @@ void TSL260R::setWaveLength(uint16_t waveLength)
6158

6259
uint16_t TSL260R::getWaveLength()
6360
{
64-
return _waveLength;
61+
return _waveLength;
6562
}
6663

6764

68-
float TSL260R::getWaveLengthFactor()
65+
float TSL260R::getWaveLengthFactor()
6966
{
70-
return _waveLengthFactor;
67+
return _waveLengthFactor;
7168
}
7269

7370

@@ -83,6 +80,21 @@ float TSL260R::calculateWaveLengthFactor(uint16_t waveLength)
8380
}
8481

8582

83+
///////////////////////////////////////////////////////
84+
//
85+
// irradiance parameters
86+
//
87+
void TSL260R::setAA(float aa) { _aa = aa; }
88+
float TSL260R::getAA() { return _aa; }
89+
90+
void TSL260R::setBB(float bb) { _bb = bb; }
91+
float TSL260R::getBB() { return _bb; }
92+
93+
94+
///////////////////////////////////////////////////////
95+
//
96+
// PRIVATE
97+
//
8698
float TSL260R::multiMap(float value, float * _in, float * _out, uint8_t size)
8799
{
88100
// take care the value is within range
@@ -111,24 +123,18 @@ float TSL260R::multiMap(float value, float * _in, float * _out, uint8_t size)
111123
TSL261R::TSL261R() : TSL260R()
112124
{
113125
// datasheet page 9
114-
// voltage parameters
126+
// irradiance parameters
115127
_aa = 23.34564;
116128
_bb = -0.03692;
117-
// waveLength parameters
118-
_waveLength = 940;
119-
_waveLengthFactor = 1.0;
120129
}
121130

122131

123132
TSL261R::TSL261R(uint8_t pin, uint16_t maxADC, float voltage) : TSL260R(pin, maxADC, voltage)
124133
{
125134
// datasheet page 9
126-
// voltage parameters
135+
// irradiance parameters
127136
_aa = 23.34564;
128137
_bb = -0.03692;
129-
// waveLength parameters
130-
_waveLength = 940;
131-
_waveLengthFactor = 1.0;
132138
}
133139

134140

@@ -139,28 +145,20 @@ TSL261R::TSL261R(uint8_t pin, uint16_t maxADC, float voltage) : TSL260R(pin, max
139145
TSL262R::TSL262R() : TSL260R()
140146
{
141147
// datasheet page 9
142-
// voltage parameters
148+
// irradiance parameters
143149
_aa = 110;
144150
_bb = 0;
145-
// waveLength parameters
146-
_waveLength = 940;
147-
_waveLengthFactor = 1.0;
148151
}
149152

150153

151-
152154
TSL262R::TSL262R(uint8_t pin, uint16_t maxADC, float voltage) : TSL260R(pin, maxADC, voltage)
153155
{
154156
// datasheet page 9
155-
// voltage parameters
157+
// irradiance parameters
156158
_aa = 110;
157159
_bb = 0;
158-
// waveLength parameters
159-
_waveLength = 940;
160-
_waveLengthFactor = 1.0;
161160
}
162161

163162

164-
165163
// -- END OF FILE --
166164

libraries/TSL260R/TSL260R.h

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
//
33
// FILE: TSL260R.h
44
// AUTHOR: Rob Tillaart
5-
// VERSION: 0.1.1
5+
// VERSION: 0.1.2
66
// DATE: 2022-11-25
77
// PURPOSE: library for the TSL260R IR to voltage convertor
88

99

10-
#define TSL260R_LIB_VERSION (F("0.1.1"))
10+
#define TSL260R_LIB_VERSION (F("0.1.2"))
1111

1212
#include "Arduino.h"
1313

@@ -36,12 +36,19 @@ class TSL260R
3636
// useful for debugging too
3737
float calculateWaveLengthFactor(uint16_t waveLength);
3838

39+
// irradiance parameters
40+
// only change these with care.
41+
void setAA(float aa);
42+
float getAA();
43+
void setBB(float aa);
44+
float getBB();
45+
3946

4047
protected:
41-
uint8_t _pin;
42-
float _voltagePerStep;
43-
uint16_t _waveLength;
44-
float _waveLengthFactor;
48+
uint8_t _pin = 0;
49+
float _voltagePerStep = 0;
50+
uint16_t _waveLength = 940;
51+
float _waveLengthFactor = 1;
4552
// _aa and _bb are defined in constructor;
4653
// need getter / setter to adjust values runtime
4754
float _aa;

libraries/TSL260R/examples/TSL260R_internal_ADC/TSL260R_internal_ADC.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// FILE: TSL260R_internal_ADC.ino
33
// AUTHOR: Rob Tillaart
4-
// PURPOSE: verify figure 12 datasheet page 9 voltage vs irradiance.
4+
// PURPOSE: demo internal ADC
55
// DATE: 2022-11-27
66
//
77
// always check datasheet
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//
2+
// FILE: TSL260R_internal_ADC_average.ino
3+
// AUTHOR: Rob Tillaart
4+
// PURPOSE: demo average internal ADC
5+
// DATE: 2022-11-28
6+
//
7+
// always check datasheet
8+
//
9+
// PIN 1 - GND
10+
// PIN 2 - VDD - 5V
11+
// PIN 3 - SIGNAL
12+
13+
14+
#include "TSL260R.h"
15+
16+
TSL260R TSL0(A0, 1023, 5.0); // Arduino UNO
17+
18+
uint32_t lastMeasurement = 0;
19+
20+
21+
void setup()
22+
{
23+
Serial.begin(115200);
24+
Serial.println();
25+
Serial.println(__FILE__);
26+
Serial.print("\nTSL260R_LIB_VERSION: ");
27+
Serial.println(TSL260R_LIB_VERSION);
28+
29+
Serial.println("\t TSL260\tTSL261\tTSL262");
30+
Serial.println("uW/cm2");
31+
Serial.println("========");
32+
}
33+
34+
35+
void loop()
36+
{
37+
uint32_t now = millis();
38+
if (now - lastMeasurement >= 100)
39+
{
40+
lastMeasurement = now;
41+
Serial.print(TSL0.irradiance(), 3);
42+
Serial.print("\t");
43+
44+
float voltage = 0;
45+
for (int i = 0; i < 10; i++)
46+
{
47+
voltage += analogRead(A0) * (5.0 / 1023);
48+
}
49+
Serial.println(TSL0.irradiance(voltage * 0.1), 3);
50+
}
51+
}
52+
53+
54+
// -- END OF FILE --

libraries/TSL260R/examples/TSL260R_test/TSL260R_test.ino

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// FILE: TSL260R_test.ino
33
// AUTHOR: Rob Tillaart
4-
// PURPOSE: verify figure 12 datasheet page 9 voltage vs irradiance.
4+
// PURPOSE: test wavelength
55
// DATE: 2022-11-27
66
//
77
// always check datasheet
@@ -14,6 +14,8 @@
1414
#include "TSL260R.h"
1515

1616
TSL260R TSL0(A0, 1023, 5.0);
17+
TSL261R TSL1;
18+
TSL262R TSL2;
1719

1820
uint32_t lastMeasurement = 0;
1921

@@ -28,6 +30,18 @@ void setup()
2830

2931
Serial.println(TSL0.getWaveLength());
3032
Serial.println(TSL0.getWaveLengthFactor());
33+
Serial.println(TSL0.getAA());
34+
Serial.println(TSL0.getBB());
35+
36+
Serial.println(TSL1.getWaveLength());
37+
Serial.println(TSL1.getWaveLengthFactor());
38+
Serial.println(TSL1.getAA());
39+
Serial.println(TSL1.getBB());
40+
41+
Serial.println(TSL2.getWaveLength());
42+
Serial.println(TSL2.getWaveLengthFactor());
43+
Serial.println(TSL2.getAA());
44+
Serial.println(TSL2.getBB());
3145
}
3246

3347

libraries/TSL260R/keywords.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ getWavelength KEYWORD2
1313
getWaveLengthFactor KEYWORD2
1414
calculateWaveLengthFactor KEYWORD2
1515

16+
setAA KEYWORD2
17+
getAA KEYWORD2
18+
setBB KEYWORD2
19+
getBB KEYWORD2
20+
1621

1722
# Constants (LITERAL1)
1823
TSL260R_LIB_VERSION LITERAL1

libraries/TSL260R/library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"type": "git",
1616
"url": "https://github.com/RobTillaart/TSL260R.git"
1717
},
18-
"version": "0.1.1",
18+
"version": "0.1.2",
1919
"license": "MIT",
2020
"frameworks": "*",
2121
"platforms": "*",

0 commit comments

Comments
 (0)