@falbriard An attempt to write a logic with Blockly & MicroPython code (via UIFlow), able to store up to 1000 characters on a RFID tag:
# by Claude Falbriard - QcLab Brazil
# RFID tag with RC522 layout
from m5stack import *
from m5stack_ui import *
from uiflow import *
import time
import unit
screen = M5Screen()
screen.clean_screen()
screen.set_screen_bg_color(0x000000)
rfid_0 = unit.get(unit.RFID, unit.PORTA)
inputsrt2 = None
elecounter = None
alldata = None
inputstr1 = None
inputdata = None
inputstr4 = None
cardready = None
label0 = M5Label('RFID Reader', x=10, y=10, color=0xf5f2f2, font=FONT_MONT_14,
parent=None)
text_2 = M5Label('text_2', x=10, y=113, color=0xb1ed94, font=FONT_MONT_14,
parent=None)
text_4 = M5Label('text_4', x=10, y=138, color=0xccf1a6, font=FONT_MONT_14,
parent=None)
debug1 = M5Label('Debug: ', x=10, y=226, color=0xf09a9a, font=FONT_MONT_14,
parent=None)
alldata_label = M5Label('alldata', x=10, y=170, color=0xdff2d7, font=FONT_MONT_14,
parent=None)
inputd1 = M5Label('input data', x=10, y=48, color=0xe8f081, font=FONT_MONT_14,
parent=None)
text_1 = M5Label('text_1', x=10, y=88, color=0xcbeeb9, font=FONT_MONT_14,
parent=None)
elecounter = 0
# constructing an RFID RC522 compliant data writer
# https://www.blindtextgenerator.com/lorem-ipsum
# generate a string with max length of 1000 characters
ipsumstr = """Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo
ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient
montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium
quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec,
vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam
dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum
semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat
vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus.
Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam
ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus.
Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet
adipiscing sem neque sed ipsum. N"""
# chop test data string to 256 bytes
ipsumstr = ipsumstr[:256]
# split a text into 16 bytes elements, max size = 1000
def split_by_n(seq, n):
'''A generator to divide a sequence into chunks of n units.'''
while seq:
yield seq[:n]
seq = seq[n:]
rc522list = list(split_by_n(ipsumstr, 16))
blkcount = len(rc522list)
# process list by RC522 element max 1000 char
validptr = [1,2,4,5,6,8,9,10,12,13,14,16,17,18,20,21,22,24,25,26,28,29,30,\
32,33,34,36,37,38,40,41,42,44,45,46,48,49,50,52,53,54,56,57,58,\
60,61,62,64,65,66,68,69,70,72,73,74,76,77,78,80,81,82,84,85,86]
keyptr = [3,7,11,15,19,23,27,31,35,39,43,47,51,55,59,63,67,71,75,79,83]
while True:
alldata = ''
inputstr1 = ''
inputsrt2 = ''
inputdata = ''
inputstr4 = ''
cardready = False
wait(1)
debug1.set_text('start reading ...')
if rfid_0.isCardOn():
debug1.set_text('card found')
inputdata = rfid_0.readUid()
speaker.playTone(740, 1/2)
inputd1.set_text(str(inputdata))
elecounter = 0
for ele in rc522list:
blkdata = ele
blkaddr = validptr[elecounter]
rfid_0.writeBlock(blkaddr,blkdata)
elecounter += 1
wait_ms(400)
# read data only for debug
inputstr1 = rfid_0.readBlockStr(1)
inputsrt2 = rfid_0.readBlockStr(2)
inputstr4 = rfid_0.readBlockStr(4)
# all data stored on tag
for blkcount in range (0,elecounter):
blkaddr = validptr[blkcount]
record = rfid_0.readBlockStr(blkaddr)
alldata += record
if inputdata == '1e1cb67cc8':
power.setVibrationIntensity(80)
power.setVibrationEnable(True)
wait(0.5)
power.setVibrationEnable(False)
# show data for debug and validation
text_1.set_text(str(inputstr1))
text_2.set_text(str(inputsrt2))
text_4.set_text(str(inputstr4))
alldata_label.set_text(str(alldata))
wait(2)