0.1.2 TSL235R

This commit is contained in:
rob tillaart 2021-12-29 13:37:09 +01:00
parent 286fe0b44e
commit 378c0271e9
15 changed files with 100 additions and 109 deletions

View File

@ -2,6 +2,10 @@ compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
- uno
- leonardo
- due
- zero
# - due
# - zero
# - leonardo
- m4
- esp32
# - esp8266
# - mega2560

View File

@ -4,10 +4,14 @@ name: Arduino CI
on: [push, pull_request]
jobs:
arduino_ci:
runTest:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: Arduino-CI/action@master
# Arduino-CI/action@v0.1.1
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6
- run: |
gem install arduino_ci
arduino_ci.rb

View File

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2021-2021 Rob Tillaart
Copyright (c) 2020-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

View File

@ -1,5 +1,7 @@
[![Arduino CI](https://github.com/RobTillaart/TSL235R/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
[![Arduino-lint](https://github.com/RobTillaart/TSL235R/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/TSL235R/actions/workflows/arduino-lint.yml)
[![JSON check](https://github.com/RobTillaart/TSL235R/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/TSL235R/actions/workflows/jsoncheck.yml)
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/TSL235R/blob/master/LICENSE)
[![GitHub release](https://img.shields.io/github/release/RobTillaart/TSL235R.svg?maxAge=3600)](https://github.com/RobTillaart/TSL235R/releases)
@ -22,7 +24,7 @@ For measurements below 1uW/cm2 one bests measures for multiple seconds
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 nr of pulses in 1 second.
value to Hz, which is the number of pulses in 1 second.
## Connection
@ -46,11 +48,12 @@ 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.
- **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. At the default wavelength of 635 nm the wavelength correction factor == 1.0
- **void setWavelength(uint16_t wavelength = 635)** sets the wavelength so the formulas can use a
correction factor. At the default wavelength of 635 nm the wavelength correction factor == 1.0
- **uint16_t getWavelength()** returns the set wavelength. Convenience function.
- **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) monochomatic light.
This works only for (almost) monochromatic light.
- **void setVoltage(float voltage)** sets the voltage so the formulas can use a correction factor.
This voltage correction factor is rather small < 1.5%
- **float getVoltage()** returns the set voltage. Convenience function.
@ -63,6 +66,9 @@ See examples for typical usage.
## Future
- improve documentation
- test test test
- investigate hardware solutions for e.g. divide by 100 or so
- investigate correction factor for white light and mixed light sources.
- investigate callibration factor for timing of processor used.
- investigate calibration factor for timing of processor used.
-

View File

@ -1,12 +1,13 @@
//
// FILE: TSL235R.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.1.1
// PURPOSE: library fot the TSL235R light to frequency convertor
// VERSION: 0.1.2
// PURPOSE: library for the TSL235R light to frequency convertor
//
// HISTORY:
// 0.1.0 2020-05-29 initial version
// 0.1.1 2020-06-03 add irradiance_HS()
// 0.1.2 2021-12-29 update build-CI, readme, library.json, license, minor edits
#include "TSL235R.h"
@ -49,11 +50,12 @@ void TSL235R::setVoltage(float voltage)
calculateFactor();
}
void TSL235R::calculateFactor()
{
// figure 1 datasheet
// 1 Khz crosses the line at 35/230 between 1 and 10.
// so the correctiion factor is 10^0.15217 = 1.419659 = 1.42
// 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)
// as the graph is in kHz we need to correct a factor 1000
// as the irradiance function gets Hz
const float cf = 0.00142;
@ -75,24 +77,25 @@ float TSL235R::calcWLF(uint16_t _waveLength)
}
float TSL235R::multiMap(float val, float * _in, float * _out, uint8_t size)
float TSL235R::multiMap(float value, float * _in, float * _out, uint8_t size)
{
// take care the value is within range
// val = constrain(val, _in[0], _in[size-1]);
if (val <= _in[0]) return _out[0];
if (val >= _in[size-1]) return _out[size-1];
// 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] allready tested
while(val > _in[pos]) pos++;
uint8_t pos = 1; // _in[0] already tested
while(value > _in[pos]) pos++;
// this will handle all exact "points" in the _in array
if (val == _in[pos]) return _out[pos];
if (value == _in[pos]) return _out[pos];
// interpolate in the right segment for the rest
return (val - _in[pos-1]) * (_out[pos] - _out[pos-1]) / (_in[pos] - _in[pos-1]) + _out[pos-1];
uint8_t pos1 = pos - 1;
return (value - _in[pos1]) * (_out[pos] - _out[pos1]) / (_in[pos] - _in[pos1]) + _out[pos1];
}
// -- END OF FILE --

View File

@ -2,11 +2,11 @@
//
// FILE: TSL235R.h
// AUTHOR: Rob Tillaart
// VERSION: 0.1.1
// PURPOSE: library fot the TSL235R light to frequency convertor
// VERSION: 0.1.2
// PURPOSE: library for the TSL235R light to frequency convertor
#define TSL235R_LIB_VERSION (F("0.1.1"))
#define TSL235R_LIB_VERSION (F("0.1.2"))
#include "Arduino.h"
@ -18,7 +18,7 @@ public:
TSL235R(float voltage = 5.0);
float irradiance(uint32_t Hz);
float irradiance(uint32_t pulses, uint32_t milliseconds); // obsolete?
float irradiance(uint32_t pulses, uint32_t milliseconds); // obsolete?
float irradiance_HS(uint32_t pulses, uint32_t microseconds);
float getFactor() { return _factor; };
@ -30,6 +30,7 @@ public:
float getVoltage() { return _voltage; };
float getVoltageFactor() { return _voltageFactor; };
private:
uint16_t _waveLength = 635;
float _waveLengthFactor = 1.0;
@ -39,8 +40,9 @@ private:
void calculateFactor();
float calcWLF(uint16_t _waveLength);
float multiMap(float val, float * _in, float * _out, uint8_t size);
float multiMap(float value, float * _in, float * _out, uint8_t size);
};
// -- END OF FILE --

View File

@ -1,16 +1,13 @@
//
// FILE: TSL235R_demo.ino
// AUTHOR: Rob Tillaart
// VERSION: 0.1.1
// PURPOSE: demo
// DATE: 2021-05-29
//
// NOTE
// This code will work up to ~150KHz on an Arduino UNO
// above that frequency the interrupt saturate the processor.
//
// Digital Pin layout ARDUINO
// =============================
// 2 IRQ 0 - to TSL235R
@ -25,22 +22,18 @@
TSL235R mySensor;
volatile uint32_t cnt = 0;
uint32_t oldcnt = 0;
volatile uint32_t count = 0;
uint32_t oldCount = 0;
uint32_t t = 0;
uint32_t lastMeasurement = 0;
void count_irq()
{
cnt++;
count++;
}
///////////////////////////////////////////////////////////////////
//
// SETUP
//
void setup()
{
Serial.begin(115200);
@ -59,9 +52,9 @@ void loop()
if (now - lastMeasurement >= 1000)
{
lastMeasurement = now;
t = cnt;
uint32_t Hz = t - oldcnt;
oldcnt = t;
t = count;
uint32_t Hz = t - oldCount;
oldCount = t;
Serial.print("Hz: ");
Serial.print(Hz);
@ -71,4 +64,6 @@ void loop()
}
}
// -- END OF FILE --

View File

@ -1,15 +1,12 @@
//
// FILE: TSL235R_multi.ino
// AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// PURPOSE: demo
// DATE: 2021-05-29
//
// NOTE
// the max number of interrupt an Arduino UNO can handle
// is in the order of 150000 for all interrupts.
// the max number of interrupt an Arduino UNO can handle
// is in the order of ~150 KHz for all interrupts.
//
// Digital Pin layout ARDUINO
// =============================
@ -19,7 +16,6 @@
// PIN 1 - GND
// PIN 2 - VDD - 5V
// PIN 3 - SIGNAL
//
#include "TSL235R.h"
@ -41,6 +37,7 @@ void count_irq1()
cnt1++;
}
void count_irq2()
{
cnt2++;
@ -89,4 +86,6 @@ void loop()
}
}
// -- END OF FILE --

View File

@ -1,19 +1,16 @@
//
// FILE: TSL235R_multi_alternate.ino
// AUTHOR: Rob Tillaart
// VERSION: 0.1.1
// PURPOSE: demo
// DATE: 2021-05-29
//
// NOTE
// This code will work up to ~150 kHz on an Arduino UNO
// Note
// the max number of interrupt an Arduino UNO can handle
// is in the order of 20000.
// in the demo we alternate the two interrupt pins to be able
// to have a larger range per sensor.
// This code will work up to ~150 KHz on an Arduino UNO
//
// NOTE
// in the demo we alternate the two interrupt pins to be able
// to have a larger range per sensor.
// The price is that the values are behind at least a second.
//
// Digital Pin layout ARDUINO
// =============================
@ -23,7 +20,6 @@
// PIN 1 - GND
// PIN 2 - VDD - 5V
// PIN 3 - SIGNAL
//
#include "TSL235R.h"
@ -45,11 +41,6 @@ void count_irq()
}
///////////////////////////////////////////////////////////////////
//
// SETUP
//
void setup()
{
Serial.begin(115200);
@ -97,4 +88,6 @@ void loop()
// ...
}
// -- END OF FILE --

View File

@ -1,15 +1,14 @@
//
// FILE: TSL235R_non_interrupt.ino
// AUTHOR: Rob Tillaart
// VERSION: 0.1.1
// PURPOSE: demo polling
// DATE: 2021-06-03
//
// NOTE
// This code will work up to ~150 kHz on an Arduino UNO
// above that pulses come in faster than digitalRead
// can reliably handle
// This code will work up to ~150 kHz on an Arduino UNO
// above that pulses come in faster than digitalRead
// can reliably handle
//
// Digital Pin layout ARDUINO
// =============================
// 2 - to TSL235R
@ -25,10 +24,6 @@
TSL235R mySensor;
///////////////////////////////////////////////////////////////////
//
// SETUP
//
void setup()
{
Serial.begin(115200);
@ -59,4 +54,6 @@ void loop()
Serial.println(" uW/cm2");
}
// -- END OF FILE --

View File

@ -1,19 +1,16 @@
//
// FILE: TSL235R_non_interrupt_UNO.ino
// AUTHOR: Rob Tillaart
// VERSION: 0.1.1
// PURPOSE: demo polling with direct port access
// PURPOSE: demo polling with direct port access = AVR.UNO specific!
// DATE: 2021-06-03
//
// NOTE
// This code will work up to ~1700 kHz (3800 uW/cm2) on an Arduino UNO
// above that pulses come in faster than the code can reliably handle
// This code will work up to ~1700 kHz (3800 uW/cm2) on an Arduino UNO
// above that pulses come in faster than the code can reliably handle
//
// NOTE
// - the code is UNO specific as it uses low level PORT manipulations
// - the code is blocking and not suitable for low level of radiance.
// the code is UNO specific as it uses low level PORT manipulations
// the code is blocking and not suitable for low level of radiance.
//
// Digital Pin layout ARDUINO
// =============================
@ -22,7 +19,6 @@
// PIN 1 - GND
// PIN 2 - VDD - 5V
// PIN 3 - SIGNAL
//
#include "TSL235R.h"
@ -31,10 +27,6 @@
TSL235R mySensor;
///////////////////////////////////////////////////////////////////
//
// SETUP
//
void setup()
{
Serial.begin(115200);
@ -51,7 +43,7 @@ void loop()
uint32_t start = micros();
while (cnt < 60000)
{
while (PIND & 0x04); // wait for LOW
while (PIND & 0x04); // wait for LOW AVR.UNO specific !!
cnt++;
while ((PIND & 0x04) == 0x00); // wait for HIGH
}
@ -66,4 +58,6 @@ void loop()
Serial.println(" uW/cm2");
}
// -- END OF FILE --

View File

@ -1,14 +1,12 @@
//
// FILE: TSL235R_pulses.ino
// AUTHOR: Rob Tillaart
// VERSION: 0.1.1
// PURPOSE: demo
// DATE: 2021-05-29
//
// NOTE
// This code will work up to ~150 kHz on an Arduino UNO
// above that pulses come in faster than the code can reliably handle
//
// Digital Pin layout ARDUINO
// =============================
@ -18,13 +16,13 @@
// PIN 1 - GND
// PIN 2 - VDD - 5V
// PIN 3 - SIGNAL
//
#include "TSL235R.h"
TSL235R mySensor;
volatile uint32_t cnt1 = 0;
uint32_t oldcnt1 = 0;
uint32_t t = 0;
@ -37,10 +35,6 @@ void count_irq1()
}
///////////////////////////////////////////////////////////////////
//
// SETUP
//
void setup()
{
Serial.begin(115200);
@ -75,4 +69,6 @@ void loop()
}
}
// -- END OF FILE --

View File

@ -15,8 +15,9 @@
"type": "git",
"url": "https://github.com/RobTillaart/TSL235R.git"
},
"version": "0.1.1",
"version": "0.1.2",
"license": "MIT",
"frameworks": "*",
"platforms": "*"
"platforms": "*",
"headers": "TSL235R.h"
}

View File

@ -1,5 +1,5 @@
name=TSL235R
version=0.1.1
version=0.1.2
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Library for the TSL235R light to frequency convertor.

View File

@ -29,6 +29,7 @@
// assertNAN(arg); // isnan(a)
// assertNotNAN(arg); // !isnan(a)
#include <ArduinoUnitTests.h>
@ -36,23 +37,19 @@
#include "TSL235R.h"
unittest_setup()
{
fprintf(stderr, "TSL235R_LIB_VERSION: %s\n", (char *) TSL235R_LIB_VERSION);
}
unittest_teardown()
{
}
unittest(test_constructor)
{
fprintf(stderr, "VERSION: %s\n", TSL235R_LIB_VERSION);
TSL235R mysensor;
assertEqual(635, mysensor.getWavelength() );
assertEqualFloat(1.0, mysensor.getWaveLengthFactor(), 0.001);