diff --git a/libraries/TSL260R/.arduino-ci.yml b/libraries/TSL260R/.arduino-ci.yml new file mode 100644 index 00000000..b4ab412d --- /dev/null +++ b/libraries/TSL260R/.arduino-ci.yml @@ -0,0 +1,27 @@ +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: + - uno + # - due + # - zero + # - leonardo + - m4 + - esp32 + - esp8266 + # - mega2560 + - rpipico diff --git a/libraries/TSL260R/.github/FUNDING.yml b/libraries/TSL260R/.github/FUNDING.yml new file mode 100644 index 00000000..90d9ab4c --- /dev/null +++ b/libraries/TSL260R/.github/FUNDING.yml @@ -0,0 +1,4 @@ +# These are supported funding model platforms + +github: RobTillaart + diff --git a/libraries/TSL260R/.github/workflows/arduino-lint.yml b/libraries/TSL260R/.github/workflows/arduino-lint.yml new file mode 100644 index 00000000..b2ca058c --- /dev/null +++ b/libraries/TSL260R/.github/workflows/arduino-lint.yml @@ -0,0 +1,13 @@ + +name: Arduino-lint + +on: [push, pull_request] +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: arduino/arduino-lint-action@v1 + with: + library-manager: update + compliance: strict diff --git a/libraries/TSL260R/.github/workflows/arduino_test_runner.yml b/libraries/TSL260R/.github/workflows/arduino_test_runner.yml new file mode 100644 index 00000000..096b975b --- /dev/null +++ b/libraries/TSL260R/.github/workflows/arduino_test_runner.yml @@ -0,0 +1,17 @@ +--- +name: Arduino CI + +on: [push, pull_request] + +jobs: + runTest: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: 2.6 + - run: | + gem install arduino_ci + arduino_ci.rb diff --git a/libraries/TSL260R/.github/workflows/jsoncheck.yml b/libraries/TSL260R/.github/workflows/jsoncheck.yml new file mode 100644 index 00000000..04603d08 --- /dev/null +++ b/libraries/TSL260R/.github/workflows/jsoncheck.yml @@ -0,0 +1,18 @@ +name: JSON check + +on: + push: + paths: + - '**.json' + pull_request: + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: json-syntax-check + uses: limitusus/json-syntax-check@v1 + with: + pattern: "\\.json$" + diff --git a/libraries/TSL260R/CHANGELOG.md b/libraries/TSL260R/CHANGELOG.md new file mode 100644 index 00000000..632e3f14 --- /dev/null +++ b/libraries/TSL260R/CHANGELOG.md @@ -0,0 +1,22 @@ +# Change Log TSL260R + +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.1] - 2022-11-27 +- update documentation +- add analogRead Constructor +- add irradiance() for internal analogRead() +- fix camelCase WaveLength +- update unit tests. +- add extra example. +- add keywords.txt + + +## [0.1.0] - 2022-11-25 +- initial version - written on datasheet only + Need to buy hardware for testing. + diff --git a/libraries/TSL260R/LICENSE b/libraries/TSL260R/LICENSE new file mode 100644 index 00000000..cb502675 --- /dev/null +++ b/libraries/TSL260R/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022-2022 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 +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/libraries/TSL260R/README.md b/libraries/TSL260R/README.md new file mode 100644 index 00000000..535b29d4 --- /dev/null +++ b/libraries/TSL260R/README.md @@ -0,0 +1,127 @@ + +[![Arduino CI](https://github.com/RobTillaart/TSL260R/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci) +[![Arduino-lint](https://github.com/RobTillaart/TSL260R/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/TSL260R/actions/workflows/arduino-lint.yml) +[![JSON check](https://github.com/RobTillaart/TSL260R/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/TSL260R/actions/workflows/jsoncheck.yml) +[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/TSL260R/blob/master/LICENSE) +[![GitHub release](https://img.shields.io/github/release/RobTillaart/TSL260R.svg?maxAge=3600)](https://github.com/RobTillaart/TSL260R/releases) + + +# TSL260R + +Arduino library for the TSL260R IR to voltage convertor + + +## Description + +The TSL260R (TSL261R, TSL262R) is a IR sensor that outputs a voltage depending on the irradiation. + +This library does convert the output voltage to uW/cm2. + +As the sensors 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. + +| Type | max uW/cm2 | +|:---------:|:------------:| +| TSL260R | 30 | +| TSL261R | 70 | +| TSL262R | 125 | + + +**Warning** this library is experimental so you should use it with care. +It is written on the datasheet, and I have no hardware yet to test it. +Of course I am very interested in your experiences and feedback to improve +the library. + + + +## Hardware Connection + +Always check datasheet + +``` +// Front view +// +// PIN 1 - GND +// PIN 2 - VDD 2.7 V .. 5.5 V +// PIN 3 - SIGNAL voltage out +``` + + +## Interface + +#### using 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. + - pin = analogRead() pin + - maxADC = max value of the internal ADC, UNO = 1023. + - voltage = max voltage of the internal ADC. +- **TSL261R(uint8_t pin, uint16_t maxADC, float voltage)** idem for TSL261R. +- **TSL262R(uint8_t pin, uint16_t maxADC, float voltage)** idem for TSL262R. +- **float irradiance()** returns the irradiance in uW/cm2. +Uses the analogRead() of the internal ADC. +**Fails** by returning 0 when object is created with the other constructor. + + +#### using external ADC + +- **TSL260R()** constructor when using an external ADC or more than one internal samples +to measure the voltage. +When using this constructor one cannot use the parameterless **irradiance()**, see above. +- **TSL261R()** idem for TSL261R. +- **TSL262R()** idem for TSL262R. +- **float irradiance(float voltage)** returns the irradiance in uW/cm2 based upon voltage +parameter. Does not use an internal analogRead(). +Note the user can average 8 internal ADC measurements to reduce noise and then use +this function based upon the average voltage. + + +#### WaveLength + +- **void setWaveLength(uint16_t waveLength = 940)** sets the wave length so the conversion +can use a correction factor. +At 900 - 940 nm the wave length correction factor == 1.0. +Wave length should be between 830 and 1100. +- **uint16_t getWaveLength()** returns the configured wave length. +- **float getWaveLengthFactor()** returns the wave length correction factor. +Note the sensor is most sensitive around 940 nm. See datasheet. +- **calculateWaveLengthFactor(uint16_t waveLength)** calculates the factor to compensate +for less sensitivity at other wave lengths. +E.g. if the sensor is 0.5 x as sensitive at a given wave length the factor should be 2. + + +#### Calibration + +To elaborate. + + +## Operations + +See examples. + + +## Future + +#### must +- 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. + +#### could +- test with different IR LEDS (e.g. remote) +- Normalized Output Voltage vs Angular Displacement correction + - figure 11 +- temperature correction +- + diff --git a/libraries/TSL260R/TSL260R .cpp b/libraries/TSL260R/TSL260R .cpp new file mode 100644 index 00000000..a2033231 --- /dev/null +++ b/libraries/TSL260R/TSL260R .cpp @@ -0,0 +1,166 @@ +// +// FILE: TSL260R.cpp +// AUTHOR: Rob Tillaart +// VERSION: 0.1.1 +// DATE: 2022-11-25 +// PURPOSE: library for the TSL260R IR to voltage convertor + + +#include "TSL260R.h" + + +TSL260R::TSL260R(uint8_t pin, uint16_t maxADC, float voltage) +{ + _pin = pin; + _voltagePerStep = voltage / maxADC; + // datasheet page 9 figure 12 + // voltage parameters + _aa = 10.0067; + _bb = -0.02013423; + // waveLength parameters + _waveLength = 940; + _waveLengthFactor = 1.0; +} + + +TSL260R::TSL260R() +{ + TSL260R(0, 1, 0); // prevent divide by zero + // datasheet page 9 + // voltage parameters + _aa = 10.0067; + _bb = -0.02013423; + // waveLength parameters + _waveLength = 940; + _waveLengthFactor = 1.0; +} + + +float TSL260R::irradiance(float voltage) +{ + float value = _aa * voltage + _bb; + if (_waveLengthFactor != 1.0) value *= _waveLengthFactor; + return value; +} + + +float TSL260R::irradiance() +{ + if (_voltagePerStep <= 0) return 0; + float voltage = analogRead(_pin) * _voltagePerStep; + return irradiance(voltage); +} + + +void TSL260R::setWaveLength(uint16_t waveLength) +{ + _waveLength = waveLength; + _waveLengthFactor = calculateWaveLengthFactor(_waveLength); +} + + +uint16_t TSL260R::getWaveLength() +{ + return _waveLength; +} + + +float TSL260R::getWaveLengthFactor() +{ + return _waveLengthFactor; +} + + +float TSL260R::calculateWaveLengthFactor(uint16_t waveLength) +{ + // figure 12 datasheet + // 940 nm is reference 1.000 + // remaining is linear interpolated between points in the graph + float in[] = { 800, 830, 880, 900, 940, 990, 1050, 1100, 1150}; + float out[] = { 0.01, 0.1, 0.8, 1.0, 1.0, 0.5, 0.3, 0.1, 0.01}; + // the correction factor is reciprocate as sensor is less sensitive. + return 1.0 / multiMap(waveLength, in, out, 9); +} + + +float TSL260R::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]); + if (value <= _in[0]) return _out[0]; + if (value >= _in[size-1]) return _out[size-1]; + + // 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 + if (value == _in[pos]) return _out[pos]; + + // 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]; +} + + + +/////////////////////////////////////////////////////// +// +// TSL261R +// +TSL261R::TSL261R() : TSL260R() +{ + // datasheet page 9 + // voltage 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 + _aa = 23.34564; + _bb = -0.03692; + // waveLength parameters + _waveLength = 940; + _waveLengthFactor = 1.0; +} + + +/////////////////////////////////////////////////////// +// +// TSL262R +// +TSL262R::TSL262R() : TSL260R() +{ + // datasheet page 9 + // voltage 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 + _aa = 110; + _bb = 0; + // waveLength parameters + _waveLength = 940; + _waveLengthFactor = 1.0; +} + + + +// -- END OF FILE -- + diff --git a/libraries/TSL260R/TSL260R.h b/libraries/TSL260R/TSL260R.h new file mode 100644 index 00000000..f2c840fd --- /dev/null +++ b/libraries/TSL260R/TSL260R.h @@ -0,0 +1,75 @@ +#pragma once +// +// FILE: TSL260R.h +// AUTHOR: Rob Tillaart +// VERSION: 0.1.1 +// DATE: 2022-11-25 +// PURPOSE: library for the TSL260R IR to voltage convertor + + +#define TSL260R_LIB_VERSION (F("0.1.1")) + +#include "Arduino.h" + + +class TSL260R +{ +public: + + // for internal ADC + TSL260R(uint8_t pin, uint16_t maxADC, float voltage); + // for external ADC + TSL260R(); + + // use internal ADC, defined in constructor + // uses a single analogRead() => defined by constructor. + float irradiance(); + // use external (or internal) ADC voltage. + // e.g to average multiple analogRead() calls + float irradiance(float voltage); + + // range: 800 - 1150 ==> 940 = default. + void setWaveLength(uint16_t waveLength = 940); + uint16_t getWaveLength(); + float getWaveLengthFactor(); + + // useful for debugging too + float calculateWaveLengthFactor(uint16_t waveLength); + + +protected: + uint8_t _pin; + float _voltagePerStep; + uint16_t _waveLength; + float _waveLengthFactor; + // _aa and _bb are defined in constructor; + // need getter / setter to adjust values runtime + float _aa; + float _bb; + float multiMap(float value, float * _in, float * _out, uint8_t size); +}; + + +/////////////////////////////////////////////////////// +// +// DERIVED CLASSES +// +class TSL261R : public TSL260R +{ +public: + TSL261R(); + TSL261R(uint8_t pin, uint16_t maxADC, float voltage); +}; + + +class TSL262R : public TSL260R +{ +public: + TSL262R(); + TSL262R(uint8_t pin, uint16_t maxADC, float voltage); +}; + + +// -- END OF FILE -- + + diff --git a/libraries/TSL260R/examples/TSL260R_demo/TSL260R_demo.ino b/libraries/TSL260R/examples/TSL260R_demo/TSL260R_demo.ino new file mode 100644 index 00000000..b93f6858 --- /dev/null +++ b/libraries/TSL260R/examples/TSL260R_demo/TSL260R_demo.ino @@ -0,0 +1,54 @@ +// +// FILE: TSL260R_demo.ino +// AUTHOR: Rob Tillaart +// PURPOSE: verify figure 12 datasheet page 9 voltage vs irradiance. +// DATE: 2022-11-27 +// +// always check datasheet +// +// PIN 1 - GND +// PIN 2 - VDD - 5V +// PIN 3 - SIGNAL + + +#include "TSL260R.h" + +TSL260R TSL0; +TSL261R TSL1; +TSL262R TSL2; + +uint32_t lastMeasurement = 0; + + +void setup() +{ + Serial.begin(115200); + Serial.println(); + Serial.println(__FILE__); + Serial.print(" TSL260R_LIB_VERSION: "); + Serial.println(TSL260R_LIB_VERSION); + + Serial.println("\t TSL260\tTSL261\tTSL262"); + Serial.println("Volt \t uW/cm2"); + Serial.println("=============================="); + for (float voltage = 0.1; voltage <= 3; voltage += 0.1) + { + Serial.print(voltage, 3); + Serial.print("\t"); + Serial.print(TSL0.irradiance(voltage), 3); + Serial.print("\t"); + Serial.print(TSL1.irradiance(voltage), 3); + Serial.print("\t"); + Serial.print(TSL2.irradiance(voltage), 3); + Serial.println(); + } + Serial.println("\ndone..."); +} + + +void loop() +{ +} + + +// -- END OF FILE -- diff --git a/libraries/TSL260R/examples/TSL260R_demo/output_0.1.0.txt b/libraries/TSL260R/examples/TSL260R_demo/output_0.1.0.txt new file mode 100644 index 00000000..0fbab614 --- /dev/null +++ b/libraries/TSL260R/examples/TSL260R_demo/output_0.1.0.txt @@ -0,0 +1,38 @@ +TSL260R_demo.ino + +TSL260R_LIB_VERSION: 0.1.0 + TSL260 TSL261 TSL262 +Volt uW/cm2 +============================== +0.100 0.981 2.298 11.000 +0.200 1.981 4.632 22.000 +0.300 2.982 6.967 33.000 +0.400 3.983 9.301 44.000 +0.500 4.983 11.636 55.000 +0.600 5.984 13.970 66.000 +0.700 6.985 16.305 77.000 +0.800 7.985 18.640 88.000 +0.900 8.986 20.974 99.000 +1.000 9.987 23.309 110.000 +1.100 10.987 25.643 121.000 +1.200 11.988 27.978 132.000 +1.300 12.989 30.312 143.000 +1.400 13.989 32.647 154.000 +1.500 14.990 34.982 165.000 +1.600 15.991 37.316 176.000 +1.700 16.991 39.651 187.000 +1.800 17.992 41.985 198.000 +1.900 18.993 44.320 209.000 +2.000 19.993 46.654 220.000 +2.100 20.994 48.989 231.000 +2.200 21.995 51.323 242.000 +2.300 22.995 53.658 253.000 +2.400 23.996 55.993 264.000 +2.500 24.997 58.327 275.000 +2.600 25.997 60.662 286.000 +2.700 26.998 62.996 297.000 +2.800 27.999 65.331 308.000 +2.900 28.999 67.665 319.000 +3.000 30.000 70.000 330.000 + +done... diff --git a/libraries/TSL260R/examples/TSL260R_internal_ADC/TSL260R_internal_ADC.ino b/libraries/TSL260R/examples/TSL260R_internal_ADC/TSL260R_internal_ADC.ino new file mode 100644 index 00000000..804e5b44 --- /dev/null +++ b/libraries/TSL260R/examples/TSL260R_internal_ADC/TSL260R_internal_ADC.ino @@ -0,0 +1,45 @@ +// +// FILE: TSL260R_internal_ADC.ino +// AUTHOR: Rob Tillaart +// PURPOSE: verify figure 12 datasheet page 9 voltage vs irradiance. +// DATE: 2022-11-27 +// +// 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) + { + Serial.println(TSL0.irradiance(), 3); + } +} + + +// -- END OF FILE -- diff --git a/libraries/TSL260R/examples/TSL260R_plotter/TSL260R_plotter.ino b/libraries/TSL260R/examples/TSL260R_plotter/TSL260R_plotter.ino new file mode 100644 index 00000000..ede82d70 --- /dev/null +++ b/libraries/TSL260R/examples/TSL260R_plotter/TSL260R_plotter.ino @@ -0,0 +1,46 @@ +// +// FILE: TSL260R_plotter.ino +// AUTHOR: Rob Tillaart +// PURPOSE: demo +// DATE: 2022-11-27 +// +// always check datasheet +// +// PIN 1 - GND +// PIN 2 - VDD - 5V +// PIN 3 - SIGNAL + + +#include "TSL260R.h" + +TSL260R TSL; + +uint32_t lastMeasurement = 0; + +void setup() +{ + Serial.begin(115200); + Serial.println(); +// Serial.println(__FILE__); +// Serial.print(" TSL260R_LIB_VERSION: "); +// Serial.println(TSL260R_LIB_VERSION); +} + + +void loop() +{ + uint32_t now = millis(); + if (now - lastMeasurement >= 100) + { + lastMeasurement = now; + + float voltage = analogRead(A0) * 5.0 / 1023; + Serial.print(voltage, 3); + Serial.print(" \t"); + Serial.print(TSL.irradiance(voltage), 3); + Serial.println(" uW/cm2"); + } +} + + +// -- END OF FILE -- diff --git a/libraries/TSL260R/examples/TSL260R_test/TSL260R_test.ino b/libraries/TSL260R/examples/TSL260R_test/TSL260R_test.ino new file mode 100644 index 00000000..e05cf26a --- /dev/null +++ b/libraries/TSL260R/examples/TSL260R_test/TSL260R_test.ino @@ -0,0 +1,39 @@ +// +// FILE: TSL260R_test.ino +// AUTHOR: Rob Tillaart +// PURPOSE: verify figure 12 datasheet page 9 voltage vs irradiance. +// DATE: 2022-11-27 +// +// always check datasheet +// +// PIN 1 - GND +// PIN 2 - VDD - 5V +// PIN 3 - SIGNAL + + +#include "TSL260R.h" + +TSL260R TSL0(A0, 1023, 5.0); + +uint32_t lastMeasurement = 0; + + +void setup() +{ + Serial.begin(115200); + Serial.println(); + Serial.println(__FILE__); + Serial.print(" TSL260R_LIB_VERSION: "); + Serial.println(TSL260R_LIB_VERSION); + + Serial.println(TSL0.getWaveLength()); + Serial.println(TSL0.getWaveLengthFactor()); +} + + +void loop() +{ +} + + +// -- END OF FILE -- diff --git a/libraries/TSL260R/keywords.txt b/libraries/TSL260R/keywords.txt new file mode 100644 index 00000000..67bfb613 --- /dev/null +++ b/libraries/TSL260R/keywords.txt @@ -0,0 +1,19 @@ +# Syntax Colouring Map For TSL260R + +# Data types (KEYWORD1) +TSL260R KEYWORD1 +TSL261R KEYWORD1 +TSL262R KEYWORD1 + + +# Methods and Functions (KEYWORD2) +irradiance KEYWORD2 +setWavelength KEYWORD2 +getWavelength KEYWORD2 +getWaveLengthFactor KEYWORD2 +calculateWaveLengthFactor KEYWORD2 + + +# Constants (LITERAL1) +TSL260R_LIB_VERSION LITERAL1 + diff --git a/libraries/TSL260R/library.json b/libraries/TSL260R/library.json new file mode 100644 index 00000000..642429d5 --- /dev/null +++ b/libraries/TSL260R/library.json @@ -0,0 +1,23 @@ +{ + "name": "TSL260R", + "keywords": "TSL260R,TSL261R,TSL262R,infrared, voltage, wavelength", + "description": "Arduino library for the TSL260R, TSL261R and TSL262R infrared to voltage convertor. Includes wavelength compensation. 940 nanoMeter is default.", + "authors": + [ + { + "name": "Rob Tillaart", + "email": "Rob.Tillaart@gmail.com", + "maintainer": true + } + ], + "repository": + { + "type": "git", + "url": "https://github.com/RobTillaart/TSL260R.git" + }, + "version": "0.1.1", + "license": "MIT", + "frameworks": "*", + "platforms": "*", + "headers": "TSL260R.h" +} diff --git a/libraries/TSL260R/library.properties b/libraries/TSL260R/library.properties new file mode 100644 index 00000000..68770bb7 --- /dev/null +++ b/libraries/TSL260R/library.properties @@ -0,0 +1,11 @@ +name=TSL260R +version=0.1.1 +author=Rob Tillaart +maintainer=Rob Tillaart +sentence=Arduino library for the TSL260R, TSL261R and TSL262R infrared to voltage convertor. +paragraph=Includes wavelength compensation. 940 nanoMeter is default. +category=Sensors +url=https://github.com/RobTillaart/TSL260R +architectures=* +includes=TSL260R.h +depends= diff --git a/libraries/TSL260R/test/unit_test_001.cpp b/libraries/TSL260R/test/unit_test_001.cpp new file mode 100644 index 00000000..95d75b0b --- /dev/null +++ b/libraries/TSL260R/test/unit_test_001.cpp @@ -0,0 +1,130 @@ +// +// FILE: unit_test_001.cpp +// AUTHOR: Rob Tillaart +// DATE: 2022-11-25 +// PURPOSE: unit tests for the temperature library +// https://github.com/RobTillaart/TSL260R +// https://github.com/Arduino-CI/arduino_ci/blob/master/REFERENCE.md +// + +// supported assertions +// ---------------------------- +// assertEqual(expected, actual); // a == b +// assertNotEqual(unwanted, actual); // a != b +// assertComparativeEquivalent(expected, actual); // abs(a - b) == 0 or (!(a > b) && !(a < b)) +// assertComparativeNotEquivalent(unwanted, actual); // abs(a - b) > 0 or ((a > b) || (a < b)) +// assertLess(upperBound, actual); // a < b +// assertMore(lowerBound, actual); // a > b +// assertLessOrEqual(upperBound, actual); // a <= b +// assertMoreOrEqual(lowerBound, actual); // a >= b +// assertTrue(actual); +// assertFalse(actual); +// assertNull(actual); + +// // special cases for floats +// assertEqualFloat(expected, actual, epsilon); // fabs(a - b) <= epsilon +// assertNotEqualFloat(unwanted, actual, epsilon); // fabs(a - b) >= epsilon +// assertInfinity(actual); // isinf(a) +// assertNotInfinity(actual); // !isinf(a) +// assertNAN(arg); // isnan(a) +// assertNotNAN(arg); // !isnan(a) + + +#include + + +#include "Arduino.h" +#include "TSL260R.h" + + +unittest_setup() +{ + fprintf(stderr, "TSL260R_LIB_VERSION: %s\n", (char *) TSL260R_LIB_VERSION); +} + + +unittest_teardown() +{ +} + + +unittest(test_constructor_I) +{ + TSL260R TSL0; + TSL261R TSL1; + TSL262R TSL2; + + 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, TSL2.getWaveLengthFactor(), 0.001); +} + + +unittest(test_constructor_II) +{ + TSL260R TSL0(14, 1023, 5.0); + TSL261R TSL1(14, 1023, 5.0); + TSL262R TSL2(14, 1023, 5.0); + + 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); +} + + +unittest(test_irradiance) +{ + TSL260R TSL0; + TSL261R TSL1; + TSL262R TSL2; + + // see output example 1 + assertEqualFloat(6.985, TSL0.irradiance(0.700), 0.001); + assertEqualFloat(16.305, TSL1.irradiance(0.700), 0.001); + assertEqualFloat(77.000, TSL2.irradiance(0.700), 0.001); +} + + +unittest(test_calculateWaveLengthFactor) +{ + TSL260R TSL; + + // check the internal table + assertEqualFloat(100, TSL.calculateWaveLengthFactor(700), 0.1); + assertEqualFloat(100, TSL.calculateWaveLengthFactor(800), 0.1); + assertEqualFloat(10, TSL.calculateWaveLengthFactor(830), 0.01); + assertEqualFloat(1.25, TSL.calculateWaveLengthFactor(880), 0.001); + assertEqualFloat(1.0, TSL.calculateWaveLengthFactor(900), 0.001); + assertEqualFloat(1.0, TSL.calculateWaveLengthFactor(940), 0.001); + assertEqualFloat(2.0, TSL.calculateWaveLengthFactor(990), 0.001); + assertEqualFloat(3.333, TSL.calculateWaveLengthFactor(1050), 0.001); + assertEqualFloat(10, TSL.calculateWaveLengthFactor(1100), 0.01); + assertEqualFloat(100, TSL.calculateWaveLengthFactor(1150), 0.1); + assertEqualFloat(100, TSL.calculateWaveLengthFactor(1200), 0.1); +} + + +unittest(test_get_setWaveLength) +{ + TSL260R TSL; + + for (uint16_t wavelen = 800; wavelen < 1200; wavelen += 50) + { + TSL.setWaveLength(wavelen); + assertEqual(wavelen, TSL.getWaveLength()); + } +} + + + +unittest_main() + + +// --------