[搬运]StickV+StickC做无线一维条码扫描器
本帖最后由 vany5921 于 2020-4-21 15:12 编辑为你的图书ISBN码创建一个无线条码扫描器,当然也可以扫描其他一维码。你可以在StickV上用相机看书号,用M5SctickV查看isbn,然后在键盘上键入代码。使用前在Arduion IDE中安装ESP32 BLE键盘库,地址https://github.com/T-vK/ESP32-BLE-Keyboard//使用以下程序时需要先将蓝牙与电脑配对连接,确保连接正常,否则注释掉BLE相关部分。
StickV端程序
import sensor
import image
import lcd
import time
from machine import I2C,UART
from fpioa_manager import fm
#uart initial
fm.register(35, fm.fpioa.UART2_TX, force=True)
fm.register(34, fm.fpioa.UART2_RX, force=True)
uart_Port = UART(UART.UART2, 115200,8,0,0, timeout=1000, read_buf_len= 4096)
clock = time.clock()
lcd.init()
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.set_vflip(1)
sensor.set_hmirror(1)
sensor.run(1)
sensor.skip_frames(20)
while True:
clock.tick()
img = sensor.snapshot()
res = img.find_barcodes()
fps =clock.fps()
if len(res) > 0:
data = res.payload()
print(data)
uart_Port.write(data)
time.sleep(2)
lcd.display(img)
M5StickC端
#include <M5StickC.h>
#include <BleKeyboard.h>
//reception M5StickV
HardwareSerial serial_ext(2);
//Connect HID Bluetooth
BleKeyboard bleKeyboard;
void setup() {
M5.begin();
M5.Lcd.setRotation(3);
M5.Lcd.fillScreen(BLACK);
M5.Lcd.setCursor(0, 0);
M5.Lcd.setTextSize(2);
M5.Lcd.println("GO");
bleKeyboard.begin();
// Connect M5StickV
pinMode(32, OUTPUT);
pinMode(33, INPUT);
serial_ext.begin(115200, SERIAL_8N1, 32, 33);
}
// for IBSN (Number)
void loop() {
if(bleKeyboard.isConnected()) {
if ( serial_ext.available() > 0 ) {
bleKeyboard.press(KEY_LEFT_SHIFT );
String str = serial_ext.readStringUntil('\n');
bleKeyboard.print(str);
bleKeyboard.releaseAll();
M5.Lcd.fillScreen(BLACK);
M5.Lcd.setCursor(0, 0);
M5.Lcd.println(str);
}
}
}
页:
[1]