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
..
Explore... Chat... Share...
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
..
----------------------------------------------------------------------
-- 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
-- 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)
It takes about 20-25 seconds for home assistant c[…]
I tried to upgrade tof my sonoff basic R2 with the[…]
a problem Perhaps you want to define "Probl[…]
Rebooting your router will not give you a faster I[…]
There are no other notifications from esptool.py i[…]
Using the Arduino IDE, you'll learn how to set up […]
In this project, you will post to Twitter using an[…]
In this project, we will build a water level contr[…]
I guess I'm late, but I had the same problem and f[…]
Last night I received my first D1 Minis for a lear[…]
Although I am aware that this is an old post, I fe[…]