Spin demo code for the TSL235?
Hey everyone, I'm evaluation some different color sensors and I would like to try a TSL235 (?R?), but I haven't been able to find any Spin code for it. http://www.parallax.com/product/604-00084 There is an example for using an Arduino from Parallax, but nothing for the Propeller chip. I think the world is upside down....
http://learn.parallax.com/tsl235r-light-frequency-converter-arduino-demo
I've also checked the Obex and no luck, does anyone have a simple demo that they would be willing to share?
Thanks for your time,
Dave
http://learn.parallax.com/tsl235r-light-frequency-converter-arduino-demo
I've also checked the Obex and no luck, does anyone have a simple demo that they would be willing to share?
Thanks for your time,
Dave
Comments
Hey JonnyMac,
Thanks for asking.
The goal is to find the best method and sensor(s) for detecting (individually) red, green, blue, IR, & UV light reflected from an object about 2-3 inches away.
I've currently been testing a number of different sensors (photo-resistors, photo-resistor diodes, TSL235, etc.) In the end I'll create an array of 5-12 covering an area about 8 inches wide. The refresh rate will need to be at least 10 hz. I had been planning on dedicating a cog for this job.
BTW I always enjoy reading your articles in N&V.
Dave
var long oldcount long temp long avg long freq long loopcount pub main | t setup t := cnt repeat waitcnt(t += (10 * MS_001)) temp := phsa ' capture current count freq := temp - oldcount avg := avg + freq if (++loopcount == 25) term.tx(CR) term.dec(avg / 25) term.tx(CLREOL) avg := 0 loopcount := 0 oldcount := temp pub setup '' Setup IO and objects for application term.start(RX1, TX1, %0000, 115_200) ' start serial for terminal ctra := (%01010 << 26) | TSL ' setup pin to count positive edges frqa := 1 ' for testing only -- remove this line when sensor is connected synth.synth("B", TSL, 300_000)
The key to my code is using a counter in POSEDGE mode -- this mimics the edge-triggered interrupt of the Arduino. You can easily drop this code into a Spin cog to provide a count/period to your foreground application.
var long cycles pub main | t setup t := cnt repeat waitcnt(t += (10 * MS_001)) term.tx(HOME) term.dec(cycles) term.tx(CLREOL) pub setup '' Setup IO and objects for application term.start(RX1, TX1, %0000, 115_200) ' start serial for terminal cognew(run_tsl235(TSL, @cycles, 100), @tslstack) ' start TLS monitor cog ' for testing only -- remove this line when sensor is connected synth.synth("B", TSL, 300_000) con { ----------------------------- } { T S L 2 3 5 M O N I T O R } { ----------------------------- } var long tslstack[32] pri run_tsl235(pin, p_result, ms) | new, old, t '' Monitor TSL235 '' -- updates long at p_result every ms milliseconds ms *= clkfreq / 1000 ' convert ms to ticks new := 0 old := 0 ctra := (%01010 << 26) | pin ' setup pin to count positive edges frqa := 1 phsa := 0 t := cnt ' sync with system timer repeat ' loop forever waitcnt(t += ms) ' wait ms milliseconds new := phsa ' capture current count long[p_result] := new - old ' report count to foreground old := new ' save for next cycle