Try   HackMD

新人資訊

技術-開發板 #13-試一下RFID,可嗶卡了

嗶卡已經是我們生活的日常,搭捷運,消費付款,出入公司廠區門禁等等,這個 Arduino 也是可玩的。遲遲沒去玩它是因為找不到可做的應用,但終究還是要演練一次才好,當作技術儲備;演練過後覺得,若要做整套公司的門禁管理系統好像也不太難,多做準備總是好事。

首先準備必要的硬體模組,NodeMcu ESP8266 主板,RC522 RFID Reader (這次我焊的接腳好看多了),兩張卡 (一個鈕扣型的和一個卡片型),然後為了確認有刷到卡再準備一個蜂鳴器,和一片小小的 OLED 顯示器。

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

然後是接線,RC522 的接腳較複雜,但不乏網路熱心人士分享,參考這一篇 https://blog.jmaker.com.tw/arduino-rfid/ 寫得很清楚。RC522 對應到 NodeMcu 接腳如下:

  1. SDA (Serial Data) > D4 (可在程式設定)
  2. SCK (Serial Clock) > D5 (NodeMcu 固定接腳)
  3. MOSI (Master Out Slave In) > D7 (NodeMcu 固定接腳)
  4. MISO (Master In Slave Out) > D6 (NodeMcu 固定接腳)
  5. IRQ > 不用接
  6. GND > GND
  7. RST > D3 (可在程式設定)
  8. 3.3V > 3.3V
    以上這些怪怪的接腳原來是定義在 SPI (Serial Peripheral Interface) 通信協定裏:https://en.wikipedia.org/wiki/Serial_Peripheral_Interface

複習一下 NodeMcu 接腳:

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

然後是蜂鳴器,有兩種 (有源和無源),有源是簡單的單一頻率,無源是可以發出不同頻率音高組出簡單樂曲用的,這邊用最簡單的有源蜂鳴器,只有兩個接腳 (正負),負的接地,正的接到任一個 Digital Output (我選 D8),程式控制高電壓則響,低電壓則停,很簡單的。

然後還要搞定那片小 OLED 顯示,花了些力氣爬文後測通,它有四個接腳,除了基本的電源兩支腳外,搞不清楚 SDA and SCL 要接哪裡,這問題在 Adafruit_SSD1306 程式庫的範例裡面找到答案 (https://github.com/adafruit/Adafruit_SSD1306),固定接 D1 > SCL, D2 > SDA,整個接完非常壯觀,用到的接腳空前的多,已經充分利用了這片小小的 NodeMcu,竟然同時供應三組電源:RC522 + 蜂鳴器 + OLED,可以包在一小盒子裡沒有問題。

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

剩下就是寫程式部分了,相關的程式庫如下,都可在 IDE 環境安裝。

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

整個操作過程簡單順暢:

https://youtu.be/ojwkGfYFdGM

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

嗶卡的技術關節已經打通,除了最直覺的門禁管制系統以外尚不知可做何應用,先這樣吧。

By Newman Chen 2022/6/2

後記,2022/6/4:

脫離了大麵包板,巧妙的縮進一個小小的盒子裡,非常接近一個最終產品形式了。如果用焊接取代那些線,加上漂亮的外殼,和可雲端管理和更新的系統,應該可以創造出很棒的解決方案。

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

https://youtu.be/asP26CV9f-g

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

參考資料:

https://blog.jmaker.com.tw/arduino-rfid/

https://github.com/adafruit/Adafruit_SSD1306

https://en.wikipedia.org/wiki/Serial_Peripheral_Interface