IR transmitter/receiver

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
ajocius
Posts: 83
Joined: Mon Feb 19, 2018 6:31 am

IR transmitter/receiver

Post by ajocius » Tue Nov 19, 2019 12:54 pm

Is it possible to read IR signal from remote (any commercial remote control unit) using ESP32 and IR receiver, then reproduce that code using ESP32 and IR transmitter? Find many examples using Arduino, but didn't come across Micropython example.

User avatar
MostlyHarmless
Posts: 166
Joined: Thu Nov 21, 2019 6:25 pm
Location: Pennsylvania, USA

Re: IR transmitter/receiver

Post by MostlyHarmless » Thu Nov 21, 2019 11:08 pm

Not saying it is impossible, but with pure Micropython it is going to be difficult to build something that resembles the function of a "Universal Remote". Recording and replaying arbitrary IR signals, that is.

The biggest problem is going to be sampling the signal from your original IR remote through something like an IR transistor at a sufficient rate.

A quick check on my OScope with a trivial loop of

Code: Select all

MPY: soft reboot
MicroPython v1.11-586-g1530fda9c on 2019-11-21; ESP32 module with ESP32
Type "help()" for more information.
>>> import machine
>>> led = machine.Pin(2, machine.Pin.OUT)
>>> while True:
...     led.on()
...     led.off()
...     
shows
ScreenImg_001.png
ScreenImg_001.png (30.38 KiB) Viewed 14849 times
So even a trivial loop like that can only run at about 38 kHz. And it isn't very consistent as the pre-trigger waveform shows.

Assuming that reading a GPIO takes about as long as it takes to toggle it and since we need more code and memory access inside that loop ... our sampling frequency will be severely limited.

Generating signals is a lot easier than analyzing them.


Regards, Jan


Edit: Uploading image to forum for permanent link
Last edited by MostlyHarmless on Mon Dec 02, 2019 12:31 am, edited 1 time in total.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: IR transmitter/receiver

Post by Roberthh » Fri Nov 22, 2019 7:25 am

Using Viper code you can toggle up to the MHz range. But using an ESP32, the RMT unit is made for interacting with Remotes. So it's the proper driver which is missing. RMT is excellent on generating and detecting pulses or carrier bursts. There is work in progress. See https://github.com/micropython/micropython/pull/5184
And both the Pycom and the loboris fork have it implemented, although only partial. Carrier bursts are not implemenetd yet.

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

Re: IR transmitter/receiver

Post by ajocius » Fri Nov 22, 2019 9:50 am

Find many solutions for Arduino, build one receiver on Arduino UNO and it works. Maybe that particular IR signal is easier to handle (think it is called NEC) ? Is there any reason that it is more difficult to implement on ESP32 with Micropython? Is it HW or SW that makes this implementation difficult?

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

Re: IR transmitter/receiver

Post by pythoncoder » Fri Nov 22, 2019 11:29 am

Receiving 38KHz IR signals really needs one of these. This demodulates the 38KHz signal providing a much slower waveform which can readily be handled in code. The chip also does a lot of noise removal.

Note that some remotes use 36KHz requiring a different chip. I think these are fairly uncommon.
Peter Hinch
Index to my micropython libraries.

OutoftheBOTS_
Posts: 847
Joined: Mon Nov 20, 2017 10:18 am

Re: IR transmitter/receiver

Post by OutoftheBOTS_ » Fri Nov 22, 2019 8:51 pm

I have used a cheap IR receiver like posted by pythoncoder with a RPi and python written code to capture all my remotes around the house see this video https://www.youtube.com/watch?v=zDErQPXtMyU&t=3s from about half way in you will see me show the different protocols of the different remotes around the house.

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

Re: IR transmitter/receiver

Post by ajocius » Tue Nov 26, 2019 1:49 pm

Saw your video, thanks. Can you please share your github adress with code? Also, did you manage to program transmitter as well?

OutoftheBOTS_
Posts: 847
Joined: Mon Nov 20, 2017 10:18 am

Re: IR transmitter/receiver

Post by OutoftheBOTS_ » Tue Nov 26, 2019 9:41 pm

Unfortunately I never saved the code to github and it was only on the RPi which later crashed. It is a pity because many others have asked for the code.

It basically went like this. I created a 2D array to hold the timing of offs and ons, then had a loop that waited for the long start bit then stored all the timing of the on's and off's that followed until there was a long break then analyzed the results. If you watch my whole video you should be able to work out what your looking for

And yes I manged to then transmit with the RPi.

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

Re: IR transmitter/receiver

Post by ajocius » Wed Nov 27, 2019 1:15 pm

way above my knowledge level :)

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

Re: IR transmitter/receiver

Post by mcauser » Tue Dec 24, 2019 9:32 am

The ESP32 specific RMT driver has now been merged and is in v1.12.
So far it’s TX only, and more features will be added soon.

I’ve got this little 5V UART IR TX+RX module working with ESP32.
https://github.com/mcauser/micropython-ys-irtm
It can listen, capture and replay with a few lines of code.

Post Reply