# Telecomando IR per condizionatori

<abstract>
Appunti per realizzare un generatore di comandi IR per i condizionatori Acme
</abstract>

<img src="./receiver_sender.jpg">

Le prove lo ho fatte usando Platform.io su Mac

## Sender

Per ricevere da IR e vedere se il telecomando è supportato ho usato un ricevitore TSOP6236, lo stesso usato per la CM3-Home. Collegato direttamente ala GND, al 3V3 e 
al pin 14 (D5) del Wemos D1 (ESP12-F)

* [Datasheet ricevitore IR](https://www.vishay.com/docs/82463/tsop62.pdf) Stesso usato per la CM3-Home

Il codice che ho usato per riconoscere il telecomando è questo:

* <https://github.com/crankyoldgit/IRremoteESP8266/blob/master/examples/IRrecvDumpV2/IRrecvDumpV2.ino>


Dump del comando di spegnimento:

    Timestamp : 001375.323
    Library   : v2.7.20
    
    Protocol  : LG2
    Code      : 0x88C0051 (28 Bits)
    Mesg Desc.: Model: 2 (AKB75215403), Power: Off
    uint16_t rawData[59] = {3242, 9792,  502, 1540,  592, 496,  532, 496,  532, 500,  534, 1496,  572, 510,  528, 502,  532, 496,  532, 1488,  568, 1512,  570, 510,  508, 522,  534, 496,  532, 500,  532, 496,  532, 496,  534, 500,  532, 496,  502, 518,  558, 500,  508, 522,  534, 1504,  550, 504,  558, 1488,  550, 506,  558, 496,  534, 500,  528, 1500,  572};  // LG2 88C0051
    uint32_t address = 0x88;
    uint32_t command = 0xC005;
    uint64_t data = 0x88C0051;

Dump di un comando di accensione:

    Timestamp : 001426.403
    Library   : v2.7.20
    
    Protocol  : LG2
    Code      : 0x8800F43 (28 Bits)
    Mesg Desc.: Model: 2 (AKB75215403), Power: On, Mode: 0 (Cool), Temp: 30C, Fan: 4 (Maximum)
    uint16_t rawData[59] = {3478, 9766,  584, 1492,  570, 518,  512, 518,  516, 518,  512, 1552,  510, 500,  538, 518,  510, 522,  512, 518,  512, 522,  512, 518,  512, 518,  512, 522,  512, 518,  512, 522,  512, 500,  538, 1514,  550, 1504,  568, 1526,  550, 1508,  570, 496,  542, 1560,  512, 496,  486, 564,  536, 500,  482, 564,  538, 1514,  550, 1510,  516};  // LG2 8800F43
    uint32_t address = 0x88;
    uint32_t command = 0xF4;
    uint64_t data = 0x8800F43;

## Sender

Per trasmettere ho usato un LED IR connesso con una R da 100 ohm tra GND e GPIO4 (D2).

Sorgente derivato da <https://github.com/crankyoldgit/IRremoteESP8266/blob/master/examples/CommonAcControl/CommonAcControl.ino> e 
adattato ai condizionatori al primo piano Acme

    #include <Arduino.h>
    #include <IRremoteESP8266.h>
    #include <IRac.h>
    #include <IRutils.h>
    
    const uint16_t kIrLed = 4;  // The ESP GPIO pin to use that controls the IR LED.
    IRac ac(kIrLed);  // Create a A/C object using GPIO to sending messages with.
    
    void setup() {
      Serial.begin(115200);
      delay(200);
    
      // Set up what we want to send.
      // See state_t, opmode_t, fanspeed_t, swingv_t, & swingh_t in IRsend.h for
      // all the various options.
      ac.next.protocol = decode_type_t::LG2;  // Set a protocol to use.
      ac.next.model = 2;  // Some A/Cs have different models. Try just the first.
      ac.next.mode = stdAc::opmode_t::kCool;  // Run in cool mode initially.
      ac.next.celsius = true;  // Use Celsius for temp units. False = Fahrenheit
      ac.next.degrees = 18;  // 25 degrees.
      ac.next.fanspeed = stdAc::fanspeed_t::kMedium;  // Start the fan at medium.
      ac.next.swingv = stdAc::swingv_t::kOff;  // Don't swing the fan up or down.
      ac.next.swingh = stdAc::swingh_t::kOff;  // Don't swing the fan left or right.
      ac.next.light = false;  // Turn off any LED/Lights/Display that we can.
      ac.next.beep = false;  // Turn off any beep from the A/C if we can.
      ac.next.econo = false;  // Turn off any economy modes if we can.
      ac.next.filter = false;  // Turn off any Ion/Mold/Health filters if we can.
      ac.next.turbo = false;  // Don't use any turbo/powerful/etc modes.
      ac.next.quiet = false;  // Don't use any quiet/silent/etc modes.
      ac.next.sleep = -1;  // Don't set any sleep time or modes.
      ac.next.clean = false;  // Turn off any Cleaning options if we can.
      ac.next.clock = -1;  // Don't set any current time if we can avoid it.
      ac.next.power = true;  // Initially start with the unit off.
    }
    
    int i=18;
    
    void loop() {
      Serial.printf("Send %d\n",i);
    
      ac.next.degrees = i;
      i++;
      ac.sendAc();  // Have the IRac class create and send a message.
      delay(1000);  // Wait 5 seconds.
      if (i==31) i=18;
    }

il file platformio.ini usato è questo:

    [env:esp12e]
    platform = espressif8266
    board = esp12e
    framework = arduino
    upload_speed = 230400
    monitor_speed = 115200
    lib_deps = crankyoldgit/IRremoteESP8266 @ ^2.7.20


    
## Links

* <https://github.com/crankyoldgit/IRremoteESP8266>