99精品伊人亚洲|最近国产中文炮友|九草在线视频支援|AV网站大全最新|美女黄片免费观看|国产精品资源视频|精彩无码视频一区|91大神在线后入|伊人终合在线播放|久草综合久久中文

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

完善資料讓更多小伙伴認(rèn)識你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

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

瑞科慧聯(lián)(RAK) ? 2022-07-28 14:17 ? 次閱讀
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

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

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

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

2、采用LoRaWAN?無線傳輸?shù)淖x卡器安裝部署方便

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

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

搭建 LoRaWAN?NFC 讀卡器概述

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

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

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

硬件電路搭建

硬件準(zhǔn)備

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

RAK4631 模塊、RAK19007 底板、RAK13600 NFC 讀卡器等硬件準(zhǔn)備RAK4631 模塊、RAK19007 底板、RAK13600 NFC 讀卡器等硬件準(zhǔn)備

硬件組裝

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

連接NFC天線、LoRa?天線、藍(lán)牙天線,并安裝至外殼中。硬件組裝完成之后就可以進(jìn)行軟件設(shè)置。

軟件環(huán)境搭建

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

打開 Arduino IDE,進(jìn)入“文件 > 首選項”

打開 Arduino IDE打開 Arduino IDE

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

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

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

在Arduino IDE上粘貼復(fù)制好的URL在Arduino IDE上粘貼復(fù)制好的URL

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

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

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

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

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

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

安裝使用到的庫

現(xiàn)在安裝 RAK13600-PN532 庫和 Adafruit bus 庫:

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

安裝 Adafruit bus 庫安裝 Adafruit bus 庫

代碼開發(fā)

LoRaWAN?部分的初始化,此函數(shù)可以初始化協(xié)議棧的所有參數(shù),入網(wǎng)方式是OTAA,用戶需要根據(jù)自己的頻段,入網(wǎng)參數(shù)修改此宏定義,代碼中使用的頻段是 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 控制,所以要記住在未使用蜂鳴器時,記得關(guān)閉輸出。

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

NFC 芯片初始化代碼,采用 IIC 通信協(xié)議,初始化結(jié)束后,就可以使用 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?服務(wù)器上。

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"); } }

數(shù)據(jù)日志

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

RAK7268內(nèi)置LoRaWAN?服務(wù)器日志:

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

/** @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(""); }

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

    關(guān)注

    61

    文章

    1666

    瀏覽量

    182631
  • RAK
    RAK
    +關(guān)注

    關(guān)注

    0

    文章

    48

    瀏覽量

    2318
收藏 人收藏
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

    評論

    相關(guān)推薦
    熱點推薦

    硬核跨界!CAN轉(zhuǎn)EtherCAT:門禁讀卡器的“破壁者”來了

    新老設(shè)備,統(tǒng)統(tǒng)接入同網(wǎng)絡(luò); 節(jié)能暗器:聯(lián)動控制燈光、空調(diào),能耗優(yōu)化悄悄進(jìn)行; 遠(yuǎn)程操控:手機(jī)/電腦鍵調(diào)試,設(shè)備維護(hù)不再“跑斷腿”。 某大廈改造門禁系統(tǒng),舊讀卡器是CAN協(xié)議“釘子戶”,新中控卻只認(rèn)
    發(fā)表于 07-16 14:24

    PAE 電鍍行車讀卡器,電鍍行業(yè)的得力助手

    主要是向大家推薦PAE電鍍行車讀卡器
    的頭像 發(fā)表于 06-24 14:53 ?167次閱讀

    汽車數(shù)字鑰匙新選擇:意法半導(dǎo)體ST25R系列車規(guī)NFC讀卡器

    意法半導(dǎo)體(STMicroelectronics)最新推出的ST25R500和ST25R501車規(guī)NFC讀卡器,不僅性能卓越,還專為汽車應(yīng)用設(shè)計,滿足車聯(lián)網(wǎng)聯(lián)盟(CCC)和無線充電聯(lián)盟(WPC)的嚴(yán)格標(biāo)準(zhǔn)。那么,這兩款新品究竟有哪些亮點?它們?nèi)绾沃ζ嚁?shù)字鑰匙和無線充電
    的頭像 發(fā)表于 06-24 14:02 ?1022次閱讀
    汽車數(shù)字鑰匙新選擇:意法半導(dǎo)體ST25R系列車規(guī)<b class='flag-5'>NFC</b><b class='flag-5'>讀卡器</b>

    DD3118 高集成度讀卡器控制芯片數(shù)據(jù)手冊

    DD3118是款采用40納米低功耗技術(shù)制造的高性能、高集成度讀卡器控制芯?片,專為讀卡器設(shè)計。作為讀卡器的核心功能模塊,DD3118支持USB?3.0、SD ?3.0和eMMC?4.
    發(fā)表于 06-16 16:14 ?1次下載

    DD3118規(guī)格書|DD3118說明書|3.0讀卡器芯片規(guī)格書

    DD3118是款高性能、高度集成的讀卡器控制芯片,DD3118采用40nm低功耗技術(shù)制造,專為讀卡器或者讀卡方案設(shè)計的芯片。DD3118作為讀卡器
    發(fā)表于 06-12 17:40 ?0次下載

    MAX14502高速USB至SD讀卡器,提供旁路控制技術(shù)手冊

    MAX14502 USB轉(zhuǎn)SD? 卡讀卡器為支持全速USB通信(12Mbps)且?guī)в?b class='flag-5'>一或兩SD卡插槽的便攜式設(shè)備,提供了將其升級為高速(480Mbps)USB卡
    的頭像 發(fā)表于 05-22 11:32 ?248次閱讀

    意法半導(dǎo)體ST25R系列NFC讀卡器新增車規(guī)產(chǎn)品

    意法半導(dǎo)體ST25R系列NFC讀卡器推出兩款喚醒速度和檢測距離俱佳的車規(guī)新產(chǎn)品,提升用戶體驗。ST25R500和ST25R501符合車聯(lián)網(wǎng)聯(lián)盟(CCC)和無線充電聯(lián)盟(Wireless Power Consortium)兩大標(biāo)準(zhǔn)的要求,目標(biāo)應(yīng)用瞄準(zhǔn)汽車數(shù)字鑰匙、設(shè)備配對、
    的頭像 發(fā)表于 05-14 09:44 ?479次閱讀

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

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

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

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

    可以使用基于PN7642的Pegoda智能卡讀卡器根據(jù)CCC要求定制NFC應(yīng)用嗎?

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

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

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

    TRF7970A NFC讀卡器天線多路復(fù)用

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

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

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

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

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