Irq flags #13137
Replies: 3 comments 5 replies
-
How is the LDR connected? I'd normally think of them as an analog signal that you'd need to read with an ADC or comparator? If the analog signal is wired direct to pin digital input I'd very much expect it to "bounce" a lot as it crosses the low to high threshold and vice versa, triggering multiple interrupt signals. That being said if it's fast moving enough you could still treat it like a pushbutton which typically has a similar bounce issue. There's some great examples of debouncing switch inputs with asyncio here that might work for you: https://github.com/peterhinch/micropython-async/blob/master/aswitch.py |
Beta Was this translation helpful? Give feedback.
-
Interrupts are the most misunderstood feature of MicroPython. They should be reserved for applications where very fast responses are required. Further, unless the signal causing the interrupt has fast edges (<1μs), behaviour of the host silicon is indeterminate. For slowly changing sources a hardware Schmitt trigger should be used. It is usually simpler to poll the input using a task in |
Beta Was this translation helpful? Give feedback.
-
thanks for all input. I decided to go back to basics and just read pin values in a loop with delay. I also removed transistor so now have a simple voltage divider with LDR tied to 3.3 and through a pot and other resistors down to gnd. Mid point to gpio via 330R. I have tested this simple circuit with a 60K resistor in place of LDR ON and 1M to replicate LDR off and all works as expected?? Any ideas |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi. I’m trying to write a very simply python script to monitor a GPIO input from an LDR that detects light.
My program is working using debounce in the callback function but I am very confused by the irq flags fucnction. There are lots of interrupts caused by the hardware implementation I guess, but the values of the flags() function is very odd. I understand that the register sets decimal 4 as falling edge and rising edge as 8. Also the documentation says the flags are reset to 0 after callback function has completed.
I am seeing a flags() result of 12 ( I assume this is BOTH rising and falling edge? Also the flags returns 12 in the main program AFTER leaving the callback function. Does anyone know why?
I would like to use the status from flags() of rising or falling edge in my program but with these results cannot do so.
Beta Was this translation helpful? Give feedback.
All reactions