Atomic QRCode2 Base
This library is the driver for Atomic QRCode2 Base, and the module communicates via UART.
Support the following products:
UiFlow2 Example:
QRCode Scan in Key Mode
Open the atoms3_qrcode2_key_mode_example.m5f2 project in UiFlow2.
In Key Mode, the module starts decoding when the button is pressed and stops decoding when the button is released. After a successful decoding, it stops decoding. To continue decoding, the button must be released and pressed again.
UiFlow2 Code Block:
Example output:
None
QRCode Scan in Continuous Mode
Open the atoms3_qrcode2_continuous_mode_example.m5f2 project in UiFlow2.
In Continuous Mode, pressing the button once starts decoding, and pressing the button again stops decoding.
UiFlow2 Code Block:
Example output:
None
QRCode Scan in Auto Mode
Open the atoms3_qrcode2_auto_mode_example.m5f2 project in UiFlow2.
In Auto Mode, the module starts decoding when powered on and cannot be stopped.
UiFlow2 Code Block:
Example output:
None
QRCode Scan in Pulse Mode
Open the atoms3_qrcode2_pulse_mode_example.m5f2 project in UiFlow2.
In Pulse Mode, set the TRIG pin to hold a low level for more than 20ms to trigger decoding once.
UiFlow2 Code Block:
Example output:
None
QRCode Scan in Motion Sensing Mode
Open the atoms3_qrcode2_motion_sensing_mode_example.m5f2 project in UiFlow2.
In Motion Sensing Mode, the module automatically triggers decoding when it detects a change in the scene based on visual recognition information.
UiFlow2 Code Block:
Example output:
None
MicroPython Example:
QRCode Scan in Key Mode
In Key Mode, the module starts decoding when the button is pressed and stops decoding when the button is released. After a successful decoding, it stops decoding. To continue decoding, the button must be released and pressed again.
MicroPython Code Block:
1# SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 2# 3# SPDX-License-Identifier: MIT 4 5import os, sys, io 6import M5 7from M5 import * 8from base import AtomicQRCode2Base 9 10 11title0 = None 12label_data = None 13label_status = None 14base_qrcode2 = None 15is_scanning = None 16status = None 17data = None 18 19 20def setup(): 21 global title0, label_data, label_status, base_qrcode2, is_scanning, status, data 22 M5.begin() 23 title0 = Widgets.Title("QRCode", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18) 24 label_data = Widgets.Label("data", 5, 60, 1.0, 0xFFFFFF, 0x000000, Widgets.FONTS.DejaVu18) 25 label_status = Widgets.Label( 26 "stop scan", 5, 25, 1.0, 0xFFFFFF, 0x000000, Widgets.FONTS.DejaVu18 27 ) 28 base_qrcode2 = AtomicQRCode2Base(2, 5, 6, 7) 29 base_qrcode2.set_trigger_mode(base_qrcode2.TRIGGER_MODE_KEY) 30 is_scanning = False 31 status = is_scanning 32 33 34def loop(): 35 global title0, label_data, label_status, base_qrcode2, is_scanning, status, data 36 M5.update() 37 if BtnA.isPressed(): 38 base_qrcode2.set_trig(0) 39 is_scanning = True 40 else: 41 base_qrcode2.set_trig(1) 42 is_scanning = False 43 if status != is_scanning: 44 status = is_scanning 45 if status: 46 label_status.setColor(0x00FF00, 0x000000) 47 label_status.setText(str("scanning")) 48 else: 49 label_status.setColor(0xFFFFFF, 0x000000) 50 label_status.setText(str("stop scan")) 51 data = base_qrcode2.read() 52 if data: 53 label_data.setText(str(data.decode())) 54 55 56if __name__ == "__main__": 57 try: 58 setup() 59 while True: 60 loop() 61 except (Exception, KeyboardInterrupt) as e: 62 try: 63 from utility import print_error_msg 64 65 print_error_msg(e) 66 except ImportError: 67 print("please update to latest firmware")
Example output:
None
QRCode Scan in Continuous Mode
In Continuous Mode, pressing the button once starts decoding, and pressing the button again stops decoding.
MicroPython Code Block:
1# SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 2# 3# SPDX-License-Identifier: MIT 4 5import os, sys, io 6import M5 7from M5 import * 8from base import AtomicQRCode2Base 9 10 11title0 = None 12label_data = None 13label_status = None 14base_qrcode2 = None 15is_scanning = None 16data = None 17 18 19def btna_was_clicked_event(state): 20 global title0, label_data, label_status, base_qrcode2, is_scanning, data 21 if is_scanning: 22 base_qrcode2.stop_decode() 23 label_status.setText(str("stop scan")) 24 label_status.setColor(0xFFFFFF, 0x000000) 25 else: 26 base_qrcode2.start_decode() 27 label_status.setText(str("scanning")) 28 label_status.setColor(0x00FF00, 0x000000) 29 is_scanning = not is_scanning 30 31 32def setup(): 33 global title0, label_data, label_status, base_qrcode2, is_scanning, data 34 M5.begin() 35 title0 = Widgets.Title("QRCode", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18) 36 label_data = Widgets.Label("data", 5, 60, 1.0, 0xFFFFFF, 0x000000, Widgets.FONTS.DejaVu18) 37 label_status = Widgets.Label( 38 "stop scan", 5, 25, 1.0, 0xFFFFFF, 0x000000, Widgets.FONTS.DejaVu18 39 ) 40 BtnA.setCallback(type=BtnA.CB_TYPE.WAS_CLICKED, cb=btna_was_clicked_event) 41 base_qrcode2 = AtomicQRCode2Base(2, 5, 6, 7) 42 base_qrcode2.set_trigger_mode(base_qrcode2.TRIGGER_MODE_CONTINUOUS) 43 base_qrcode2.set_startup_tone(1) 44 base_qrcode2.set_decode_success_beep(2) 45 base_qrcode2.stop_decode() 46 is_scanning = False 47 48 49def loop(): 50 global title0, label_data, label_status, base_qrcode2, is_scanning, data 51 M5.update() 52 data = base_qrcode2.read() 53 if data: 54 label_data.setText(str(data.decode())) 55 56 57if __name__ == "__main__": 58 try: 59 setup() 60 while True: 61 loop() 62 except (Exception, KeyboardInterrupt) as e: 63 try: 64 from utility import print_error_msg 65 66 print_error_msg(e) 67 except ImportError: 68 print("please update to latest firmware")
Example output:
None
QRCode Scan in Auto Mode
In Auto Mode, the module starts decoding when powered on and cannot be stopped.
MicroPython Code Block:
1# SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 2# 3# SPDX-License-Identifier: MIT 4 5import os, sys, io 6import M5 7from M5 import * 8from base import AtomicQRCode2Base 9 10 11title0 = None 12label_data = None 13label_status = None 14base_qrcode2 = None 15data = None 16 17 18def setup(): 19 global title0, label_data, label_status, base_qrcode2, data 20 M5.begin() 21 title0 = Widgets.Title("QRCode", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18) 22 label_data = Widgets.Label("data", 5, 60, 1.0, 0xFFFFFF, 0x000000, Widgets.FONTS.DejaVu18) 23 label_status = Widgets.Label( 24 "scanning", 5, 25, 1.0, 0x00FF00, 0x000000, Widgets.FONTS.DejaVu18 25 ) 26 base_qrcode2 = AtomicQRCode2Base(2, 5, 6, 7) 27 base_qrcode2.set_trigger_mode(base_qrcode2.TRIGGER_MODE_AUTO) 28 29 30def loop(): 31 global title0, label_data, label_status, base_qrcode2, data 32 M5.update() 33 data = base_qrcode2.read() 34 if data: 35 label_data.setText(str(data.decode())) 36 37 38if __name__ == "__main__": 39 try: 40 setup() 41 while True: 42 loop() 43 except (Exception, KeyboardInterrupt) as e: 44 try: 45 from utility import print_error_msg 46 47 print_error_msg(e) 48 except ImportError: 49 print("please update to latest firmware")
Example output:
None
QRCode Scan in Pulse Mode
In Pulse Mode, set the TRIG pin to hold a low level for more than 20ms to trigger decoding once.
MicroPython Code Block:
1# SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 2# 3# SPDX-License-Identifier: MIT 4 5import os, sys, io 6import M5 7from M5 import * 8from base import AtomicQRCode2Base 9import time 10 11 12title0 = None 13label_data = None 14label_status = None 15base_qrcode2 = None 16data = None 17 18 19def btna_was_clicked_event(state): 20 global title0, label_data, label_status, base_qrcode2, data 21 base_qrcode2.set_trig(0) 22 time.sleep_ms(20) 23 base_qrcode2.set_trig(1) 24 label_status.setText(str("scanning")) 25 label_status.setColor(0x00FF00, 0x000000) 26 27 28def setup(): 29 global title0, label_data, label_status, base_qrcode2, data 30 M5.begin() 31 title0 = Widgets.Title("QRCode", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18) 32 label_data = Widgets.Label("data", 5, 60, 1.0, 0xFFFFFF, 0x000000, Widgets.FONTS.DejaVu18) 33 label_status = Widgets.Label( 34 "stop scan", 5, 25, 1.0, 0xFFFFFF, 0x000000, Widgets.FONTS.DejaVu18 35 ) 36 BtnA.setCallback(type=BtnA.CB_TYPE.WAS_CLICKED, cb=btna_was_clicked_event) 37 base_qrcode2 = AtomicQRCode2Base(2, 5, 6, 7) 38 base_qrcode2.set_trigger_mode(base_qrcode2.TRIGGER_MODE_PULSE) 39 40 41def loop(): 42 global title0, label_data, label_status, base_qrcode2, data 43 M5.update() 44 data = base_qrcode2.read() 45 if data: 46 label_data.setText(str(data.decode())) 47 label_status.setText(str("stop scan")) 48 label_status.setColor(0xFFFFFF, 0x000000) 49 50 51if __name__ == "__main__": 52 try: 53 setup() 54 while True: 55 loop() 56 except (Exception, KeyboardInterrupt) as e: 57 try: 58 from utility import print_error_msg 59 60 print_error_msg(e) 61 except ImportError: 62 print("please update to latest firmware")
Example output:
None
QRCode Scan in Motion Sensing Mode
In Motion Sensing Mode, the module automatically triggers decoding when it detects a change in the scene based on visual recognition information.
MicroPython Code Block:
1# SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 2# 3# SPDX-License-Identifier: MIT 4 5import os, sys, io 6import M5 7from M5 import * 8from base import AtomicQRCode2Base 9 10 11title0 = None 12label_data = None 13label_status = None 14base_qrcode2 = None 15data = None 16 17 18def setup(): 19 global title0, label_data, label_status, base_qrcode2, data 20 M5.begin() 21 title0 = Widgets.Title("QRCode", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18) 22 label_data = Widgets.Label("data", 5, 60, 1.0, 0xFFFFFF, 0x000000, Widgets.FONTS.DejaVu18) 23 label_status = Widgets.Label( 24 "detecting", 5, 25, 1.0, 0x00FF00, 0x000000, Widgets.FONTS.DejaVu18 25 ) 26 base_qrcode2 = AtomicQRCode2Base(2, 5, 6, 7) 27 base_qrcode2.set_trigger_mode(base_qrcode2.TRIGGER_MODE_MOTION_SENSING) 28 base_qrcode2.set_motion_sensitivity(1) 29 30 31def loop(): 32 global title0, label_data, label_status, base_qrcode2, data 33 M5.update() 34 data = base_qrcode2.read() 35 if data: 36 label_data.setText(str(data.decode())) 37 38 39if __name__ == "__main__": 40 try: 41 setup() 42 while True: 43 loop() 44 except (Exception, KeyboardInterrupt) as e: 45 try: 46 from utility import print_error_msg 47 48 print_error_msg(e) 49 except ImportError: 50 print("please update to latest firmware")
Example output:
None
API
AtomicQRCode2Base
- class base.qrcode2.AtomicQRCode2Base
Create an AtomicQRCode2Base object.
- Parameters:
UiFlow2 Code Block:

