Atomic QRCode Base
这个库是 Atomic QRCode Base 的驱动,该模块使用 UART 通信。
支持以下产品:
UiFlow2 应用示例:
按键模式二维码识别
在 UiFlow2 上打开 atoms3_qrcode_key_mode_example.m5f2 项目。
在按键模式下,模块在按下按键时开始解码,并在释放按键时停止解码
UiFlow2 代码块:
示例输出:
无
主机模式二维码识别
在 UiFlow2 上打开 atoms3_qrcode_host_mode_example.m5f2 项目。
在主机模式下,按下一次按键开始解码,再次按下停止解码。
UiFlow2 代码块:
示例输出:
无
自动模式二维码识别
在 UiFlow2 上打开 atoms3_qrcode_auto_mode_example.m5f2 项目。
在自动模式下,模块上电开始扫码解码,不可停止。
UiFlow2 代码块:
示例输出:
无
脉冲模式二维码识别
在 UiFlow2 上打开 atoms3_qrcode_pulse_mode_example.m5f2 项目。
在脉冲模式下,设置触发引脚超过 20ms 的低电平触发解码一次。
UiFlow2 代码块:
示例输出:
无
移动感应模式二维码识别
在 UiFlow2 上打开 atoms3_qrcode_motion_sensing_mode_example.m5f2 项目。
在感应模式下,模块基于视觉识别信息检测到场景变化时,会自动触发解码。
UiFlow2 代码块:
示例输出:
无
MicroPython 应用示例:
按键模式二维码识别
在按键模式下,模块在按下按键时开始解码,并在释放按键时停止解码
MicroPython 代码块:
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 AtomicQRCodeBase 9 10 11title0 = None 12label_data = None 13label_status = None 14base_qrcode = None 15is_scanning = None 16status = None 17data = None 18 19 20def setup(): 21 global title0, label_data, label_status, base_qrcode, 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_qrcode = AtomicQRCodeBase(2, 5, 6, 7, 8) 29 base_qrcode.set_trigger_mode(base_qrcode.TRIGGER_MODE_KEY) 30 is_scanning = False 31 status = is_scanning 32 33 34def loop(): 35 global title0, label_data, label_status, base_qrcode, is_scanning, status, data 36 M5.update() 37 if BtnA.isPressed(): 38 base_qrcode.set_trig(0) 39 is_scanning = True 40 else: 41 base_qrcode.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_qrcode.read() 52 if data: 53 label_data.setText(str(data.decode())) 54 print(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")
示例输出:
无
主机模式二维码识别
在主机模式下,按下一次按键开始解码,再次按下停止解码。
MicroPython 代码块:
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 AtomicQRCodeBase 9 10 11title0 = None 12label_data = None 13label_status = None 14base_qrcode = None 15is_scanning = None 16data = None 17 18 19def btna_was_clicked_event(state): 20 global title0, label_data, label_status, base_qrcode, is_scanning, data 21 if is_scanning: 22 base_qrcode.stop_decode() 23 label_status.setText(str("stop scan")) 24 label_status.setColor(0xFFFFFF, 0x000000) 25 else: 26 base_qrcode.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_qrcode, 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_qrcode = AtomicQRCodeBase(2, 5, 6, 7, 8) 42 is_scanning = False 43 base_qrcode.set_trigger_mode(base_qrcode.TRIGGER_MODE_HOST) 44 base_qrcode.set_pos_light_mode(base_qrcode.POS_LIGHT_ON_DECODE) 45 base_qrcode.set_fill_light_mode(base_qrcode.FILL_LIGHT_ON_DECODE) 46 47 48def loop(): 49 global title0, label_data, label_status, base_qrcode, is_scanning, data 50 M5.update() 51 data = base_qrcode.read() 52 if data: 53 label_data.setText(str(data.decode())) 54 print(data.decode()) 55 base_qrcode.start_decode() 56 57 58if __name__ == "__main__": 59 try: 60 setup() 61 while True: 62 loop() 63 except (Exception, KeyboardInterrupt) as e: 64 try: 65 from utility import print_error_msg 66 67 print_error_msg(e) 68 except ImportError: 69 print("please update to latest firmware")
示例输出:
无
自动模式二维码识别
在自动模式下,模块上电开始扫码解码,不可停止。
MicroPython 代码块:
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 AtomicQRCodeBase 9 10 11title0 = None 12label_data = None 13label_status = None 14base_qrcode = None 15data = None 16 17 18def setup(): 19 global title0, label_data, label_status, base_qrcode, 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_qrcode = AtomicQRCodeBase(2, 5, 6, 7, 8) 27 base_qrcode.set_trigger_mode(base_qrcode.TRIGGER_MODE_AUTO) 28 29 30def loop(): 31 global title0, label_data, label_status, base_qrcode, data 32 M5.update() 33 data = base_qrcode.read() 34 if data: 35 print(data.decode()) 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")
示例输出:
无
脉冲模式二维码识别
在脉冲模式下,设置触发引脚超过 20ms 的低电平触发解码一次。
MicroPython 代码块:
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 AtomicQRCodeBase 9import time 10 11 12title0 = None 13label_data = None 14label_status = None 15base_qrcode = None 16data = None 17 18 19def btna_was_clicked_event(state): 20 global title0, label_data, label_status, base_qrcode, data 21 base_qrcode.set_trig(0) 22 time.sleep_ms(20) 23 base_qrcode.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_qrcode, 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_qrcode = AtomicQRCodeBase(2, 5, 6, 7, 8) 38 base_qrcode.set_trigger_mode(base_qrcode.TRIGGER_MODE_PULSE) 39 40 41def loop(): 42 global title0, label_data, label_status, base_qrcode, data 43 M5.update() 44 data = base_qrcode.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")
示例输出:
无
移动感应模式二维码识别
在感应模式下,模块基于视觉识别信息检测到场景变化时,会自动触发解码。
MicroPython 代码块:
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 AtomicQRCodeBase 9 10 11title0 = None 12label_data = None 13label_status = None 14base_qrcode = None 15data = None 16 17 18def setup(): 19 global title0, label_data, label_status, base_qrcode, 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_qrcode = AtomicQRCodeBase(2, 5, 6, 7, 8) 27 base_qrcode.set_trigger_mode(base_qrcode.TRIGGER_MODE_MOTION_SENSING) 28 29 30def loop(): 31 global title0, label_data, label_status, base_qrcode, data 32 M5.update() 33 data = base_qrcode.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")
示例输出:
无
API应用
AtomicQRCodeBase
- class base.qrcode.AtomicQRCodeBase(id=1, tx=5, rx=6, trig=7, done=8)
基类:
object创建一个 AtomicQRCodeBase 对象。
- 参数:
UiFlow2 代码块:

MicroPython 代码块:
from base import AtomicQRCodeBase base_qrcode = AtomicQRCodeBase(id = 1, tx = 6, rx = 5, trig = 7, done = 8)
- set_trig(value)
设置触发引脚电平。
- 参数:
value (int) –
0- 低电平,1- 高电平。- 返回类型:
None
UiFlow2 代码块:

MicroPython 代码块:
base_qrcode.set_trig(value)
- start_decode()
开始解码。
UiFlow2 代码块:

MicroPython 代码块:
base_qrcode.start_decode()
- 返回类型:
None
- stop_decode()
停止解码。
UiFlow2 代码块:

MicroPython 代码块:
base_qrcode.stop_decode()
- 返回类型:
None
- set_trigger_mode(mode)
Set trigger mode.
- 参数:
mode (int) – 触发解码模式,可选项: -
TRIGGER_MODE_KEY: 按键模式, 触发引脚低电平触发解码,高电平停止解码,解码成功后停止解码。-TRIGGER_MODE_HOST: 主机模式, 命令控制解码,解码成功或者超时停止解码-TRIGGER_MODE_AUTO: 自动模式, 上电自动开始解码。-TRIGGER_MODE_PULSE: 脉冲模式, 触发引脚 20ms 以上低电平触发一次解码。-TRIGGER_MODE_MOTION_SENSING: 移动感应模式,使用图像识别感应,当检测到场景发生变化时,触发解码。- 返回类型:
None
UiFlow2 代码块:

MicroPython 代码块:
base_qrcode.set_trigger_mode(mode)
- set_decode_continuous(delay_100ms)
设置解码持续时间。
- 参数:
delay_100ms (int) – 解码持续时间(单位: 100ms),范围:0~99,对应 0~9900 ms(0表示无限时)。
- 返回类型:
None
UiFlow2 代码块:

MicroPython 代码块:
base_qrcode.set_decode_continuous(delay_100ms)
- set_decode_interval(interval_100ms)
设置解码间隔时间
- 参数:
interval_100ms (int) – 解码间隔时间(单位:100ms),范围:0~99,对应 0~9900 ms。
- 返回类型:
None
UiFlow2 代码块:

MicroPython 代码块:
base_qrcode.set_decode_interval(interval_100ms)
- set_same_code_interval(interval_100ms)
设置同码间隔。
- 参数:
interval_100ms (int) – 同码间隔(单位:100ms), 范围: 0~99, 对应 0~9900ms 。
- 返回类型:
None
UiFlow2 代码块:

MicroPython 代码块:
base_qrcode.set_same_code_interval(interval_100ms)
- set_fill_light_mode(mode)
设置补光灯模式。
- 参数:
mode (int) – 补光灯模式,可选项: -
FILL_LIGHT_OFF: 常灭。-FILL_LIGHT_ON: 常亮。 -FILL_LIGHT_ON_DECODE: 解码时亮。- 返回类型:
None
UiFlow2 代码块:

MicroPython 代码块:
base_qrcode.set_fill_light_mode(mode)
- set_pos_light_mode(mode)
设置定位灯模式。
- 参数:
mode (int) – 定位灯模式,可选项: -
POS_LIGHT_OFF: 常灭。 -POS_LIGHT_ON: 常亮。 -POS_LIGHT_ON_DECODE: 解码时亮。- 返回类型:
None
UiFlow2 代码块:

MicroPython 代码块:
base_qrcode.set_pos_light_mode(mode)
- set_startup_tone(enable)
设置启动提示音。
- 参数:
enable (bool) – True - 开启启动提示音, False - 关闭启动提示音。
- 返回类型:
None
UiFlow2 代码块:

MicroPython 代码块:
base_qrcode.set_startup_tone(enable)
/img-3fe4e63e-ae76-4a9b-b3fc-948adb3c274d.jpg)







