IR transmitter/receiver

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: IR transmitter/receiver

Post by pythoncoder » Wed Mar 25, 2020 6:37 am

I'm baffled by this post. The MicroPython source tree has no pigpio.h. Please could you explain exactly what this post is about?

My IR library can be found here and it contains no such file (being entirely Python code).
Peter Hinch
Index to my micropython libraries.

JonRob
Posts: 6
Joined: Sat Mar 14, 2020 6:26 am

Re: IR transmitter/receiver

Post by JonRob » Mon Jun 01, 2020 6:35 am

First time posting! I was looking at the IR python repo posted above. I am curious how the 38khz carrier is being accomplished on the esp32? I just made it work after hours of poking and my solution was differents. What I did was find the esp32_rmt.c file and change the values for tx config, and bingo!

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

Re: IR transmitter/receiver

Post by pythoncoder » Mon Jun 01, 2020 8:00 am

It is explained in the docs.
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_ » Mon Jun 01, 2020 12:16 pm

JonRob wrote:
Mon Jun 01, 2020 6:35 am
First time posting! I was looking at the IR python repo posted above. I am curious how the 38khz carrier is being accomplished on the esp32? I just made it work after hours of poking and my solution was differents. What I did was find the esp32_rmt.c file and change the values for tx config, and bingo!
Technically the RMT peripheral of the ESP32 is designed to create single pulse trains just like the IR transmitter needs.

JonRob
Posts: 6
Joined: Sat Mar 14, 2020 6:26 am

Re: IR transmitter/receiver

Post by JonRob » Mon Jun 01, 2020 3:58 pm

pythoncoder wrote:
Mon Jun 01, 2020 8:00 am
It is explained in the docs.
Oh, I see, using PWM on another pin and wiring them together in the circuit to make the carrier, Brilliant!
How hard would it be to add a couple arguments to the esp32.RMT() call to set the values? Hard coding works for my needs but I am like a cat, curious about how. Is there a readme that has any clues?

maybe add something here to 'allowed_args[] = ' in ports/esp32/esp32_rmt.c
and use them in the config setup below?

Code: Select all

STATIC mp_obj_t esp32_rmt_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
    static const mp_arg_t allowed_args[] = {
        { MP_QSTR_id,        MP_ARG_REQUIRED | MP_ARG_INT, {.u_int = -1} },
        { MP_QSTR_pin,       MP_ARG_REQUIRED | MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
        { MP_QSTR_clock_div,                   MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 8} }, // 100ns resolution
    };
    
    .
    .
    .
    rmt_config_t config;
    config.rmt_mode = RMT_MODE_TX;
    config.channel = (rmt_channel_t)self->channel_id;
    config.gpio_num = self->pin;
    config.mem_block_num = 1;
    config.tx_config.loop_en = 0;

    config.tx_config.carrier_en = true;  <---  extend this variable
    config.tx_config.idle_output_en = 1;  
    config.tx_config.idle_level = 0;
    config.tx_config.carrier_duty_percent = 50;   <----- and this
    config.tx_config.carrier_freq_hz = 38000;  <---------and this
    config.tx_config.carrier_level = 1;
    

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

Re: IR transmitter/receiver

Post by pythoncoder » Tue Jun 02, 2020 4:58 am

I haven't studied the C code. The hardware supports modulation and support in the Python API would be great. I'm sure a tested PR would be welcomed by the maintainers.
Peter Hinch
Index to my micropython libraries.

JonRob
Posts: 6
Joined: Sat Mar 14, 2020 6:26 am

Re: IR transmitter/receiver

Post by JonRob » Tue Jun 09, 2020 2:19 am

pythoncoder wrote:
Tue Jun 02, 2020 4:58 am
I haven't studied the C code. The hardware supports modulation and support in the Python API would be great. I'm sure a tested PR would be welcomed by the maintainers.
Here it is! First pull request also. https://github.com/micropython/micropython/pull/6127/ Tests on the scope passed.

jadro
Posts: 25
Joined: Wed Apr 29, 2020 7:02 pm

Re: IR transmitter/receiver

Post by jadro » Sun Feb 14, 2021 5:06 pm

Hi,

I read this post because I like to do transceiver for my Air conditioner, it is an older model of Samsung and I read all documentation about this Air conditioner but can't find any info about protocol it used... If anyone knows or deal with SAMSUNG, please let e know the PROTOCOL, or is not necessary to know this? Does the code you provide support all protocols? I am not yet able to connect all the elements so I ask and collect information ...

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

Re: IR transmitter/receiver

Post by MostlyHarmless » Sun Jul 11, 2021 2:47 am