MicroPython Code Block:
from base import AtomicQRCode2Base base_qrcode2 = AtomicQRCode2Base(id = 1, tx = 6, rx = 5, trig = 7)
- set_trig(value)
Set trigger pin value.
- Parameters:
value (int) –
0: low level.1: high level.
UiFlow2 Code Block:

MicroPython Code Block:
base_qrcode2.set_trig(value)
- start_decode()
Start decode.
UiFlow2 Code Block:

MicroPython Code Block:
base_qrcode2.start_decode()
- stop_decode()
Stop decode.
UiFlow2 Code Block:

MicroPython Code Block:
base_qrcode2.stop_decode()
- read()
Read qrcode data.
- Returns:
qrcode data.
- Return type:
None | bytes
If no data is received, return None.
UiFlow2 Code Block:

MicroPython Code Block:
base_qrcode2.read()
- set_trigger_mode(mode)
Set trigger mode.
- Parameters:
mode (int) –
The trigger mode. Available options:
TRIGGER_MODE_KEY: Key Mode, Decoding starts when the trigger pin is low and stops when the trigger pin is high.TRIGGER_MODE_CONTINUOUS: Call start_decode() to start decoding and stop_decode() to stop decoding.TRIGGER_MODE_AUTO: Auto Mode, Performs continuous decoding upon power-up and cannot be stopped.TRIGGER_MODE_PULSE: Pulse Mode, A 20ms low-level pulse on the trigger pin initiates a single decoding operation.TRIGGER_MODE_MOTION_SENSING: Motion Sensing Mode, Uses image recognition; decoding starts when a scene change is detected.
UiFlow2 Code Block:

