Skip to content

Infrared Transmitter

Library: IRremote (#include <IRremote.hpp>)
Access: IrSender global object
TX Pin: GPIO 44

The M5Cardputer has a built-in IR LED for infrared transmission. It supports NEC, Sony, RC5, and other protocols via the IRremote library.


Setup

#define DISABLE_CODE_FOR_RECEIVER  // Save memory (keyboard already takes RMT for ADV)
#define SEND_PWM_BY_TIMER
#define IR_TX_PIN 44
#include <IRremote.hpp>

void setup() {
    IrSender.begin(DISABLE_LED_FEEDBACK);
    IrSender.setSendPin(IR_TX_PIN);
}
Macro Purpose
DISABLE_CODE_FOR_RECEIVER Saves flash/RAM — no receive needed on Cardputer
SEND_PWM_BY_TIMER Use timer-based PWM instead of RMT (avoids RMT channel conflict)
IR_TX_PIN 44 IR LED pin on M5Cardputer

Sending NEC Commands

NEC is the most common IR protocol (used by most TVs, ACs, etc.).

IrSender.sendNEC(address, command, repeats);
Parameter Type Description
address uint16_t Device address (e.g., 0x1111)
command uint8_t Command code (e.g., 0x34 for power)
repeats uint8_t Number of repeats (0 = send once)

Example: TV Power Toggle

// Samsung TV power: address=0x0707, command=0x02
IrSender.sendNEC(0x0707, 0x02, 0);

Example: Volume Control with Keyboard

void loop() {
    M5Cardputer.update();

    if (M5Cardputer.Keyboard.isChange()) {
        M5Cardputer.Keyboard.updateKeysState();
        for (char c : M5Cardputer.Keyboard.keysState().word) {
            switch (c) {
                case '+':
                    IrSender.sendNEC(0x1111, 0x10, 0);  // Vol+
                    break;
                case '-':
                    IrSender.sendNEC(0x1111, 0x11, 0);  // Vol-
                    break;
            }
        }
    }
}

Other Protocols

IrSender.sendSony(address, command, repeats);   // Sony SIRCS
IrSender.sendRC5(address, command, repeats);     // Philips RC5
IrSender.sendRC6(address, command, repeats);     // Philips RC6
IrSender.sendRaw(data, length, frequency);       // Raw pulse train

For protocol details, refer to the IRremote documentation.


Quick Example: IR Remote Emulator

Complete example at examples/Basic/ir_nec:

#define DISABLE_CODE_FOR_RECEIVER
#define SEND_PWM_BY_TIMER
#define IR_TX_PIN 44
#include <IRremote.hpp>
#include <M5Cardputer.h>

void setup() {
    M5Cardputer.begin();
    IrSender.begin(DISABLE_LED_FEEDBACK);
    IrSender.setSendPin(IR_TX_PIN);

    M5Cardputer.Display.println("IR NEC Sender");
    M5Cardputer.Display.println("Press any key to send IR command");
}

void loop() {
    M5Cardputer.update();

    if (M5Cardputer.Keyboard.isChange() && M5Cardputer.Keyboard.isPressed()) {
        IrSender.sendNEC(0x1111, 0x34, 0);
        M5Cardputer.Display.println("Sent NEC 0x1111 0x34");
    }
}