pbendersky / ir-esp-uart

Reliable IR library for ESP-OPEN-RTOS
MIT License
4 stars 0 forks source link

Please provide more information on your design used #1

Closed peros550 closed 5 years ago

peros550 commented 5 years ago

Hi Pablo,

I have a Wemos D1 mini and trying to use your code.

Did you use the schematic as described in this page? https://www.analysir.com/blog/2017/01/29/updated-esp8266-nodemcu-backdoor-upwm-hack-for-ir-signals/

Thanks,

peros550 commented 5 years ago

I tried your code, it works nicely. Many thanks!

Based on Analysir design I used the following connections:

image

For anyone who is interested, here is an example:

// Common initialization (can be done only once)
ir_esp_uart_init();
ir_esp_uart_set_frequency(38);

and here is a procedure for activating a Toyotomi AC at 30 degrees heating. The numbers (RAW data ) were produced using the original IR remote and a program called AnalysIR.

void ac_button_heat_30(){

//RAW data compatible with  IRremote library format
uint16_t Warm_30_I[] = {8920, 4364, 696, 488, 724, 460, 724, 1548, 724, 1544, 720, 1544, 700, 488, 724, 460, 724, 488, 696, 464, 728, 1540, 696, 1572, 724, 1544, 720, 468, 720, 464, 720, 464, 724, 460, 728, 460, 724, 488, 700, 464, 720, 460, 728, 464, 720, 1544, 724, 464, 724, 464, 724, 460, 724, 464, 724, 460, 724, 488, 696, 1548, 720, 488, 700, 1544, 720, 464, 720, 468, 696, 1572, 720, 464, 728, 19624, 696, 512, 700, 464, 724, 484, 700, 460, 724, 464, 724, 464, 720, 468, 720, 464, 700, 484, 724, 488, 700, 460, 724, 464, 724, 464, 724, 1544, 720, 460, 728, 464, 720, 464, 724, 464, 692, 492, 724, 464, 724, 460, 724, 488, 696, 464, 724, 464, 720, 464, 724, 488, 700, 488, 696, 464, 724, 464, 724, 1540, 700, 1572, 720, 464, 720};
uint16_t array_size;
int i;

array_size = sizeof(Warm_30_I)/sizeof(Warm_30_I[0]);

// Command begin
ir_esp_uart_begin();

for(i = 0; i < array_size; i++)
{

//// Command
ir_esp_uart_mark(Warm_30_I[i]);
i++;

if(i < array_size)
{
ir_esp_uart_space(Warm_30_I[i]);
}
}

// Command end
ir_esp_uart_end();

}
peros550 commented 5 years ago

@pbendersky Hi Pablo. How reliable is this library for you? After setting up the above design, it does send the command, but not successfully 10/10. Success rate for me was around 7 out of 10.

If you could provide any advice it would be great Thanks

pbendersky commented 5 years ago

Sadly yes. Although it’s way better than what is replacing (using bit banging), I still see some failed commands. 7 of 10 success rate sounds about right.

I’ll try debugging it more, but as I lack the instruments it’s a matter of trial and error mostly.

peros550 commented 5 years ago

Thank you Pablo! It is true that it's much much better than the rest libraries I have tried. I hope you can make it 👍 If you need help testing it, let me know. I'll keep an eye in this issue. :)

Thanks!

pbendersky commented 5 years ago

I'll leave it open and update if I find anything.

pbendersky commented 5 years ago

@peros550 just tried a bit and found a fix.

What you need to do to improve reliability is:

  1. Wrap the IR sending code in a task (that you create with xTaskCreate).
  2. Within the task, wrap the IR sending code in a critical section.

For example, based on your code:

void ac_button_heat_30_task() {

    //RAW data compatible with  IRremote library format
    uint16_t Warm_30_I[] = {8920, 4364, 696, 488, 724, 460, 724, 1548, 724, 1544, 720, 1544, 700, 488, 724, 460, 724, 488, 696, 464, 728, 1540, 696, 1572, 724, 1544, 720, 468, 720, 464, 720, 464, 724, 460, 728, 460, 724, 488, 700, 464, 720, 460, 728, 464, 720, 1544, 724, 464, 724, 464, 724, 460, 724, 464, 724, 460, 724, 488, 696, 1548, 720, 488, 700, 1544, 720, 464, 720, 468, 696, 1572, 720, 464, 728, 19624, 696, 512, 700, 464, 724, 484, 700, 460, 724, 464, 724, 464, 720, 468, 720, 464, 700, 484, 724, 488, 700, 460, 724, 464, 724, 464, 724, 1544, 720, 460, 728, 464, 720, 464, 724, 464, 692, 492, 724, 464, 724, 460, 724, 488, 696, 464, 724, 464, 720, 464, 724, 488, 700, 488, 696, 464, 724, 464, 724, 1540, 700, 1572, 720, 464, 720};
    uint16_t array_size;
    int i;

    array_size = sizeof(Warm_30_I)/sizeof(Warm_30_I[0]);

    // Command begin
    taskENTER_CRITICAL();
    ir_esp_uart_begin();

    for(i = 0; i < array_size; i++)
    {

    //// Command
    ir_esp_uart_mark(Warm_30_I[i]);
    i++;

    if(i < array_size)
    {
    ir_esp_uart_space(Warm_30_I[i]);
    }
    }

    // Command end
    ir_esp_uart_end();
    taskEXIT_CRITICAL();

    vTaskDelete(NULL);

}

void ac_button_heat_30() {
    xTaskCreate(ac_button_heat_30_task, "Send IR", 2048, state, 2 | portPRIVILEGE_BIT, NULL);
}

The critical section guarantees the scheduler doesn't interrupt your task, so the IR code runs with the correct timings.

peros550 commented 5 years ago

Thank you! I’ll test it the soonest possible and let you know!

peros550 commented 5 years ago

I just had the chance to test it! Excellent work Pablo! Many Thanks!