MicroPython Code Block:
base_qrcode2.set_trigger_mode(mode)
- set_decode_delay(delay_ms)
Set decode delay.
- Parameters:
delay_ms (int) – decode delay time(ms), 0 means continuous decoding until success.
UiFlow2 Code Block:

MicroPython Code Block:
base_qrcode2.set_decode_delay(delay_ms)
- set_trigger_timeout(timeout_ms)
Set trigger timeout.
- Parameters:
timeout_ms – trigger timeout time(ms), Decoding will automatically stop when the duration exceeds this value.
UiFlow2 Code Block:

MicroPython Code Block:
base_qrcode2.set_trigger_timeout(timeout_ms)
- set_motion_sensitivity(level)
Set motion detection sensitivity. (in Motion Sensing Mode)
- Parameters:
level (int) – sensitivity level. Range: 1~5. The higher the level, the more sensitive it is to scene changes.
UiFlow2 Code Block:

MicroPython Code Block:
base_qrcode2.set_motion_sensitivity(level)
- set_continuous_decode_delay(delay_ms)
Set continuous decode delay. (in Motion Sensing Mode)
- Parameters:
delay_ms (int) – delay time(unit: 100ms), 0 means continuous decoding until timeout.
UiFlow2 Code Block:

MicroPython Code Block:
base_qrcode2.set_continuous_decode_delay(delay_ms)
- set_trigger_decode_delay(delay_ms):
Set trigger decode delay. (in Motion Sensing Mode)
Sets the trigger decoding delay time. This is the delay between re-entering the scene change detection phase and starting recognition again after detecting a change.
- Parameters:
delay_ms (int) – Trigger decode delay time(unit: ms).
UiFlow2 Code Block:

