Page 1 of 4

IR transmitter/receiver

Posted: Tue Nov 19, 2019 12:54 pm
by ajocius
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.

Re: IR transmitter/receiver

Posted: Thu Nov 21, 2019 11:08 pm
by MostlyHarmless
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 15069 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

Re: IR transmitter/receiver

Posted: Fri Nov 22, 2019 7:25 am
by Roberthh
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.

Re: IR transmitter/receiver

Posted: Fri Nov 22, 2019 9:50 am
by ajocius
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?

Re: IR transmitter/receiver

Posted: Fri Nov 22, 2019 11:29 am
by pythoncoder
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.

Re: IR transmitter/receiver

Posted: Fri Nov 22, 2019 8:51 pm
by OutoftheBOTS_
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.

Re: IR transmitter/receiver

Posted: Tue Nov 26, 2019 1:49 pm
by ajocius
Saw your video, thanks. Can you please share your github adress with code? Also, did you manage to program transmitter as well?

Re: IR transmitter/receiver

Posted: Tue Nov 26, 2019 9:41 pm
by OutoftheBOTS_
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.

Re: IR transmitter/receiver

Posted: Wed Nov 27, 2019 1:15 pm
by ajocius
way above my knowledge level :)

Re: IR transmitter/receiver

Posted: Tue Dec 24, 2019 9:32 am
by mcauser
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.