QRCode Unit
The QRCode Unit
is an integrated one-dimensional/two-dimensional code scanning unit that combines a CMOS QR code capture engine with a resolution of 640x480 and a bus conversion MCU (STM32F030). It features a device-side toggle switch that allows for switching between I2C and UART communication interfaces.
Support the following products:
Micropython Example:
import os, sys, io
import M5
from M5 import *
from unit import QRCodeUnit
from hardware import *
def qrcode_0_event(qrdata):
print(qrdata)
i2c0 = I2C(0, scl=Pin(1), sda=Pin(2), freq=100000)
qrcode_0 = QRCodeUnit(0, i2c0, 0x21)
qrcode_0.set_event_cb(qrcode_0_event)
qrcode_0.set_trigger_mode(1)
while True:
qrcode_0.event_poll_loop()
time.sleep_ms(25)
UIFLOW2 Example:
class QRCodeUnit
Constructors
- class QRCodeUnit(mode, i2c, address, id, port)
Create a QRCodeUnit object
- Parameters:
mode – 0: I2C, 1: UART mode.
i2c – the I2C object.
address – the I2C address of the device. Default is 0x21.
id – 1: UART1, 2: UART2.
port – uart pin tuple, which contains:
(tx_pin, rx_pin)
UIFLOW2:
Methods
- QRCodeUnit.get_qrcode_data_length()
Scan the QR code and get the available data length.
Return:
int
: available data length is int format
UIFLOW2:
- QRCodeUnit.get_qrcode_data()
Scan the QR code and get the data in the string.
Return:
string
: scanned data output is string format
UIFLOW2:
- QRCodeUnit.set_trigger_mode(mode)
Set the trigger mode to Auto or Manual(Key).
- The parameters is:
mode
: auto: 0 or manual: 1
UIFLOW2:
- QRCodeUnit.set_manual_scan(ctrl)
Set the manual(use the key button) scanning control ON or OFF.
- The parameters is:
ctrl
: off: 0 or on: 1
Note
This command is only effective in manual trigger mode
UIFLOW2:
- QRCodeUnit.set_event_cb(qrcode_0_event)
Set the callback event and callback function.
- The callback function:
qrcode_0_event
An handler showing a message has been received:
def qrcode_0_event(_qrdata): print(_qrdata) pass
UIFLOW2:
- QRCodeUnit.event_poll_loop()
The calling event poll block must be used inside a loop.
UIFLOW2:
- QRCodeUnit.get_qrcode_data_status()
Reading data scanned QR code after get the data status
Return:
int
: 0: not ready, 1: data available, 2: read again
UIFLOW2:
- QRCodeUnit.get_trigger_mode()
Get the auto or manual trigger mode status.
Return:
int
: 0: auto, 1: manual
UIFLOW2:
- QRCodeUnit.get_trigger_button_status()
Get the trigger button status
Return:
int
: 1: press, 0: not pressed
UIFLOW2:
- QRCodeUnit.get_device_info(info)
Get the firmware version details and I2C address of this device.
- The parameters is:
info
: 0xFE: firmware version, 0xFF: I2C address
UIFLOW2:
- QRCodeUnit.clear_qrcode_data_status()
Clear the data status after reading the QR code scanned data.
UIFLOW2:
- QRCodeUnit.set_device_i2c_address(addr)
The i2c address can be changed by the user and this address should be between 0x01 and 0x7F.
addr
: range of address(0x01 - 0x7F).
UIFLOW2: