Environment setup: Refer to the Arduino IDE Getting Started Guide to install the IDE, and install the appropriate board package and required libraries for your development board.
Required libraries:
Required hardware:
G5 (TX)
and G6 (RX)
.#define UART_AUTO_SCAN_MODE
macro in the code.setDecodeTrigger
only works in manual scan mode. In automatic mode, calling this function will not control scanning/decoding.#include <M5Unified.h>
#include <M5GFX.h>
#include "M5UnitQRCode.h"
M5Canvas canvas(&M5.Display);
M5UnitQRCodeUART qrcode;
// #define UART_AUTO_SCAN_MODE //Enabling this macro definition will automatically scan and decode the code.
#define UART_TX 5
#define UART_RX 6
void setup() {
M5.begin();
Serial.begin(115200);
canvas.setColorDepth(16);
canvas.createSprite(M5.Display.width(), M5.Display.height());
canvas.setFont(&fonts::efontCN_16);
canvas.setTextScroll(true);
while (!qrcode.begin(&Serial1, 115200, UART_TX, UART_RX)) {
canvas.println("Init Fail");
Serial.println("QRCode2 Init Fail");
canvas.pushSprite(0, 0);
delay(1000);
}
canvas.println("Init Success");
Serial.println("QRCode2 Init Success");
#ifdef UART_AUTO_SCAN_MODE
canvas.println("Auto Scan Mode");
qrcode.setTriggerMode(AUTO_SCAN_MODE);
#else
canvas.println("Manual Scan Mode");
qrcode.setTriggerMode(MANUAL_SCAN_MODE);
#endif
canvas.setTextColor(TFT_YELLOW);
canvas.println("Press screen to\nstop/start scan");
canvas.setTextColor(TFT_WHITE);
canvas.pushSprite(0, 0);
}
void loop() {
if (qrcode.available()) {
String data = qrcode.getDecodeData();
uint16_t length = data.length();
Serial.printf("len:%d\n", length);
Serial.printf("decode data:");
Serial.println(data);
canvas.println("Decode data:");
canvas.println(data);
canvas.pushSprite(0, 0);
}
M5.update();
#ifndef UART_AUTO_SCAN_MODE
if (M5.BtnA.wasPressed()) {
qrcode.setDecodeTrigger(true); //Trigger scanning and decoding process once
}
#endif
}
1. Download mode: Different devices require different steps to enter download/programming mode before flashing. Refer to the device programming section at the bottom of the Arduino IDE Getting Started Guide for detailed steps.
For AtomS3R, press and hold the reset button for about 2 seconds until the internal green LED lights, then release. The device is now in download mode and ready for programming.