0
  • 聊天消息
  • 系統(tǒng)消息
  • 評論與回復
登錄后你可以
  • 下載海量資料
  • 學習在線課程
  • 觀看技術視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會員中心
創(chuàng)作中心

完善資料讓更多小伙伴認識你,還能領取20積分哦,立即完善>

3天內不再提示

用搭積木的方式自制一個NFC讀卡器

瑞科慧聯(RAK) ? 2022-07-28 14:17 ? 次閱讀

地鐵刷卡、上下班門禁打卡、高鐵進站刷身份證、Apple Pay 購物……這些日常使用場景,都使用了 NFC 非接觸式識別和互聯技術,極大地方便了人們的生活。

不過,目前市面上常見的NFC無線讀卡器都使用 WIFI或藍牙進行數據傳輸,功耗較高、且傳輸距離有限。而如果采用 LoRaWAN?傳輸,則可以解決上述問題。事實上,基于 LoRaWAN?的 NFC 讀卡器優(yōu)點突出:

1、LoRaWAN?的傳輸距離遠、接收靈敏度高、且功耗低

2、采用LoRaWAN?無線傳輸的讀卡器安裝部署方便

3、能使用電池供電、可持續(xù)使用半年以上。

本文將通過瑞科慧聯的模塊化開發(fā)套件 WisBlock 教大家快速搭建一個支持LoRaWAN?的無線讀卡器,讓這個讀卡器讀到電子標簽數據時,可以自動將數據上傳到 LoRaWAN?服務器上。WisBlock 其實是一個物聯網解決方案設計生態(tài)系統(tǒng),由可拼接的模塊和易于使用的軟件工具組成,可加快物聯網產品生產周期、縮短上市時間。

搭建 LoRaWAN?NFC 讀卡器概述

本次搭建使用的硬件是瑞科慧聯(RAK)的 WisBlock 套件,MCU 選擇的是RAK4631WisBlock Core 模塊,該模塊采用強大的 Nordic nRF52840 MCU,可以支持藍牙 5.0(藍牙低能耗),以及 Semtech最新的 LoRa?收發(fā)器 SX1262,支持 LoRa?和藍牙兩種通信模式。

該 NFC 還選擇了 WisBlock 套件的 RAK13600 NFC 讀卡器模組,它使用的是 PN532芯片,可以支持 ISO/ICE 14443A/B 卡類型的讀寫,而且還搭配了一個蜂鳴器模組 RAK18001,當 NFC 刷卡有效時,蜂鳴器會發(fā)出響聲提醒。

對了,該 NFC 讀卡器的搭建還會使用到瑞科慧聯(RAK)的低代碼開發(fā)平臺 RUI3,它為 WisBlock 提供包含傳感器驅動接口、無線發(fā)送接口等豐富的 API接口函數,這樣我們只需要寫少量的應用代碼就可以完成此產品搭建了。

硬件電路搭建

硬件準備

首先我們需要準備 RAK4631 模塊、RAK5005-O 底板、RAK13600 NFC 讀卡器、RAK18001 蜂鳴器、兩張 ISO 14443B 卡、一根 LoRa?天線、一根 NFC天線、一個 Unify 外殼、一根藍牙天線(安裝在外殼內)。

RAK4631 模塊、RAK19007 底板、RAK13600 NFC 讀卡器等硬件準備RAK4631 模塊、RAK19007 底板、RAK13600 NFC 讀卡器等硬件準備

硬件組裝

把 RAK4631 模塊扣在 CPU SLOT 的位置,RAK13600 扣在 IO SLOT 的位置,RAK18001 扣在 SLOT A(或者SLOT B),并且使用螺絲把模組固定。

連接NFC天線、LoRa?天線、藍牙天線,并安裝至外殼中。硬件組裝完成之后就可以進行軟件設置。

軟件環(huán)境搭建

Arduino IDE中添加 RAK4631-R 開發(fā)板

打開 Arduino IDE,進入“文件 > 首選項”

打開 Arduino IDE打開 Arduino IDE

單擊圖中圖標,修改“附加開發(fā)板管理器網址”選項,將 RAK4631-R WisBlock Core 添加中 Arduino 開發(fā)板管理器中。

在 Arduino IDE上修改“附加開發(fā)板管理器網址”在 Arduino IDE上修改“附加開發(fā)板管理器網址”

