Netherlands
Offline
Tesla Member
Karma: 90
Posts: 9407
In theory there is no difference between theory and practice, however in practice there are many...
|
 |
« on: May 16, 2011, 10:26:13 am » |
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 As always comments and remarks are welcome, Rob
|
|
|
|
« Last Edit: May 16, 2011, 01:16:58 pm by robtillaart »
|
Logged
|
|
|
|
|
|
|
Cotati California
Offline
Newbie
Karma: 0
Posts: 4
|
 |
« Reply #2 on: June 09, 2011, 12:58:22 pm » |
...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 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
Tesla Member
Karma: 90
Posts: 9407
In theory there is no difference between theory and practice, however in practice there are many...
|
 |
« Reply #3 on: June 10, 2011, 02:48:42 am » |
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
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 4
|
 |
« Reply #4 on: February 14, 2013, 08:16:27 pm » |
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
Tesla Member
Karma: 90
Posts: 9407
In theory there is no difference between theory and practice, however in practice there are many...
|
 |
« Reply #5 on: February 15, 2013, 05:33:00 pm » |
two TSL should be something like this (not tested) /* * 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
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 4
|
 |
« Reply #6 on: February 16, 2013, 08:17:43 am » |
This worked with two sensors. Thanks!
|
|
|
|
|
Logged
|
|
|
|
|
Netherlands
Offline
Tesla Member
Karma: 90
Posts: 9407
In theory there is no difference between theory and practice, however in practice there are many...
|
 |
« Reply #7 on: February 17, 2013, 02:37:54 pm » |
Welcome!
|
|
|
|
|
Logged
|
|
|
|
|
|
|
Netherlands
Offline
Tesla Member
Karma: 90
Posts: 9407
In theory there is no difference between theory and practice, however in practice there are many...
|
 |
« Reply #9 on: February 26, 2013, 01:58:11 pm » |
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
|
|
|
|
|
Netherlands
Offline
Tesla Member
Karma: 90
Posts: 9407
In theory there is no difference between theory and practice, however in practice there are many...
|
 |
« Reply #10 on: February 26, 2013, 02:01:34 pm » |
|
|
|
|
|
Logged
|
|
|
|
|
|