jadro wrote:
Sun Feb 14, 2021 5:06 pm
I read this post because I like to do transceiver for my Air conditioner, it is an older model of Samsung and I read all documentation about this Air conditioner but can't find any info about protocol it used... If anyone knows or deal with SAMSUNG, please let e know the PROTOCOL, or is not necessary to know this? Does the code you provide support all protocols? I am not yet able to connect all the elements so I ask and collect information ...
Sorry to have been absent from the forum for (way too) long. Getting back into things, so checking my posts.

jadro, after doing a little bit in this direction I slowed down my efforts on the hardware side and tried to understand the protocol side of things. Let me tell you that IR protocols are a complete MESS. Yes, in capital letters. For getting a glimpse of how bad things are, check out this: http://www.hifi-remote.com/johnsfine/DecodeIR.html

Yeah, I was scratching my head about it too for a while, but after you read it for the 4th or 5th time, it starts sinking in.

What I did then was getting a BroadLink RM Mini3 and connected it to NodeRed. NodeRed has a function to "record" the buttons from an existing remote and then get the raw data in a JSON file inside the NodeRed data directory. I then proceeded to write Python scripts that can use those IRP protocol specifications together with that raw data to try and parse the raw data into anything meaningful. That way I would figure out what protocol a specific remote was sending (like Sony12 or Sony15). When you look at the IRP definition for Sony12 below, you see "F:7,D:5" and for Sony15 you see "F:7,D:8" in those strings. Those are actually the number of bits transmitted for the Function and Ddevice. All the other fluff around it defines the carrier frequency, what type of start sequence is sent, what on/off durations mean a 0 or a 1 and so on. Obviously Sony12 uses a total of 12 bits to address the device and function (7 + 5).

I am at the point where I can generate the actual IR codes for the RMmini from the resulting config file. This is the start of that file:

Code: Select all

{
  "IRP": {
    "Sony12": "{40k,600}<1,-1|2,-1>(4,-1,F:7,D:5,^45m)+",
    "Sony15": "{40k,600}<1,-1|2,-1>(4,-1,F:7,D:8,^45m)+",
    "Sony20": "{40k,600}<1,-1|2,-1>(4,-1,F:7,D:5,S:8,^45m)+",
    "G.I. Cable": "{38.7k,490}<1,-4.5|1,-9>(18,-9,F:8,D:4,C:4,1,-84,(18,-4.5,1,-178)*) {C = -(D + F:4 + F:4:4)}"
  },
  "Functions": {
    "TV_PWRON": ["Sony12", 1, -1, 46, [3]],
    "TV_PWROFF": ["Sony12", 1, -1, 47, [3]],

    "AMP_PWRON": ["Sony15", 48, -1, 46, [3]],
    "AMP_PWROFF": ["Sony15", 48, -1, 47, [3]],
    "AMP_PWR": ["Sony15", 48, -1, 21, [3]],
    "AMP_MUTE": ["Sony15", 48, -1, 20, [3]],
    "AMP_VOL_DOWN": ["Sony15", 48, -1, 19, [3]],
    "AMP_VOL_UP": ["Sony15", 48, -1, 18, [3]],
    "AMP_SLEEP": ["Sony15", 48, -1, 96, [3]],

    "AMP_INPUT_BD": ["Sony20", 16, 40, 22, [3]],
    "AMP_INPUT_DVD": ["Sony15", 48, -1, 125, [3]],
    "AMP_INPUT_CATV": ["Sony15", 176, -1, 3, [3]],
    "AMP_INPUT_TV": ["Sony15", 48, -1, 106, [3]],
    "AMP_INPUT_VIDEO": ["Sony15", 48, -1, 34, [3]],
    "AMP_INPUT_CD": ["Sony15", 48, -1, 37, [3]],
    "AMP_INPUT_DMPORT": ["Sony20", 16, 40, 48, [3]],

    "DVR_0": ["G.I. Cable", 0, -1, 0, [1]],
    "DVR_1": ["G.I. Cable", 0, -1, 1, [1]],
Yes, that is 4 different protocols for just 3 devices (TV, Sound and DVR). Don't ask me how Sony managed to have one Surround Sound System use two different IR encodings.

Anyhow, if there is interest in this I can share my codec scripts via github.


Regards, Jan

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

Re: IR transmitter/receiver

Post by MostlyHarmless » Sun Jul 11, 2021 3:04 am

On a side note, by try and error I found that a lot of devices have IR functions, that are not available from their original remotes. Like dedicated power on/off signals, where the remote can only send the power toggle signal.

This means that if you can only use a remote "learn & repeat" system in order to teach a generic remote, you can never teach it those special codes. By going through the process of analyzing the protocol and then synthesizing it again, one can do the try and error and find codes, the remote doesn't support.

For home automation you most definitely want to know the codes for ON and OFF, not the one for TOGGLE.

Post Reply