capella_ben wrote:Hi All,
As a bit of fun I have implemented the Arduino RC522 library in LUA on the NodeMCU.
https://github.com/capella-ben/LUA_RC522
Ben
..
Herllo Ben, I have got some problems with that lib on nodemcu v3.
Could you check the GitHub or contact me on FB in order to clarify the source ?
I need only to read the UID of the card. and i'm using this MAIN
Code: Select all----------------------------------------------------------------------
-- Main
----------------------------------------------------------------------
-- Initialise the RC522
spi.setup(1, spi.MASTER, spi.CPOL_LOW, spi.CPHA_LOW, spi.DATABITS_8, 0)
gpio.mode(pin_rst,gpio.OUTPUT)
gpio.mode(pin_ss,gpio.OUTPUT)
gpio.write(pin_rst, gpio.HIGH) -- needs to be HIGH all the time for the RC522 to work
gpio.write(pin_ss, gpio.HIGH) -- needs to go LOW during communications
RC522.dev_write(0x01, mode_reset) -- soft reset
RC522.dev_write(0x2A, 0x8D) -- Timer: auto; preScaler to 6.78MHz
RC522.dev_write(0x2B, 0x3E) -- Timer
RC522.dev_write(0x2D, 30) -- Timer
RC522.dev_write(0x2C, 0) -- Timer
RC522.dev_write(0x15, 0x40) -- 100% ASK
RC522.dev_write(0x11, 0x3D) -- CRC initial value 0x6363
-- turn on the antenna
current = RC522.dev_read(reg_tx_control)
if bit.bnot(bit.band(current, 0x03)) then
RC522.set_bitmask(reg_tx_control, 0x03)
end
--print("RC522 Firmware Version: 0x"..string.format("%X", RC522.getFirmwareVersion()))
tmr.alarm(0, 3000, tmr.ALARM_AUTO, function()
print("RC522 Firmware Version: 0x"..string.format("%X", RC522.getFirmwareVersion()))
isTagNear, cardType = RC522.request()
if isTagNear == true then
tmr.stop(0)
err, serialNo = RC522.anticoll()
print("Tag Found: "..appendHex(serialNo).." of type: "..appendHex(cardType))
end) --timer
And it is not working, I do not know why. I'm new to LUA, just understand the construction referring to the Arduino lib made by Miguel. So i will own you a beer for any suggestions.
Should I also add the:
Code: Select all -- halt tag and get ready to read another.
buf = {}
buf[1] = 0x50 --MF1_HALT
buf[2] = 0
crc = RC522.calculate_crc(buf)
table.insert(buf, crc[1])
table.insert(buf, crc[2])
err, back_data, back_length = RC522.card_write(mode_transrec, buf)
RC522.clear_bitmask(0x08, 0x08) -- Turn off encryption
tmr.start(0)
At the end of IF tag is near to be ready to get next tag ? and what if the tag persists in range of the reader ?
Mostly i would like to get the output only when new tag is there, and only ones per tag initiation.
I'm paying in beer if you have good will to throw me a bone
Cheers
M.