MicroPython Code Block:
base_qrcode2.set_trigger_decode_delay(delay_ms)
- set_same_code_interval(interval_ms)
Set same code interval.
- Parameters:
interval_ms (int) – The interval time for repeated recognition of the same code (unit: ms).
UiFlow2 Code Block:

MicroPython Code Block:
base_qrcode2.set_same_code_interval(interval_ms)
- set_diff_code_interval(interval_ms)
Set difference code interval.
- Parameters:
interval_ms (int) – The interval time for repeated recognition of the difference code (unit: ms).
UiFlow2 Code Block:

MicroPython Code Block:
base_qrcode2.set_diff_code_interval(interval_ms)
- set_same_code_no_delay(enable)
Set same code no delay.
- Parameters:
enable (bool) – Whether to enable non-delay output for the same code. True means enabled, False means disabled.
UiFlow2 Code Block:

MicroPython Code Block:
base_qrcode2.set_same_code_no_delay(enable)
- set_fill_light_mode(mode)
Set fill light mode.
- Parameters:
mode (int) –
The fill light mode. Available options:
FILL_LIGHT_OFF: Light off.FILL_LIGHT_ON: Light on.FILL_LIGHT_ON_DECODE: Light on during decoding.
UiFlow2 Code Block:

MicroPython Code Block:
base_qrcode2.set_fill_light_mode(mode)
- set_fill_light_brightness(brightness)
Set fill light brightness.
- Parameters:
brightness (int) – The fill light brightness. Range: 0~100.
UiFlow2 Code Block:

