NEC Infrared receiver class

Discuss development of drivers for external hardware and components, such as LCD screens, sensors, motor drivers, etc.
Target audience: Users and developers of drivers.
Post Reply
MattMatic
Posts: 13
Joined: Wed Apr 22, 2015 1:44 pm

NEC Infrared receiver class

Post by MattMatic » Mon Apr 27, 2015 1:24 pm

(Hope this is the right place THIS time :D )

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 :D

Matt

photoacoustic
Posts: 24
Joined: Mon Apr 27, 2015 8:25 am

Re: NEC Infrared receiver class

Post by photoacoustic » Mon Apr 27, 2015 2:49 pm

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

MattMatic
Posts: 13
Joined: Wed Apr 22, 2015 1:44 pm

Re: NEC Infrared receiver class

Post by MattMatic » Mon Apr 27, 2015 8:04 pm


User avatar
dhylands
Posts: 3268
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: NEC Infrared receiver class

Post by dhylands » Mon Apr 27, 2015 8:40 pm

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/

ubuntourist
Posts: 1
Joined: Fri May 08, 2015 9:08 pm

Re: NEC Infrared receiver class

Post by ubuntourist » Tue Jun 02, 2015 7:40 pm

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?

MattMatic
Posts: 13
Joined: Wed Apr 22, 2015 1:44 pm

Re: NEC Infrared receiver class

Post by MattMatic » Fri Jun 26, 2015 8:38 am

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

ajocius
Posts: 73
Joined: Mon Feb 19, 2018 6:31 am

Re: NEC Infrared receiver class

Post by ajocius » Tue Nov 19, 2019 2:31 pm

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:

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)
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.

User avatar
mcauser
Posts: 437
Joined: Mon Jun 15, 2015 8:03 am

Re: NEC Infrared receiver class

Post by mcauser » Thu Nov 21, 2019 6:59 am

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

ajocius
Posts: 73
Joined: Mon Feb 19, 2018 6:31 am

Re: NEC Infrared receiver class

Post by ajocius » Thu Nov 21, 2019 9:58 am

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?

User avatar
pythoncoder
Posts: 3910
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: NEC Infrared receiver class

Post by pythoncoder » Thu Nov 21, 2019 1:46 pm

Mine is just a receiver.

A TX is some way down my long TODO list. Please don't hold your breath waiting...
Peter Hinch

Post Reply