現在復制這個 URL https://raw.githubusercontent.com/RAKWireless/RAKwireless-Arduino-BSP-Index/main/package_rakwireless.com_rui_index.json 并粘貼至下圖所示區(qū)域。如果已存在其他鏈接,將上述鏈接粘貼至新的一行。完成后,單擊“好”。

在Arduino IDE上粘貼復制好的URL在Arduino IDE上粘貼復制好的URL

重啟 Arduino IDE。 進入“工具 > 開發(fā)板:“RAK4631” > 開發(fā)板管理器”。

重啟Arduino IDE并執(zhí)行操作重啟Arduino IDE并執(zhí)行操作

在搜索框中輸入“RAK”,窗口會自動出現可用的RAKwireless WisBlock Core Boards,選擇“RAKwireless RUI nRF Boards”并安裝。

選擇并安裝 RAKwireless RUI nRF Boards選擇并安裝 RAKwireless RUI nRF Boards

BSP 安裝完成后,根據圖中路徑選擇 RAKwireless WisBlock Core模塊。

選擇 RAKwireless WisBlock Core 模塊選擇 RAKwireless WisBlock Core 模塊

安裝使用到的庫

現在安裝 RAK13600-PN532 庫和 Adafruit bus 庫:

安裝 RAK13600-PN532 庫安裝 RAK13600-PN532 庫

安裝 Adafruit bus 庫安裝 Adafruit bus 庫

代碼開發(fā)

LoRaWAN?部分的初始化,此函數可以初始化協議棧的所有參數,入網方式是OTAA,用戶需要根據自己的頻段,入網參數修改此宏定義,代碼中使用的頻段是 AS923。

/************************************* LoRaWAN band setting: RAK_REGION_EU433 RAK_REGION_CN470 RAK_REGION_RU864 RAK_REGION_IN865 RAK_REGION_EU868 RAK_REGION_US915 RAK_REGION_AU915 RAK_REGION_KR920 RAK_REGION_AS923 *************************************/ #define OTAA_BAND (RAK_REGION_AS923) #define OTAA_DEVEUI {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88} #define OTAA_APPEUI {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88} #define OTAA_APPKEY {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88} void lora_init()

蜂鳴器采用的是 PWM 控制,所以要記住在未使用蜂鳴器時,記得關閉輸出。

pinMode(BUZZER_CONTROL,OUTPUT); noTone(BUZZER_CONTROL);

NFC 芯片初始化代碼,采用 IIC 通信協議,初始化結束后,就可以使用 NFC的刷卡功能了。