MicroPython Code Block:
base_qrcode2.set_fill_light_brightness(brightness)
- set_pos_light_mode(mode)
Set positioning light mode.
- Parameters:
mode (int) – The positioning light mode. Available options:
POS_LIGHT_OFF: Light off.POS_LIGHT_ON_DECODE: Light on during decoding.POS_LIGHT_FLASH_ON_DECODE: Light flash during decoding.
UiFlow2 Code Block:

MicroPython Code Block:
base_qrcode2.set_pos_light_mode(mode)
- set_startup_tone(mode)
Set startup tone.
- Parameters:
mode (int) –
0: Disable startup tone.1: Play 4 beeps.2: Play 2 beeps.
UiFlow2 Code Block:

MicroPython Code Block:
base_qrcode2.set_startup_tone(mode)
- set_decode_success_beep(count)
Set decode success beep.
- Parameters:
count (int) –
0: No prompt sound.1: Play prompt sound once.2: Play prompt sound twice.
UiFlow2 Code Block:

MicroPython Code Block:
base_qrcode2.set_decode_success_beep(count)
- set_case_conversion(mode)
Set case conversion.
- Parameters:
mode (int) –
0: Off (Original data).1: Convert to uppercase.2: Convert to lowercase.
UiFlow2 Code Block:

MicroPython Code Block:
base_qrcode2.set_case_conversion(mode)
- set_protocol_format(mode)
- Parameters:
mode (int) –
0: No protocol1: Format 1: [0x03] + Data Length (2 bytes) + Data2: Format 2: [0x03] + Data Length + Number of Barcodes + Code 1 Data Length + Code 1 Data + … + CRC3: Format 3: [0x03] + Data Length + Number of Barcodes + Code 1 ID + Code 1 Data Length + Code 1 Data + … + CRC
CRC generate reference program.
def crc16_calc(data: bytes) -> int: ca_crc = 0 for byte in data: for i in range(7, -1, -1): if ca_crc & 0x8000: ca_crc = (ca_crc << 1) ^ 0x18005 else: ca_crc <<= 1 if (byte & (1 << i)) != 0: ca_crc ^= 0x18005 return ca_crc & 0xFFFF
UiFlow2 Code Block:

MicroPython Code Block:
base_qrcode2.set_protocol_format(mode)





