Описание
В статье Создания универсального ИК пульта из Arduino, я описал возможность управлять кондиционером при помощи arduino и ИК передатчика. Во время создания статьи я успешно управлял кондиционером Chigo, телевизорами LG, музыкальными центрами и прочими устройствами, которые (как выяснилось) используют IR-код до 100 меток. Что же делать с устройствами, которые используют более длинные IR-кода? При сканировании такого кода, библиотеки IRremote и IRlib не могли полностью распознать код, так как внутри библиотеки стоит ограничительная константа RAWBUF, больше которой контроллер не считывал значения (в моей версии библиотеки IRremote 0.1, значение константы RAWBUF равно 76, ограничительный предел равен 100).
Решение
Решение проблемы нашел на сайте https://www.analysir.com.
Скетч:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | // http://www.analysir.com/blog/2014/03/19/air-conditioners-problems-recording-long-infrared-remote-control-signals-arduino/ // http://www.analysir.com/blog/wp-content/uploads/2014/03/Arduino_Record_Long_AirConditioner_Infrared_Signals_10.txt // For LG AC /* Author: AnalysIR Revision: 1.0 This code is provided to overcome an issue with Arduino IR libraries It allows you to capture raw timings for signals longer than 255 marks & spaces. Typical use case is for long Air conditioner signals. You can use the output to plug back into IRremote, to resend the signal. This Software was written by AnalysIR. Usage: Free to use, subject to conditions posted on blog below. Please credit AnalysIR and provide a link to our website/blog, where possible. Copyright AnalysIR 2014 Please refer to the blog posting for conditions associated with use. http://www.analysir.com/blog/2014/03/19/air-conditioners-problems-recording-long-infrared-remote-control-signals-arduino/ Connections: IR Receiver Arduino V+ -> +5v GND -> GND Signal Out -> Digital Pin 2 (If using a 3V Arduino, you may connect V+ to +3V) */ #define LEDPIN 13 //you may increase this value on Arduinos with greater than 2k SRAM #define maxLen 700 volatile unsigned int irBuffer[maxLen]; //stores timings - volatile because changed by ISR volatile unsigned int x = 0; //Pointer thru irBuffer - volatile because changed by ISR void setup() { Serial.begin(38400); //change BAUD rate as required pinMode(4, OUTPUT); // VCC pin pinMode(3, OUTPUT); // GND ping digitalWrite(4, HIGH); // VCC +5V mode digitalWrite(3, LOW); // GND mode attachInterrupt(0, rxIR_Interrupt_Handler, CHANGE);//set up ISR for receiving IR signal } void loop() { // put your main code here, to run repeatedly: Serial.println(F("Press the button on the remote now - once only")); delay(5000); // pause 5 secs if (x) { //if a signal is captured digitalWrite(LEDPIN, HIGH);//visual indicator that signal received Serial.println(); Serial.print(F("Raw: (")); //dump raw header format - for library Serial.print((x - 1)); Serial.print(F(") ")); detachInterrupt(0);//stop interrupts & capture until finshed here for (int i = 1; i < x; i++) { //now dump the times if (!(i & 0x1)) Serial.print(F("-")); Serial.print(irBuffer[i] - irBuffer[i - 1]); Serial.print(F(", ")); } Serial.println(); // for bin output by chaeplin@gmail.com for (int n = 3; n < x; n++) { //now dump the times if (!(n & 0x1)) { if ( (irBuffer[n] - irBuffer[n - 1]) > 1000 ) { Serial.print("1"); } else { Serial.print("0"); } if ( ((n -2) % 8 ) == 0 ) { Serial.print(" "); } } } x = 0; Serial.println(); Serial.println(); digitalWrite(LEDPIN, LOW);//end of visual indicator, for this time attachInterrupt(0, rxIR_Interrupt_Handler, CHANGE);//re-enable ISR for receiving IR signal } } void rxIR_Interrupt_Handler() { if (x > maxLen) return; //ignore if irBuffer is already full irBuffer[x++] = micros(); //just continually record the time-stamp of signal transitions } |
При использовании выше приведенного скетча, мне удалось считать код длиной в 279 меток (кондиционер Cooper&Hunter CH-S18FTXLA-NG R32 Wi-Fi)
Желательно считывать код и отправлять его с одинаковых контроллеров. Например: если для считывания Вы используете контроллер Arduino Pro Mini 3.3В 8МГц ATMega328, то и для отправки сигналов, используйте подобный контроллер.
Для работоспособности скетча подключение IR receiver-а, происходит следующим образом:
Arduino Vcc (+) -> IR receiver (+)
Arduino GND (-) -> IR receiver (-)
Arduino 2 pin -> IR receiver (data)
После считывания длинного RAW кода, его можно уже отправлять при помощи библиотеки #include <IRremote.h>
и функции
1 | irsend.sendRaw(irSignal, sizeof(irSignal) / sizeof(irSignal[0]), khz); |
(Пример кода можно увидеть в IRsendRawDemo)
Скетч
Оставить комментарий