Loading...
Pages: [1]   Go Down
Author Topic: Small sketch for TSL235R Light to Frequency sensor  (Read 2522 times)
0 Members and 1 Guest are viewing this topic.
Netherlands
Offline Offline
Tesla Member
***
Karma: 90
Posts: 9407
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Today I received two TSL235 sensors that convert incoming light to frequency. As there was no article on the playground yet on this particular sensor I wrote a small sketch and added some comments - http://arduino.cc/playground/Main/TSL235R - to get people started. The code does not compensate for anything yet (input voltage, temperature etc) ; maybe some future version.

In contrast to the TSL230R it has no configurable divider for the frequency so the # IRQ's can become quite high. Today's max inhouse ~160000 . Therefor I used only the rising edge for the IRQ routine. When it is really really dark one could use CHANGE edge for the IRQ, to double the precision, but be carefull as your Arduino might get stalled during daylight smiley

As always comments and remarks are welcome,

Rob

« Last Edit: May 16, 2011, 01:16:58 pm by robtillaart » Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

Offline Offline
Sr. Member
****
Karma: 0
Posts: 379
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Take a look, may be here you could found something interesting.
http://arduino.cc/forum/index.php/topic,21536.0.html

I hope it could helps you.
madepablo
Logged

Cotati California
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

...In contrast to the TSL230R it has no configurable divider for the frequency so the # IRQ's can become quite high. Today's max inhouse ~160000 . Therefor I used only the rising edge for the IRQ routine. When it is really really dark one could use CHANGE edge for the IRQ, to double the precision, but be carefull as your Arduino might get stalled during daylight smiley

As always comments and remarks are welcome,

Rob



I'm seeing this too, if the sensor sees the window the script output stops.  When I shield the sensor from bright light, it starts streaming output again, with the first value read being very high.

How do I set this up to scale for brighter environments? I'm trying to design a logger that tracks how many minutes of sunlight there are at a given location over the course of a day.  Any suggestions on getting this sensor to do the sensing?

Cheers, D 
Logged

Netherlands
Offline Offline
Tesla Member
***
Karma: 90
Posts: 9407
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

For bright sunlight you should use:  attachInterrupt(0, irq1, RISING);  -  but still it can generate too much IRQ's to handle. So if SW cannot handle HW comes in.

check - http://interface.khm.de/index.php/lab/experiments/arduino-frequency-counter-library/ - to get an idea how this can be done.

Please not that this lib affects internal timers so some things may not work anymore.

Another alternative is to make a HW divider before connecting to Arduino. check - http://www.scribd.com/doc/13305418/Building-Dividers-With-Flipflop -




« Last Edit: February 26, 2013, 01:59:25 pm by robtillaart » Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Dear Rob,
Thank you for the code. Works great with my Uno on digital pin 2, and on digital pin 3 with small change in code. Can you tell me how to modify it to read two TSL235 sensors?
Best, David
Logged

Netherlands
Offline Offline
Tesla Member
***
Karma: 90
Posts: 9407
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

two TSL should be something like this (not tested)
Code:
/*
 *    FILE: TSL235R_duo.pde
 *  AUTHOR: Rob Tillaart
 *    DATE: 2013-02-15
 *
 * PURPOSE: prototype TSL235R monitoring (double)  
 *
 * Digital Pin layout ARDUINO
 * =============================
 *  2     IRQ 0    - to TSL235R
 *
 * PIN 1 - GND
 * PIN 2 - VDD - 5V
 * PIN 3 - SIGNAL
 *
 */

volatile unsigned long counter1= 0;
volatile unsigned long counter2= 0;
unsigned long oldcnt1 = 0;
unsigned long oldcnt2 = 0;
unsigned long t = 0;
unsigned long last;

void irq1()
{
  counter1++;
}

void irq2()
{
  counter2++;
}

///////////////////////////////////////////////////////////////////
//
// SETUP
//
void setup()
{
  Serial.begin(115200);
  Serial.println("START");
  pinMode(2, INPUT);
  digitalWrite(2, HIGH);
  attachInterrupt(0, irq1, RISING);
  attachInterrupt(1, irq2, RISING);
}

///////////////////////////////////////////////////////////////////
//
// MAIN LOOP
//
void loop()
{
  if (millis() - last > 1000)
  {
    last = millis();
    t = counter1;
    unsigned long hz = t - oldcnt1;
    Serial.print("FREQ: ");
    Serial.print(hz);
    Serial.print("\t = ");
    Serial.print((hz+50)/100);  // +50 == rounding last digit
    Serial.println(" mW/m2");
    oldcnt1 = t;

    t = counter2;
    hz = t - oldcnt2;
    Serial.print("FREQ: ");
    Serial.print(hz);
    Serial.print("\t = ");
    Serial.print((hz+50)/100);  // +50 == rounding last digit
    Serial.println(" mW/m2");
    oldcnt2 = t;
  }
}
// END OF FILE

« Last Edit: February 17, 2013, 02:39:07 pm by robtillaart » Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This worked with two sensors.
Thanks!
Logged

Netherlands
Offline Offline
Tesla Member
***
Karma: 90
Posts: 9407
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Welcome!
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

Sweden
Offline Offline
Jr. Member
**
Karma: 0
Posts: 80
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is there any change i can use the code for the TSL237 - sensor?
That sensor is way more sensitive for low light, i believe it has a output frequency @ 21.8 μW/cm2 instead of the TSL235 that has 430 μW/cm2.

It may be some other differences to? Here is the PDF for it: https://docs.google.com/viewer?a=v&q=cache:Plvrk-_pFQwJ:www.ams.com/eng/content/download/250250/975933/file/TSL237-J.pdf+TSL237&hl=sv&pid=bl&srcid=ADGEESjUTdu6N77Fo19CfVUS9QH3XGxoRrMVamEsH0Ks55GQgOfOke8V-DaDA0qYjHfaNHOmm9-tUJVo5ovLYqdlAONPu6ZyLsKOm_iwdDCqSC2U_2hMFH2ynBy48mAt6bFnG9jLaAYl&sig=AHIEtbShhuCFzTVDeFqfAbEUaVrjHy2ypw

The reason i want to use this is that when i push a button i want to take a reading from the sensor, (or two-three readings and use a median value for better accuracy) and then calculate that value to Magnitude / square arc second http://old.nightwise.org/magnitudes.htm

so i dont wanna do a continous reading, just when i press a button, take a reading, display the magnitude/ square arc second on a lcd for about 10 sec. and then my arduino will continue with the rest of my code (witch is stepper motor controll with steps printout and a DHT-sensor.

Can this be done with this code?

BR/ Daniel
« Last Edit: February 25, 2013, 05:54:35 pm by Corpze » Logged

Netherlands
Offline Offline
Tesla Member
***
Karma: 90
Posts: 9407
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Is there any change i can use the code for the TSL237 - sensor?
You need to compare the datasheets and if the only diff is the light intensity/frequency relation it should be possible.

-update-
A quick look says yes as the output signal is typically 4.5V that is enough to trigger an IRQ I think. Otherwise you can add an extra transistor to make it 5V pulses.
« Last Edit: February 26, 2013, 02:10:08 pm by robtillaart » Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

Netherlands
Offline Offline
Tesla Member
***
Karma: 90
Posts: 9407
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The link to the TSL237 datasheet - http://www.ams.com/eng/content/download/250250/975933/file/TSL237-J.pdf -

At least a bit shorter smiley-wink
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

Pages: [1]   Go Up
Print
 
Jump to: