0.1.1 TSL235R

This commit is contained in:
rob tillaart 2021-06-04 15:58:39 +02:00
parent b1cd76d5f9
commit 4ae99be508
12 changed files with 196 additions and 33 deletions

View File

@ -39,10 +39,12 @@ value to Hz, which is the nr of pulses in 1 second.
- **TSL235R(float voltage = 5.0)** constructor, optionally one can give the operational voltage
to add a small correction (< 1.5%)
- **float irradiance(uint32_t Hz)** returns the irradiance in uW/cm2.
NOte that Hz implies the measured pulses for 1 second.
Note that Hz implies the measured pulses for 1 second.
- **float irradiance(uint32_t pulses, uint32_t milliseconds)** returns the irradiance in uW/cm2
This formula is used for other duration than 1 second.
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
- **uint16_t getWavelength()** returns the set wavelength. Convenience function.
@ -62,3 +64,5 @@ See examples for typical usage.
## Future
- investigate correction factor for white light and mixed light sources.
- investigate callibration factor for timing of processor used.
-

View File

@ -1,11 +1,12 @@
//
// FILE: TSL235R.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// VERSION: 0.1.1
// PURPOSE: library fot the TSL235R light to frequency convertor
//
// HISTORY:
// 0.1.0 2020-05-29 initial version
// 0.1.1 2020-06-03 add irradiance_HS()
#include "TSL235R.h"
@ -29,6 +30,11 @@ float TSL235R::irradiance(uint32_t pulses, uint32_t milliseconds)
return (pulses * 1000.0 * _factor) / milliseconds;
}
float TSL235R::irradiance_HS(uint32_t pulses, uint32_t microseconds)
{
return (pulses * 1000000.0 * _factor) / microseconds;
}
void TSL235R::setWavelength(uint16_t wavelength)
{

View File

@ -2,11 +2,11 @@
//
// FILE: TSL235R.h
// AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// VERSION: 0.1.1
// PURPOSE: library fot the TSL235R light to frequency convertor
#define TSL235R_LIB_VERSION (F("0.1.0"))
#define TSL235R_LIB_VERSION (F("0.1.1"))
#include "Arduino.h"
@ -18,7 +18,8 @@ public:
TSL235R(float voltage = 5.0);
float irradiance(uint32_t Hz);
float irradiance(uint32_t pulses, uint32_t milliseconds);
float irradiance(uint32_t pulses, uint32_t milliseconds); // obsolete?
float irradiance_HS(uint32_t pulses, uint32_t microseconds);
float getFactor() { return _factor; };
void setWavelength(uint16_t wavelength = 635);

View File

@ -1,11 +1,16 @@
//
// FILE: TSL235R_demo.ino
// AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// 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
@ -13,7 +18,6 @@
// PIN 1 - GND
// PIN 2 - VDD - 5V
// PIN 3 - SIGNAL
//
#include "TSL235R.h"
@ -42,9 +46,8 @@ void setup()
Serial.begin(115200);
Serial.println(__FILE__);
pinMode(2, INPUT);
digitalWrite(2, HIGH);
attachInterrupt(0, count_irq, RISING);
pinMode(2, INPUT_PULLUP);
attachInterrupt(0, count_irq, FALLING);
mySensor.setWavelength(450);
}
@ -60,7 +63,9 @@ void loop()
uint32_t Hz = t - oldcnt;
oldcnt = t;
Serial.print("irradiance:\t");
Serial.print("Hz: ");
Serial.print(Hz);
Serial.print("\t");
Serial.print(mySensor.irradiance(Hz)); // assumption 1 second
Serial.println(" uW/cm2");
}

View File

@ -5,8 +5,9 @@
// PURPOSE: demo
// DATE: 2021-05-29
// Note the max number of interrupt an Arduino UNO can handle
// is in the order of 20000.
// NOTE
// the max number of interrupt an Arduino UNO can handle
// is in the order of 150000 for all interrupts.
//
@ -14,7 +15,7 @@
// =============================
// 2 IRQ 0 - to TSL235R
// 3 IRQ 1 - to TSL235R
//
//
// PIN 1 - GND
// PIN 2 - VDD - 5V
// PIN 3 - SIGNAL
@ -55,8 +56,8 @@ void setup()
Serial.begin(115200);
Serial.println(__FILE__);
pinMode(2, INPUT);
digitalWrite(2, HIGH);
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
attachInterrupt(0, count_irq1, RISING);
attachInterrupt(1, count_irq2, RISING);
@ -76,14 +77,14 @@ void loop()
uint32_t Hz = t - oldcnt1;
oldcnt1 = t;
Serial.print("irradiance 450 nm:\t");
Serial.print(mySensor_450.irradiance(Hz)); // assumption 1 second
Serial.print(mySensor_450.irradiance(Hz));
Serial.println(" uW/cm2");
t = cnt2;
Hz = t - oldcnt2;
oldcnt2 = t;
Serial.print("irradiance 650 nm:\t");
Serial.print(mySensor_650.irradiance(Hz)); // assumption 1 second
Serial.print(mySensor_650.irradiance(Hz));
Serial.println(" uW/cm2");
}
}

