The Netduino forums have been replaced by new forums at community.wildernesslabs.co.
This site has been preserved for archival purposes only
and the ability to make new accounts or posts has been turned off.
In my program.cs, I can drop a breakpoint at the event that is fired when the interrupt occurs, and after the first time the sensor interrupt occurs, the event is fired "forever", it does not ever stop.
After the event fires, I am logging the datetime ticks that the event happened, but then I do not want the event to fire again.
What is the proper programming pattern to accept the interrupt/event one time?
Hi Chuckles,
Which interrupt edge setting are you using in your constructor?
Also...you can .DisableInterrupts in your event handler, to prevent them from continuing to be called after the first event handler. You may also need to set some sort of flag, in case there are already events queued up.
Chris
Chris, thanks for taking a look at this. I am putting in a big chunk of the program in the hopes that you can help me think though the right way to do eventing. This is code for a model car race track; a switch is closed and a race starts, when a car passes over a light sensor the time is logged, and if nothing happens in 10 seconds then the time is logged anyway and then a new race heat can begin.
Also, the Micro Framework appears to throw and Exception if a property is assigned to an Interrupt port more than once (a tactic I tried in order to "reset" the hardware). Is that as-designed behavior?
In my program.cs, I can drop a breakpoint at the event that is fired when the interrupt occurs, and after the first time the sensor interrupt occurs, the event is fired "forever", it does not ever stop.
I think the photo-resistor circuit is not really suitable for this scenario: at first, it has [relatively] long response time, which is not good for time measurement, and secondly, with resistance of ~10 k? and another 10 k? resistor you have voltage divider that produces voltage in the area of undefined logic levels - i.e. 0.5*VDD, while typical thresholds are <0.3*VDD for logic 0 and >0.7*VDD for logic 1; this can cause the input to oscillate or have 'strange' behavior.
I would recommend you to first determine behavior of the photo-resistor under conditions of your system. This means connecting it to an analog input and dump voltage readings while passing the car, varying ambient light etc. From that you should be able to determine voltage threshold that corresponds to detection of car passing. Then you can calculate the value of resistor needed to construct voltage divider for digital input (interrupt). I would also consider adding a Schmitt trigger logic gate to the input to ensure proper handling of slow edges.
Personally, I would use a photo-transistor instead, it is easier to use and it will work much better.
Also, the Micro Framework appears to throw and Exception if a property is assigned to an Interrupt port more than once (a tactic I tried in order to "reset" the hardware). Is that as-designed behavior?
Yes, this is by design. You have to Dispose() the port before it can be instantiated again.
Personally, I would use a photo-transistor instead, it is easier to use and it will work much better.
Thanks for the detailed response. I have re-evaluated what I am trying to do... And now am shopping for "photo transistors". My typical part suppliers have been Adafruit and Sparkfun, neither of which appears to carry what you are talking about. Do you have a vendor recommendation?
Be warned Mouser loves hobbyists. Digi-Key doesn't mind them. And Jameco is still trying to figure them out. In the case of Jameco, should you decide to buy something from them, be prepared to buy a lot of items you might need. Even if that need is months to years later.
The closest thing at SparkFun is Infrared Emitters and Detectors, but it is expensive and has very limited range (you can salvage such pair from an optical mouse). There are many manufacturers that make photo-transistors, you should be able to get them at your local electronics store.
As always, the selection depends... I am not exactly sure how you plan to construct the optical detection system, personally I would go for LED and matching photo-transistor - 'matching' means selecting one that is sensitive to LED's light (obviously). If you can place photo-transistor at location, where it has no or little ambient light that could affect it, you can select parts that work for visible light (red, green, etc.). Otherwise, it is better to use infra-red LED and infra-red photo-transistor, which is more immune to ambient [visible] light changes, of course except direct sunlight, which contains intensive infra-red light - usually, modulation is used to compensate for sunlight disturbances, exactly the same way as in TV remote controls (the LED is driven by ~40 kHz PWM signal ("modulation"), and there is a demodulator connected after photo-detector).
Incidentally, I made a prototype of lap timer circuit for slot car (Carrera Go) long time ago, I placed IR photo-transistor and IR LED around the slot at the bottom of the plastic track part (required a little bit of drilling on the sides of the slot), so the light from LED was interrupted by car's guide pin. I used SFH309-5 photo-transistor and (I think) L-934F3C IR LED; 3 mm diameter due to space constraints, I got them at local electronic store (GME, here in Czech Republic). I did not need to use modulation, because there was virtually no way for sunlight to disturb the IR light beam from LED to the photo-transistor.
Additional tips for IR part selection:
There are two almost standard IR wavelengths: ~880 nm and ~940 nm. IR LEDs are made to have peak emission at that wavelength, relatively narrow (see Relative Spectral Emission vs. wavelength chart in the device datasheet). IR photo-transistors can be tuned to have max sensitivity at that wavelength too, but usually it is better to get a more generic one - e.g. SFH309-5 has about >80% sensitivity for whole 700 - 1000 nm range, peak at 900 ± 50 nm (see Relative Spectral Sensitivity vs. wavelength chart in the datasheet). So it will work well enough for basically any IR LED.
For optical detectors, LEDs with narrow beam are better - choose one with smaller 'angle' (also listed as 'Half Ange', ? etc.). Usually around 20°. However, there will be little difference at small distances.
There are two IR LED power classes: "normal" and "power" - for small distances "normal" is enough (IF = ~10..20 mA), power LEDs (TV remotes, long distance sensing) can require >100 mA drive current (i.e. cannot be driven directly from a microcontroller pin, an additional transistor is needed).
Alternatively, there are reflective sensors, such as QRE1113, which could be mounted for example on the track and it could detect a passing car that has small mirror (reflective tape) attached at the bottom. This particular sensor has detection distance only about 1 mm, which is probably not enough to reach the car, but you get the idea...
For this kind of derby race, cars run on top of wood guides. My plan was to drill small holes in a section of the track (image shows pink dots where holes could go), place the sensors there, and detect the shadow of the car as it passes over the holes. The crowd watching the race does not have an obscured view of the finish line. Cars have strict requirements about weight and dimensions and add-ons, so they cannot have anything added to them like reflective tape.There is approximately 3mm between the bottom of the car and the wood guide, so my plan was to drill small holes in each slot, embed the sensor in the hole, and run wiring though the hole and under the bottom of the track.
I thought that a light sensor would fit these requirements the best, detect when a shadow is cast over a sensor and mark the time.
As you can see, I am now having trouble with the detection part....
If I went with https://www.sparkfun.com/products/246 , what other hardware would I need to go with it? The video at seems to indicate it can accurately/quickly detect the difference between light and shadow.
Is that true? The track is running indoors in a US school gymnasium (lights are fluorescent and 15+ meters in the air) so I think there should be no IR interference.
All comments welcomed, I don't want to buy the wrong sensors twice!
Yes, in principle they are the same. QRD1114 contains IR photo-transistor and LED. It is designed for reflective sensing, it has peak sensing distance about 25 mils (around 0.5 cm). It is possible to take out IR photo-transistor and LED from the sensor casing (at least in the batch I have, your mileage may wary).