nfc.begin(); uint32_t versiondata = nfc.getFirmwareVersion(); if (! versiondata) { Serial.print("Didn't find PN53x board"); while (1); // halt } // Got ok data, print it out! Serial.print("Found chip PN5"); Serial.println((versiondata >> 24) & 0xFF, HEX); Serial.print("Firmware ver. "); Serial.print((versiondata >> 16) & 0xFF, DEC); Serial.print('.'); Serial.println((versiondata >> 8) & 0xFF, DEC); // Set the max number of retry attempts to read from a card // This prevents us from waiting forever for a card, which is // the default behaviour of the PN532. nfc.setPassiveActivationRetries(0xFF); //configure board to read RFID tags nfc.SAMConfig(); Serial.println("Waiting for an ISO14443A card");

每間隔 1 秒循環(huán)讀取是否有 NFC 卡存在,如果讀取 ID 成功,蜂鳴器會響 150 毫秒左右,然后發(fā)送卡 ID 到 LoRaWAN?服務器上。

void loop(void) { boolean success; uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 }; // Buffer to store the returned UID uint8_t uidLength; // Length of the UID (4 or 7 bytes dep ending on ISO14443A card type) // Wait for an ISO14443B type cards (Mifare, etc.). When one is found // 'uid' will be populated with the UID, and uidLength will indicate // if the uid is 4 bytes (Mifare Classic) or 7 bytes (Mifare Ultralight) success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength); if (success) { tone(BUZZER_CONTROL,4000); delay(150); noTone(BUZZER_CONTROL); Serial.println("Found a card!"); Serial.print("UID Length: "); Serial.print(uidLength, DEC); Serial.println(" byte s"); Serial.print("UID Value: "); for (uint8_t i = 0; i < uidLength; i++) { Serial.print(" 0x"); Serial.print(uid[i], HEX); } Serial.println(""); digitalWrite(ledPin1, HIGH); // LED turn on when input pin value is HIGH delay(150); digitalWrite(ledPin1, LOW); // /** Send the data package */ if (api.lorawan.send(uidLength, (uint8_t *) & uid, 2, true, 1)) { Serial.println("Sending is requested"); } else { Serial.println("Sending failed"); } // Wait 1 second before continuing delay(1000); } else { // PN532 probably timed out waiting for a card Serial.println("Timed out waiting for a card"); } }

數據日志

本地串口日志的信息如下所示:

RAK7268內置LoRaWAN?服務器日志:

備注:全部源代碼如下所示

/** @file iso14443a_uid.ino @author rakwireless.com @brief This example will attempt to connect to an ISO14443A card and read card UID @version 0.1 @date 2021-10-14 @copyright Copyright (c) 2021 **/ /**************************************************************************/ #include #include #include // Click here to get the library: http://librarymanager/All#RAK13600-PN532 /************************************* LoRaWAN band setting: RAK_REGION_EU433 RAK_REGION_CN470 RAK_REGION_RU864 RAK_REGION_IN865 RAK_REGION_EU868 RAK_REGION_US915 RAK_REGION_AU915 RAK_REGION_KR920 RAK_REGION_AS923 *************************************/ #define OTAA_BAND (RAK_REGION_AS923) #define OTAA_DEVEUI {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88} #define OTAA_APPEUI {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88} #define OTAA_APPKEY {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88} // If using the breakout or shield with I2C, define just the pins connected #define PN532_IRQ (WB_IO6) #define PN532_RESET (WB_IO5) // Not connected by default on the NFC Shield #define BUZZER_CONTROL WB_IO1 uint8_t ledPin1 = LED_GREEN; uint8_t ledPin2 = LED_BLUE; // Or use this line for a breakout or shield with an I2C connection: NFC_PN532 nfc(PN532_IRQ, PN532_RESET); void lora_init(); void setup(void) { Serial.begin(115200); pinMode(WB_IO2, OUTPUT); digitalWrite(WB_IO2, HIGH); pinMode(BUZZER_CONTROL,OUTPUT); noTone(BUZZER_CONTROL); // initialize the LED pin as an output pinMode(ledPin1, OUTPUT); pinMode(ledPin2, OUTPUT); lora_init(); delay(300); while (!Serial) delay(10); Serial.println("Hello!"); nfc.begin(); uint32_t versiondata = nfc.getFirmwareVersion(); if (! versiondata) { Serial.print("Didn't find PN53x board"); while (1); // halt } // Got ok data, print it out! Serial.print("Found chip PN5"); Serial.println((versiondata >> 24) & 0xFF, HEX); Serial.print("Firmware ver. "); Serial.print((versiondata >> 16) & 0xFF, DEC); Serial.print('.'); Serial.println((versiondata >> 8) & 0xFF, DEC); // Set the max number of retry attempts to read from a card // This prevents us from waiting forever for a card, which is // the default behaviour of the PN532. nfc.setPassiveActivationRetries(0xFF); //configure board to read RFID tags nfc.SAMConfig(); Serial.println("Waiting for an ISO14443A card"); } void loop(void) { boolean success; uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 }; // Buffer to store the returned UID uint8_t uidLength; // Length of the UID (4 or 7 bytes depending on ISO14443A card type) // Wait for an ISO14443B type cards (Mifare, etc.). When one is found // 'uid' will be populated with the UID, and uidLength will indicate // if the uid is 4 bytes (Mifare Classic) or 7 bytes (Mifare Ultralight) success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength); if (success) { tone(BUZZER_CONTROL,4000); delay(150); noTone(BUZZER_CONTROL); Serial.println("Found a card!"); Serial.print("UID Length: "); Serial.print(uidLength, DEC); Serial.println(" bytes"); Serial.print("UID Value: "); for (uint8_t i = 0; i < uidLength; i++) { Serial.print(" 0x"); Serial.print(uid[i], HEX); } Serial.println(""); digitalWrite(ledPin1, HIGH); // LED turn on when input pin value is HIGH delay(150); digitalWrite(ledPin1, LOW); // /** Send the data package */ if (api.lorawan.send(uidLength, (uint8_t *) & uid, 2, true, 1)) { Serial.println("Sending is requested"); } else { Serial.println("Sending failed"); } // Wait 1 second before continuing delay(1000); } else { // PN532 probably timed out waiting for a card Serial.println("Timed out waiting for a card"); } } void lora_init() { // OTAA Device EUI MSB first uint8_t node_device_eui[8] = OTAA_DEVEUI; // OTAA Application EUI MSB first uint8_t node_app_eui[8] = OTAA_APPEUI; // OTAA Application Key MSB first uint8_t node_app_key[16] = OTAA_APPKEY; if (!api.lorawan.appeui.set(node_app_eui, 8)) { Serial.printf("LoRaWan OTAA - set application EUI is incorrect! \r\n"); return; } if (!api.lorawan.appkey.set(node_app_key, 16)) { Serial.printf("LoRaWan OTAA - set application key is incorrect! \r\n"); return; } if (!api.lorawan.deui.set(node_device_eui, 8)) { Serial.printf("LoRaWan OTAA - set device EUI is incorrect! \r\n"); return; } if (!api.lorawan.band.set(OTAA_BAND)) { Serial.printf("LoRaWan OTAA - set band is incorrect! \r\n"); return; } if (!api.lorawan.deviceClass.set(RAK_LORA_CLASS_A)) { Serial.printf("LoRaWan OTAA - set device class is incorrect! \r\n"); return; } if (!api.lorawan.njm.set(RAK_LORA_OTAA)) // Set the network join mode to OTAA { Serial. printf("LoRaWan OTAA - set network join mode is incorrect! \r\n"); return; } if (!api.lorawan.join()) // Join to Gateway { Serial.printf("LoRaWan OTAA - join fail! \r\n"); return; } /** Wait for Join success */ while (api.lorawan.njs.get() == 0) { Serial.print("Wait for LoRaWAN join..."); api.lorawan.join(); delay(10000); } if (!api.lorawan.adr.set(true)) { Serial.printf ("LoRaWan OTAA - set adaptive data rate is incorrect! \r\n"); return; } if (!api.lorawan.rety.set(1)) { Serial.printf("LoRaWan OTAA - set retry times is incorrect! \r\n"); return; } if (!api.lorawan.cfm.set(1)) { Serial.printf("LoRaWan OTAA - set confirm mode is incorrect! \r\n"); return; } /** Check LoRaWan Status*/ Serial.printf("Duty cycle is %s\r\n", api.lorawan.dcs.get()? "ON" : "OFF"); // Check Duty Cycle status Serial.printf("Packet is %s\r\n", api.lorawan.cfm.get()? "CONFIRMED" : "UNCONFIRMED"); // Check Confirm status uint8_t assigned_dev_addr[4] = { 0 }; api.lorawan.daddr.get(assigned_dev_addr, 4); Serial.printf("Device Address is %02X%02X%02X%02X\r\n", assigned_dev_addr[0], assigned_dev_addr[1], assigned_dev_addr[2], assigned_dev_addr[3]); // Check Device Address Serial.println(""); }

聲明:本文內容及配圖由入駐作者撰寫或者入駐合作網站授權轉載。文章觀點僅代表作者本人,不代表電子發(fā)燒友網立場。文章及其配圖僅供工程師學習之用,如有內容侵權或者其他違規(guī)問題,請聯系本站處理。 舉報投訴
  • nfc
    nfc
    +關注

    關注

    59

    文章

    1645

    瀏覽量

    181821
  • RAK
    RAK
    +關注

    關注

    0

    文章

    48

    瀏覽量

    2236
收藏 1人收藏

    評論

    相關推薦

    SE050是否可以完全依靠NFC電源運行?

    手機或讀卡器)運行? - 通過 APDU 命令配置 SE050 的最佳方法是什么 - 使用預裝的小程序還是自定義小程序? - 對于NFC天線設計,有什么優(yōu)化技巧來確保功率穩(wěn)定嗎?
    發(fā)表于 04-10 07:32

    用于LEGIC Advant UID/序列號的NFC讀卡器,為什么無法讀取這些卡的UID/序列號?

    我目前正在開發(fā)小展示柜,其中 LEGIC Advant 卡 (CTC) 的 UID/序列號應由 NFC 閱讀讀取。在當前的設置中,我有
    發(fā)表于 04-02 08:07

    SD讀卡器芯片GL827L規(guī)格書

    SD讀卡器芯片GL827L規(guī)格書
    發(fā)表于 03-24 09:15 ?0次下載

    可以使用基于PN7642的Pegoda智能卡讀卡器根據CCC要求定制NFC應用嗎?

    我可以使用基于 PN7642 的 Pegoda 智能卡讀卡器根據 CCC 要求定制 NFC 應用?
    發(fā)表于 03-21 06:14

    NFC卡的簡單介紹及應用

    NFC張采用RFID技術的IC卡??梢蕴娲罅康腎C卡(包括信用卡)場合商場刷卡、公交卡、門禁管制,車票,門票等等。此種方式下,有
    的頭像 發(fā)表于 03-04 17:05 ?660次閱讀
    <b class='flag-5'>NFC</b>卡的簡單介紹及應用

    液顯ID讀卡器C#小程序開發(fā)

    液顯WIFI無線讀卡器ID-10FC#語音開發(fā)HTTP協議讀卡小程序。讀卡器圖片如下:? ID讀卡器的特點: ?UDP通訊協議,設備主動讀
    的頭像 發(fā)表于 01-10 15:31 ?252次閱讀
    液顯ID<b class='flag-5'>讀卡器</b>C#小程序開發(fā)

    開疆智能Modbus轉Profinet網關連接Modbus讀卡器YW-630MA配置案例

    簡介: Modbus讀卡器YW-630MA是基于RS485總線,遵循Modbus RTU協議的款IC卡讀卡器.。這款讀卡器使為PLC而設計和研發(fā)的新
    的頭像 發(fā)表于 12-23 09:41 ?323次閱讀
    開疆智能Modbus轉Profinet網關連接Modbus<b class='flag-5'>讀卡器</b>YW-630MA配置案例

    PPEC inside 超導 / 磁鐵電源,以搭積木方式快速滿足您的磁鐵供電需求

    1、PPECinside超導/磁鐵電源森木磊石PPECinside超導/磁鐵電源產品通過對超導/磁鐵電源基礎模塊的任意串并聯,使用搭積木方式進行組合,可輕松滿足用戶多樣化的輸出需求。產品采用
    的頭像 發(fā)表于 12-16 18:05 ?108次閱讀
    PPEC inside 超導 / 磁鐵電源,以<b class='flag-5'>搭積木</b>的<b class='flag-5'>方式</b>快速滿足您的磁鐵供電需求

    TRF7970A NFC讀卡器天線多路復用

    電子發(fā)燒友網站提供《TRF7970A NFC讀卡器天線多路復用.pdf》資料免費下載
    發(fā)表于 10-26 11:15 ?1次下載
    TRF7970A <b class='flag-5'>NFC</b><b class='flag-5'>讀卡器</b>天線多路復用

    AGV讀卡器在AGV自動搬運小車上應用方案

    控制根據讀取到的標簽信息,控制小車做出相應的動作,從而實現AGV小車的調度系統(tǒng)功能、站點定位功能。利用RFID技術控制AGV讀卡器來實現站點定位,相對于其他定位方式(慣性定位、超聲波定位、激光定位、二維碼定位等)不僅結構簡單,
    的頭像 發(fā)表于 10-12 17:33 ?478次閱讀
    AGV<b class='flag-5'>讀卡器</b>在AGV自動搬運小車上應用方案

    CI520|13.56MHz非接觸式讀寫NFC讀卡芯片(A卡)

    門禁系統(tǒng)為例,NFC門禁系統(tǒng)通常由NFC讀卡器、
    發(fā)表于 09-11 10:35

    二代身份證識別儀身份證閱讀讀卡器

    掃描儀 工地實名制讀卡器 二代證閱讀 ID/IC讀卡器 NFC讀卡模塊 多合身份證
    發(fā)表于 09-07 15:09

    X-CUBE-NFC4能否用于其他品牌的NFC讀卡器?

    X-CUBE-NFC4能否用于其他品牌的NFC讀卡器,或者通過移植來驅動其他品牌的NFC讀卡器
    發(fā)表于 05-22 06:27

    網絡讀卡器_產品手冊

    電子發(fā)燒友網站提供《網絡讀卡器_產品手冊.pdf》資料免費下載
    發(fā)表于 05-19 09:33 ?0次下載

    電子發(fā)燒友

    中國電子工程師最喜歡的網站

    • 2931785位工程師會員交流學習
    • 獲取您個性化的科技前沿技術信息
    • 參加活動獲取豐厚的禮品