View File

@ -1,11 +1,15 @@
//
// FILE: TSL235R_multi_alternate.ino
// AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// VERSION: 0.1.1
// PURPOSE: demo
// DATE: 2021-05-29
// Note the max number of interrupt an Arduino UNO can handle
// 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.
@ -51,14 +55,14 @@ void setup()
Serial.begin(115200);
Serial.println(__FILE__);
pinMode(2, INPUT);
digitalWrite(2, HIGH);
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
mySensor_450.setWavelength(450);
mySensor_650.setWavelength(650);
irq_select = 0;
attachInterrupt(0, count_irq, RISING);
attachInterrupt(0, count_irq, FALLING);
lastMeasurement = millis();
}
@ -75,7 +79,7 @@ void loop()
Serial.println(" uW/cm2");
pulses = 0;
irq_select = 1;
attachInterrupt(irq_select, count_irq, RISING);
attachInterrupt(irq_select, count_irq, FALLING);
}
else
{
@ -85,7 +89,7 @@ void loop()
Serial.println(" uW/cm2");
pulses = 0;
irq_select = 0;
attachInterrupt(irq_select, count_irq, RISING);
attachInterrupt(irq_select, count_irq, FALLING);
}
lastMeasurement = millis();
}

View File

@ -0,0 +1,62 @@
//
// 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
// Digital Pin layout ARDUINO
// =============================
// 2 - to TSL235R
//
// PIN 1 - GND
// PIN 2 - VDD - 5V
// PIN 3 - SIGNAL
#include "TSL235R.h"
TSL235R mySensor;
///////////////////////////////////////////////////////////////////
//
// SETUP
//
void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
pinMode(2, INPUT_PULLUP);
mySensor.setWavelength(450);
}
void loop()
{
uint16_t cnt = 0;
uint32_t start = micros();
while (cnt < 50000)
{
while (digitalRead(2) == HIGH); // wait for LOW
cnt++;
while (digitalRead(2) == LOW); // wait for HIGH
}
uint32_t duration = micros() - start;
float freq = (1e6 * cnt) / duration;
Serial.print("Hz: ");
Serial.print(freq);
Serial.print("\t");
Serial.print(mySensor.irradiance(freq)); // assumption 1 second
Serial.println(" uW/cm2");
}
// -- END OF FILE --

View File

@ -0,0 +1,7 @@
compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
- uno
- leonardo
# - due
# - zero

View File

@ -0,0 +1,69 @@
//
// FILE: TSL235R_non_interrupt_UNO.ino
// AUTHOR: Rob Tillaart
// VERSION: 0.1.1
// PURPOSE: demo polling with direct port access
// 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
// 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.
//
// Digital Pin layout ARDUINO
// =============================
// 2 - to TSL235R
//
// PIN 1 - GND
// PIN 2 - VDD - 5V
// PIN 3 - SIGNAL
//
#include "TSL235R.h"
TSL235R mySensor;
///////////////////////////////////////////////////////////////////
//
// SETUP
//
void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
pinMode(2, INPUT_PULLUP);
mySensor.setWavelength(450);
}
void loop()
{
uint16_t cnt = 0;
uint32_t start = micros();
while (cnt < 60000)
{
while (PIND & 0x04); // wait for LOW
cnt++;
while ((PIND & 0x04) == 0x00); // wait for HIGH
}
uint32_t duration = micros() - start;
float freq = (1e6 * cnt) / duration;
Serial.print("Hz: ");
Serial.print(freq);
Serial.print("\t");
Serial.print(mySensor.irradiance_HS(cnt, duration));
// Serial.print(mySensor.irradiance(freq));
Serial.println(" uW/cm2");
}
// -- END OF FILE --

View File

@ -1,10 +1,14 @@
//
// FILE: TSL235R_pulses.ino
// AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// 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
// =============================
@ -42,9 +46,8 @@ void setup()
Serial.begin(115200);
Serial.println(__FILE__);
pinMode(2, INPUT);
digitalWrite(2, HIGH);
attachInterrupt(0, count_irq1, RISING);
pinMode(2, INPUT_PULLUP);
attachInterrupt(0, count_irq1, FALLING);
mySensor.setWavelength(450);
}
@ -59,6 +62,7 @@ void loop()
t = cnt1;
uint32_t Hz = t - oldcnt1;
oldcnt1 = t;
Serial.print("irradiance(Hz):\t\t");
Serial.print(mySensor.irradiance(Hz)); // assumption 1 second
Serial.println(" uW/cm2");

View File

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

View File

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