NEC Infrared receiver class
NEC Infrared receiver class
(Hope this is the right place THIS time )
Just threw together a little library in about an hour that will let you capture infrared remote values according to the NEC protocol.
(The type available on eBay under "Arduino infrared remote")
https://github.com/MattMatic/micropython-necir
(NOTE: You may need to use a 10k pull-up resistor for the TL1838, otherwise you can get spurious triggers if just relying on the pyboard pull-up)
Essentially does a capture timer of the high-pulses (no-IR) and handles the bitstream. When a completed 32 bits have been received, and they all tally (Address + NOT Address + Command + NOT Command) then it issues the callback function.
Enjoying the speed of Python development
Matt
Just threw together a little library in about an hour that will let you capture infrared remote values according to the NEC protocol.
(The type available on eBay under "Arduino infrared remote")
https://github.com/MattMatic/micropython-necir
(NOTE: You may need to use a 10k pull-up resistor for the TL1838, otherwise you can get spurious triggers if just relying on the pyboard pull-up)
Essentially does a capture timer of the high-pulses (no-IR) and handles the bitstream. When a completed 32 bits have been received, and they all tally (Address + NOT Address + Command + NOT Command) then it issues the callback function.
Enjoying the speed of Python development
Matt
-
- Posts: 24
- Joined: Mon Apr 27, 2015 8:25 am
Re: NEC Infrared receiver class
Thank for this code.
this code will help me for understanding Timer with input capture!
I have a phototransistor for DC motor speed measurement
best regards
this code will help me for understanding Timer with input capture!
I have a phototransistor for DC motor speed measurement
best regards
Re: NEC Infrared receiver class
You will find the following pages helpful (I used these as a source):
http://wiki.micropython.org/platforms/b ... r-Examples
https://github.com/micropython/micropyt ... pture-mode
https://micropython.org/doc/module/pyb/Timer
Have fun!
http://wiki.micropython.org/platforms/b ... r-Examples
https://github.com/micropython/micropyt ... pture-mode
https://micropython.org/doc/module/pyb/Timer
Have fun!
Re: NEC Infrared receiver class
I'm also coding up some Tachometer code in the next few days.
I'm going to port some code I wrote for an ATTIny45:
http://davehylands.com/Electronics/Tachometer/
I'm going to port some code I wrote for an ATTIny45:
http://davehylands.com/Electronics/Tachometer/
-
- Posts: 1
- Joined: Fri May 08, 2015 9:08 pm
Re: NEC Infrared receiver class
I'm all-thumbs with analog electronics.
I'm looking at two IR receivers. Bricks? The brands are Keys one is Xlnda but they look identical. One has a constantly flickering red LED on the board and the other has a solid red LED. (I think the solid red one is broken from an incorrect connection when first plugged in. A colleague said he "heard and smelled" it. But he seems to feel that "solid red" is better than "flickering red".)
To test both, we've got a remote for an overhead SmartBoard projector, which definitely works. However, we cannot get either receiver to detect anything. (I've downloaded the library listed in the thread and run the example code, connecting signal to X4 on the PyBoard. All I see is a constantly repeating "0 0 True".) I added in the 10K pull-up resistor (between "S" on the brick and X4 on the PyBoard, yes?) but that didn't appear to change anything.
Suggestions?
I'm looking at two IR receivers. Bricks? The brands are Keys one is Xlnda but they look identical. One has a constantly flickering red LED on the board and the other has a solid red LED. (I think the solid red one is broken from an incorrect connection when first plugged in. A colleague said he "heard and smelled" it. But he seems to feel that "solid red" is better than "flickering red".)
To test both, we've got a remote for an overhead SmartBoard projector, which definitely works. However, we cannot get either receiver to detect anything. (I've downloaded the library listed in the thread and run the example code, connecting signal to X4 on the PyBoard. All I see is a constantly repeating "0 0 True".) I added in the 10K pull-up resistor (between "S" on the brick and X4 on the PyBoard, yes?) but that didn't appear to change anything.
Suggestions?
Re: NEC Infrared receiver class
There are many protocols for IR transmitters.
I only implemented the NEC format.
An output of 0,0,true indicates zero address, zero command, and a repeat.
It's likely your remotes are not NEC format - the repeat signal in NEC format is simply an IR pulse. The command and data, on the other hand, are verified since the frame contains both the 8-bit binary of each and the 8-bit inverse of each.
So, it's possible to get 'repeat' triggers from other brand remotes or false positives.
You'd need to get a storage scope out to see what the protocol is. This page might help: http://www.sbprojects.com/projects/ircontrol/index.php
Matt
I only implemented the NEC format.
An output of 0,0,true indicates zero address, zero command, and a repeat.
It's likely your remotes are not NEC format - the repeat signal in NEC format is simply an IR pulse. The command and data, on the other hand, are verified since the frame contains both the 8-bit binary of each and the 8-bit inverse of each.
So, it's possible to get 'repeat' triggers from other brand remotes or false positives.
You'd need to get a storage scope out to see what the protocol is. This page might help: http://www.sbprojects.com/projects/ircontrol/index.php
Matt
Re: NEC Infrared receiver class
Is this possible to read signal from remote controls laying around at home using your code MattMatic? I would like to read signal from AV receiver remote control, then use it with IR transmitter connected to ESP32 to automate AV receiver, so that I can for example turn on AV receiver using voice command or some other trigger. I have looked into github but was not sure how to implement it. Should I copy necir.py code into ESP32 and then address it from main.py using:
I am not sure how will ESP32 know what PIN has IR receiver or transmitter connected. Do you have some working code example that I could follow? Too many questions, but I can't figure out how it works.
Code: Select all
def nec_cb(nec, a, c, r)
print(a, c, r) # Address, Command, Repeat
from necir import NecIr
nec = NecIr()
nec.callback(nec_cb)
Re: NEC Infrared receiver class
Not every remote uses the NEC protocol. There's a bunch of different protocols. If you know the model number of your AV devices, there's a few sites which list 1000s of the IR devices, which protocols they use and what each button sends. Otherwise, there's some scripts which let you capture what each button sends.
There's stacks of sites like this:
* http://irdb.tk/api
* http://lirc-remotes.sourceforge.net/remotes-table.html
It's definitely possible to have an ESP32 with an IR LED pointed towards your AV receiver and have it blink out the appropriate commands.
If you have an IR receiver on your ESP32, you could use it to relay commands, or just accept web traffic / mqtt to issue commands.
MattMatic's driver is specific to the Pyboard, as it uses pyb.Timer. There is an ESP32 equivalent. Will need some refactoring.
Have you seen Peter Hinch's driver? It's working on the ESP32 and uses asyncio.
https://github.com/peterhinch/micropyth ... ter/nec_ir
There's stacks of sites like this:
* http://irdb.tk/api
* http://lirc-remotes.sourceforge.net/remotes-table.html
It's definitely possible to have an ESP32 with an IR LED pointed towards your AV receiver and have it blink out the appropriate commands.
If you have an IR receiver on your ESP32, you could use it to relay commands, or just accept web traffic / mqtt to issue commands.
MattMatic's driver is specific to the Pyboard, as it uses pyb.Timer. There is an ESP32 equivalent. Will need some refactoring.
Have you seen Peter Hinch's driver? It's working on the ESP32 and uses asyncio.
https://github.com/peterhinch/micropyth ... ter/nec_ir
Re: NEC Infrared receiver class
Haven't tried, thanks for sending link, will test out! Do you know if this also sends IR signal out? Or is it just receiver?
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: NEC Infrared receiver class
Mine is just a receiver.
A TX is some way down my long TODO list. Please don't hold your breath waiting...
A TX is some way down my long TODO list. Please don't hold your breath waiting...
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.