环境配置: 参考 Arduino IDE 上手教程完成 IDE 安装,并根据实际使用的开发板安装对应的板管理,与需要的驱动库。
使用到的驱动库:

#include <M5Unified.h>
#define TX_PIN 21
uint8_t data[5] = {0xAA, 0x55, 0x01, 0x02, 0x03};
void pulse(int high, int low) {
digitalWrite(TX_PIN, HIGH);
delayMicroseconds(high);
digitalWrite(TX_PIN, LOW);
delayMicroseconds(low);
}
void sendCorrected() {
noInterrupts();
// 1. 长时间保持低电平,确保接收端准备好
digitalWrite(TX_PIN, LOW);
delayMicroseconds(10000);
// 2. 发送明确的同步序列
pulse(5000, 2500); // 长同步脉冲
pulse(2500, 1250); // 短同步脉冲
// 3. 发送数据开始标记 - 与数据位明显不同的时序
pulse(8000, 4000); // 超长脉冲标记数据开始
// 4. 发送实际数据
for (int byte = 0; byte < 5; byte++) {
for (int bit = 7; bit >= 0; bit--) {
if (data[byte] & (1 << bit)) {
pulse(600, 300); // 发送1
} else {
pulse(300, 600); // 发送0
}
}
}
// 5. 数据结束标记
pulse(8000, 10000);
interrupts();
}
void setup() {
M5.begin();
Serial.begin(115200);
pinMode(TX_PIN, OUTPUT);
digitalWrite(TX_PIN, LOW);
M5.Display.fillRect(0, 0, 320, 240, WHITE);
M5.Display.setTextColor(BLACK);
M5.Display.setFont(&fonts::FreeMonoBold12pt7b);
M5.Display.setCursor(0, 0);
M5.Display.println("Corrected RF433T");
M5.Display.println("Click Btn A to send");
Serial.println("Corrected RF433 Transmitter Ready");
}
void loop() {
M5.update();
if (M5.BtnA.wasPressed()) {
Serial.println("SEND CORRECTED");
// 只发送一次,避免重复干扰
sendCorrected();
delay(100);
Serial.print("Sent: ");
for (int i = 0; i < 5; i++) {
Serial.printf("%02X ", data[i]);
}
Serial.println();
M5.Display.print("Sent: ");
for (int i = 0; i < 5; i++) {
M5.Display.printf("%02X ", data[i]);
}
M5.Display.println("");
}
delay(10);
}#include "RF433any.h"
#include <M5Unified.h>
#define PIN_RFINPUT 1
void setup() {
M5.begin();
M5.Display.fillRect(0, 0, 320, 240, WHITE);
M5.Display.setTextColor(BLACK);
M5.Display.setFont(&fonts::FreeMonoBold12pt7b);
M5.Display.setCursor(0, 0);
M5.Display.println("RF433 Receiver");
pinMode(PIN_RFINPUT, INPUT);
Serial.begin(115200);
Serial.println("Waiting for signal\n");
M5.Display.println("Waiting for signal");
}
Track track(PIN_RFINPUT);
void loop() {
track.treset();
while (!track.do_events())
delay(1);
Decoder *pdec0 = track.get_data(
RF433ANY_FD_DECODED | RF433ANY_FD_DEDUP | RF433ANY_FD_NO_ERROR
);
for (Decoder *pdec = pdec0; pdec != nullptr; pdec = pdec->get_next()) {
Serial.print("Received ");
M5.Display.println("Received \r\n");
Serial.print(pdec->get_nb_bits());
M5.Display.print(pdec->get_nb_bits());
Serial.print(" bits (x");
M5.Display.println(" bits (x");
Serial.print(pdec->get_repeats() + 1);
M5.Display.print(pdec->get_repeats() + 1);
Serial.print("): ");
M5.Display.println(": ");
char *buf = pdec->get_pdata()->to_str();
// DEFENSIVE PROGRAMMING
// The option RF433ANY_FD_DECODED above guarantees there's always
// something decoded. Test done though, just in case.
if (buf) {
Serial.println(buf);
M5.Display.println(buf);
free(buf);
}
}
delete pdec0;
delay(2000);
M5.Display.fillRect(0, 40, 320, 220, WHITE);
M5.Display.setCursor(0, 40);
}
// vim: ts=4:sw=4:tw=80:et下载模式:不同设备进行程序烧录前需要进入下载模式,不同的主控设备该步骤可能有所不同。详情可参考Arduino IDE上手教程页面底部的设备程序下载教程列表,查看具体的操作方式。
CoreS3 长按复位按键 (大约 2 秒) 直到内部绿色 LED 灯亮起,便可松开,此时设备已进入下载模式,等待烧录。
