@clabbersja
Sure, this is running on a M5Paper, though I have had something very similar running on a M5Core, This is the small segment of an app written for long rang tag reading at a workshop to track keys and other equipment. I have kept in the tag reading portion. I hope this helps. Some of it is not needed for the reading, just too lazy to remove from the snippet.
from m5stack import *
from m5ui import *
from uiflow import *
import wifiCfg
import time
import unit
import _thread
import os
import random
import urequests
from m5stack import touch
setScreenColor(15)
buzzer_1 = unit.get(unit.BUZZER, unit.PORTB)
uhf_rfid_0 = unit.get(unit.UHF_RFID, unit.PORTC)
version = 0.89
EPC = None
epc_bool = None
temp = None
tagList = []
TouchCordx = None
TouchCordy = None
rsense = 2
readerKey = None
businessKey = None
uhf_rfid_0.set_region(uhf_rfid_0.REGIN_US)
uhf_rfid_0.automatic_freq_hopping(0xFF)
uhf_rfid_0.set_channel_freq(924.25)
epc_bool = 0
uhf_rfid_0.set_select_mode(0x01)
print("Beapnow Reader : " + str(version))
print("---")
def genKey(length):
letters = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
result_str = ''.join(random.choice(letters) for i in range(length))
return result_str
def SetTouchCordenate():
global TouchCordx, TouchCordy
print("Setting Touch")
TouchCordx, TouchCordy, s, status = touch.read()
print(TouchCordx)
print(TouchCordy)
def uhf_rfid_cb(epc_no, dBm):
global EPC, epc_bool, temp
EPC = epc_no
_ = dBm
# label5.setText(str(EPC))
print("2")
print("---")
pass
# while not epc_bool:
# epc_bool = uhf_rfid_0.multiple_polling_read(uhf_rfid_cb, 100)
# while not (uhf_rfid_0.select_tag_param(EPC)):
# pass
ssid = None
pc = None
keyboard = None
sett = True
sim = True
bz = False
readerBool = True
touchBool = False
bzfreq = 500
la = []
ba = []
alphabet = [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"a",
"b",
"c",
"d",
"e",
"f",
"g",
"h",
"i",
"j",
"k",
"l",
"m",
"n",
"o",
"p",
"q",
"r",
"s",
"t",
"u",
"v",
"w",
"x",
"y",
"z",
]
tu = False
ltime = 0
dsc = 0
rr0 = None
rr1 = None
rr2 = None
rr3 = None
rr4 = None
rr5 = None
rr6 = None
rr7 = None
label0 = M5TextBox(502, 25, "Beapnow Tag Reader", lcd.FONT_DejaVu40, 0, rotate=90)
labelVersion = M5TextBox(
460, 30, "version: " + str(version), lcd.FONT_Default, 0, rotate=90
)
circle0 = M5Circle(492, 904, 30, 12, 0)
rectangle0 = M5Rect(290, 875, 60, 60, 12, 0)
rectangle1 = M5Rect(380, 875, 60, 60, 12, 0)
label1 = M5TextBox(334, 815, "Wifi", lcd.FONT_DejaVu24, 0, rotate=90)
label2 = M5TextBox(420, 663, "Read Sensitivity", lcd.FONT_DejaVu24, 0, rotate=90)
rs2 = M5TextBox(420, 882, "High", lcd.FONT_DejaVu18, 0, rotate=90)
label3 = M5TextBox(501, 770, "Wifi off", lcd.FONT_DejaVu24, 0, rotate=90)
label9 = M5TextBox(501, 620, "Waiting...", lcd.FONT_DejaVu24, 0, rotate=90)
label7 = M5TextBox(512, 892, "", lcd.FONT_DejaVu40, 0, rotate=90)
rectangle7 = M5Rect(170, 307, 200, 410, 14, 0)
label12 = M5TextBox(334, 322, "Tag #", lcd.FONT_DejaVu40, 0, rotate=90)
label13 = M5TextBox(331, 446, "1234567890", lcd.FONT_DejaVu40, 0, rotate=90)
label14 = M5TextBox(276, 431, "READ Success", lcd.FONT_DejaVu24, 0, rotate=90)
label15 = M5TextBox(227, 461, "Date Time", lcd.FONT_DejaVu24, 0, rotate=90)
def touchScreen():
global touchBool, ssid, pc, tu
print("Waiting for touch")
btty = 6
while True:
if touch.status():
print(str(touch.read()))
wait_ms(5)
def reader():
global bz, dsc, ltime, readerBool,rsense
temp = 0
count = 0
clean = 0
print("Waiting for RFID")
print("sensitivity = "+str(rsense))
while True:
ltime += 1
# while not temp:
temp = uhf_rfid_0.single_polling()
if temp:
label13.setText(str(temp[0]))
print("-----")
print(temp[0])
print(temp[1])
print("-----")
count += 1
lcd.show()
wait_ms(2)
def file_exists(filename):
try:
return (os.stat(filename)[0] & 0x4000) == 0
except OSError:
return False
def readSense():
global rsense
print("changing rsense")
if rsense == 2:
rsense = 5
rs2.setText("Low")
else:
rsense = 2
rs2.setText("High")
lcd.partial_show(370, 875, 60, 60)
def checkConfig():
# some check here
return True
def startTime():
print("START TIME")
# time = 0
# loop = True
# while loop:
# if time > 29:
# logTags()
# loop = False
# time += 1
# print(time)
# wait(.95)
label13.setText("")
ssid = ""
pc = ""
lcd.show()
_thread.start_new_thread(touchScreen, ())
if checkConfig():
_thread.start_new_thread(reader, ())
print("Ready for tags")
else:
print("waiting for register")