peterhinch / micropython_ir

Nonblocking device drivers to receive from IR remotes and for IR "blaster" apps.
MIT License
240 stars 51 forks source link

Using polling on ESP8266? #11

Open andrigamerita opened 2 years ago

andrigamerita commented 2 years ago

Hello, I am trying to do some RX tests with this library on my ESP8266 (NodeMCUv3 clone), but I'm having some issues regarding pin interrupts, apparently not only with this library but in general, and I've already disabled WiFi entirely. Something that makes what I'm doing even harder is that I'm not actually using an IR receiver module, but an hacked remote control with a wire soldered onto, instead of the IR LED, I searched online and apparently no one ever tried to do something like this (which is strange, an old remote made into wired seems a good idea to me for an inexpensive keypad with many buttons when you only have a couple of usable GPIO pins), so unknown problems surely occur...

Is it possible to use this library in a classic polling loop? Even just for doing tests, I will be okay with this, I don't actually know how well it would work in real programs but still, better than nothing, for now at least. Something along the lines of: in a loop, the Pin.value() is constantly being monitored every millisecond or so, if a value change is detected, then a function from this lib is called, lasting however many ms the IR signal would last, and the encoded command properly read.

Thanks to anyone helping me out!

peterhinch commented 2 years ago

The receiver chip is a lot more sophisticated than an IR LED. For a start it demodulates the ~38KHz carrier and also does a lot of noise reduction. I wouldn't attempt to do that in code on an ESP8266 - or on any chip: decoders are cheap.

Also be aware that the interrupt latency on ESP8266 and ESP32 is poor as only soft IRQ's are supported. If an interrupt coincides with a GC operation the response can be delayed by multiple ms.