0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

M5StickC Plus2 IRリモコン簡易解析

Last updated at Posted at 2025-12-22

M5StickC Plus2 と Ir Remote Unit を組み合わせてNECフォーマットの赤外線リモコン信号簡易解析スケッチを作成しました。

Aruduino IDE スケッチ

#include <M5StickCPlus2.h>

const int IR_RECEIVE_PORT_NO = 33;
const int NUM_OF_BURST_BITS = 16 * 2;
const int NUM_OF_FRAME_BITS = 100 * 2;
const int BIT_PERIOD = 562; // microseconds

int received_counter = 0;
int frame_counter = 0;
bool is_started = false;

void setup()
{
    M5.begin();
    M5.Power.begin();
    M5.Display.setRotation(1);
    Serial.begin(115200);
    pinMode(IR_RECEIVE_PORT_NO, INPUT);
    M5.Lcd.setTextSize(2);
    M5.Lcd.setCursor(0, 0);
    M5.Lcd.print("Checking IR receiver");
}

void loop()
{
    const int received_bit = digitalRead(IR_RECEIVE_PORT_NO) ? 0 : 1;

    if (received_bit != 0) {    // detected Infrared Signal
        received_counter++;
    } else {                    // NOT detected Infrared Signal
        received_counter = 0;
    }

    if (received_counter >= NUM_OF_BURST_BITS) {
        frame_counter = NUM_OF_FRAME_BITS;
    }

    if (frame_counter >= 0) {
        if (frame_counter == NUM_OF_FRAME_BITS) {
            M5.Lcd.setCursor(0, 25);
            M5.Lcd.print("detected!");
            Serial.print("\n");
        } else if (frame_counter > 0) {
            if (is_started == true) {
                Serial.print(received_bit);
            } else {
                if (received_bit != 0) {
                    Serial.print(received_bit);
                    is_started = true;
                } else {
                    ;   // skip space bits
                }
            }
        } else {
            M5.Lcd.setCursor(0, 25);
            M5.Lcd.print("         ");
            is_started = false;
        }

        frame_counter--;
    }
    
    delayMicroseconds(BIT_PERIOD / 2);
}

出力例

1100110011001100110011011101100110000001100000111000001100000...001100

赤外線2次変調(On/Off)周期 562.5マイクロ秒 に対して端数を切り捨てているため、ところどころで 0 と 1 の周期がずれていますが、ほぼ一定間隔で "00" と "11" を繰り返していることが観察できます。

オシロスコープ測定波形

M5StackCでプログラムを開発する前の準備段階でオシロスコープでIRリモコン信号を測定した波形です。

nec_format.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?