Wednesday, January 28, 2009

TSL230R to Arduino interface

This may appear to be somewhat of a non sequitur, but here we go.

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.

This tutorial has been moved to the TeamPaulC Arduino page.

9 comments:

  1. as a side note.....
    I changed lines 37 and 38 to

    digitalWrite(TSL_S0, LOW); // 10x sensitivity
    digitalWrite(TSL_S1, HIGH);

    this sets the sensitivity to 10x, which is much better suited to the light conditions at my desk. :)

    ReplyDelete
  2. Paul - great job! Always love to see great new ways of doing things! I hadn't really considered using the interrupt handler its self to do the frequency calculation - that's certainly very useful, especially to reduce the amount of code in the main loop, and reduce the chance for error. It's fun to watch as people add new capabilities and make a solution even more elegant. Keep up the good work!

    There is a thing to keep in mind though -- this may greatly reduce the resolution for bright conditions. The if/else chain takes longer than a few uSec to complete - if its still in the handler, it can't trigger it again, and some pulses will be lost at high frequencies. How does it perform in very bright conditions?

    If you're using Arduino 012, you can get rid of a bunch of the code by simply doing :

    if( millis() - pre_tm >= READ_TM ) { pre_tm = millis(); ... }

    012 uses full 32-bit unsigned int, so the unsigned int math magic takes care of rollover for you, shaving off lots of time and two unsigned ints. (I was still using 011 when I wrote that tutorial.)

    !c

    ReplyDelete
  3. Thanks for the pointers!
    I was going over that code earlier and I have a new version, but its acting a bit flaky so I haven't posted it yet. I was wondering about the roll over for 11, and I am using 12, so I will make that change for sure.

    I am pretty new to the Arduino (but not new to coding) so I am just figuring it all out. :) I am not used to a (relatively) slow CPU where clock cycles are so precious, so I will go over the code with that in mind. :)

    hmm, I guess that I could just do the counting in the interrupt, but then calculate the frequency and uW/cm when I need it. Kind of a "meet in the middle" solution.

    Anyway, thanks again for the blog post with the code to get me started!
    :D

    ReplyDelete
  4. Okay. I clicked the link and briefly read, so now I know what an Arduino is. Now I'm intrigued and I want to know what you're doing with it.

    ReplyDelete
  5. just hacking around.
    I almost have the TSL230R working, I got a maxbotic sonar working, in fact two daisy chained together an EZ0 and an EZ3, I got a phototransistor working, a PIR and a photocell.
    Why?
    {shrug}
    Never stop learning.

    Arduino 13 is coming out soon (SVN available now!) so I will upgrade to that so that I can properly format floats in Serial.print.

    I will probably order up a Really Bare Bones Board - Freediuno (http://www.moderndevice.com/RBBB_revB.shtml) to play with, and I have been eyeing the sparkfun mux/demux breakout board http://www.sparkfun.com/commerce/product_info.php?products_id=9056.

    When I DO decide to build something (and I will) then I will almost certainly buy SOMETHING from liquidware, http://www.liquidware.com/
    they have some great stuff.

    More about arduino can be found at my del.icio.us bookmarks at
    http://delicious.com/kirwoodd/arduino

    ReplyDelete
  6. well,
    I have a new version of the code that makes the interrupt handler MUCH smaller, email me if you would like it.

    While the TLS230R is indeed very accurate, it is also very CPU intensive. And by "very" I mean compare it to reading a voltage across a phototransitor. Thats a one shot "read the voltage" and bam, there it is.

    However, if you need the accuracy (like c.a. church does for photography) then the TSL230R is a great choice. But if you just want to say "it got brighter" or "its darker here than it is over there" then I suggest a phototransistor.

    ReplyDelete
  7. PaulC, could I get your newer code sample. I'm working on building a laser harp. I'm using the tsl230r chip to measure the reflection of the laser. Thanks for the great work.

    ReplyDelete
  8. @Edward
    I updated the article with the latest code.
    When you are done with your harp please let us know how you did it.

    The only laser harp based on arduino that I have seen is from stephan hobley (http://www.stephenhobley.com/build/)
    It seems a bit too complex, although it is SUPER cool. :) Its just too big a project for me. :|

    Are you thinking of using a single TSL230R, or multiple? When I saw the laser harp I thought that it would be much easier to point 6 laser pointers at 6 phototransistors connected to the 6 analog in pins on the arduino. Then sample the 6 inputs in the loop (no interrupt) and send out MIDI based on the laser that was plucked. Then you could give up one laser and use a maxbotix (http://www.maxbotix.com/) sensor to do bitch bend on the midi as you move your hand up and down.
    stephen is using a sensor to measure reflected laser light to use as a midi modifier, that would be cool as well.


    It sounds like

    ReplyDelete
  9. Hi,

    This is Shanu. I have a problem that I need your help with. I am a student of bio-medical engineering and presently working on development of a sensor for bilirubin measurement (or so-called Jaundice).
    There are 3 LED sources that I am beaming on the solution.

    On the other side, I plan to have a TSL230R chip to capture the intensity and convert it to frequency. This will take place one by one for all 3 LED's.

    Next I plan to interface TSL230R with Arduino so that I can transfer my frequency values to intensity and then perform the required calculations. Finally, I display the output.

    Could you suggest whether I am proceeding in the correct direction with arrangement of my circuit? Is there an alternative possible?

    ReplyDelete