TSL230R to Arduino interface

Last edited 02/08/2009

This was originally posted on the TeamPaulC blog, that blog entry will not be updated, but this page will be updated as required.

Thank you c.a. church for the great tutorial no how to get the TSL230R to interface with the Arduino.
He did a great job showing how to interface and calculate the
frequency. However, his approach required both an interrupt AND a
separate poll of the results every second to calculate the frequency.

His
approach is absolutely fine, but I would prefer to setup the interrupt
and have it also do the frequency calculation every period of time and
put the results into a volatile
variable. That way I can start the interrupt, never worry about it
again, and just read the frequency whenever I need it. To that end,
find below a new version of his code, slightly rearranged and with a
few new variables and output to the serial monitor for debugging.

oh, also.If you are not going to use the light sensor, you can always callnoInterrupts()andinterrupts()to
turn them off and back on. Just remember that the first time that freq
is calculated after a call to interrupts() it will be bogus!

void loop() { // this is just for debugging // it shows that you can sample freq whenever you need it // even though it is calculated once a second // I am dislplaying it every 2 seconds // note that the first time that freq is calculated, it is bogus count++; Serial.print(count); Serial.print("\tuW/cm: "); Serial.print(getUwattCm2(), DEC); Serial.print("\tfrequency: "); Serial.println(frequency, DEC); setSensitivity(); delay(1000);}

long getUwattCm2() { // copy pulse counter and multiply. // the multiplication is necessary for the current // frequency scaling level.

frequency = curPulseCount * scale;

// get uW observed - assume 640nm wavelength // calc_sensitivity is our divide-by to map to a given signal strength // for a given sensitivity (each level of greater sensitivity reduces the signal // (uW) by a factor of 10)