LoginSignup
0
0

More than 1 year has passed since last update.

PN532 NFC RFID module + elechouse を ESP32 Arduino で試す

Last updated at Posted at 2022-03-27

(Felica/Mifare/NFC チャレンジシリーズ) その他の記事はこちら 「Felica/Mifare/NFC でいろいろ実験」
https://qiita.com/nanbuwks/items/1f416d6e45a87250ee0a


「PN532 NFC RFID module を Arduino UNO で読む」
https://qiita.com/nanbuwks/items/42f639e7eec928181298

では Arduino UNO を使いましたが、ESP32 で同様に使えるか試してみます。

上記記事でライブラリをいくつか試してみましtが、

FeliCa を使う場合は elechouse 一択のようです。

と書きました。

以下は elechouse の PN532 ライブラリを ESP32 で使えるか試した結果です

環境

  • Arduino 1.8.10 Linux 版
    • portable 化済
  • esp32 by Espressif Systems Version 1.0.3
  • Ubuntu Linux 20.04 AMD64
  • NFC library for Arduino
  • WEMOS LOLIN32
    • ( ≒ ESP32 DevKitC )

ライブラリ修正

「ESP32 Arduino で error: 'boolean' does not name a type」
https://qiita.com/nanbuwks/items/d62157f6fccdbed54f86

のように、PN532_SPI.cpp を直しておきます。

スケッチ

Mifare カードを読むサンプルスケッチで試します。
「ファイル」-「スケッチ例」-「カスタムライブラリのスケッチ例」-「PN532」-「ReadMifare」を選びます。

スイッチ設定

以下の接続時には、それぞれ PN532 NFC RFID module 上のスイッチを接続に合わせて設定しています。

I2C接続

IMG_20220321_163049.jpg

ESP32 PN532 NFC Module
GND GND
3V3 VCC
SDA/21 SDA
SCL/21 SCL

実行結果



Hello!
Found chip PN532
Firmware ver. 1.6
Waiting for an ISO14443A Card ...
Found an ISO14443A card
  UID Length: 4 bytes
  UID Value:  D3 6A 93 05

Seems to be a Mifare Classic card (4 byte UID)
Trying to authenticate block 4 with default KEYA value
Sector 1 (Blocks 4..7) has been authenticated
Reading Block 4:
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................

OK

SPI接続

IMG_20220321_162654.jpg

ESP32 PN532 NFC Module
3V3 VCC
(NC) RSTQ
GND GND
(NC) IRQ
MISO/19 MISO
MOSI/23 MOSI
SCK/18 SCK
SS/5/LED SS

接続設定に合わせて、スケッチの該当箇所を以下のように直します。


#if 1
  #include <SPI.h>
  #include <PN532_SPI.h>
  #include "PN532.h"

  PN532_SPI pn532spi(SPI, 5);
  PN532 nfc(pn532spi);
#elif 0
.
.
.

実行結果


Hello!
Found chip PN532
Firmware ver. 1.6
Waiting for an ISO14443A Card ...
Found an ISO14443A card
  UID Length: 4 bytes
  UID Value:  D3 6A 93 05

Seems to be a Mifare Classic card (4 byte UID)
Trying to authenticate block 4 with default KEYA value
Sector 1 (Blocks 4..7) has been authenticated
Reading Block 4:
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................

動きました

シリアル接続

image.png

ESP32 PN532 NFC Module
GND GND
3V3 VCC
16 (Serial2 RX) TXD
17 (Serial2 TX) RXD


#if 0
  #include <SPI.h>
  #include <PN532_SPI.h>
  #include "PN532.h"

  PN532_SPI pn532spi(SPI, 5);
  PN532 nfc(pn532spi);
#elif 1
  #include <PN532_HSU.h>
  #include <PN532.h>
      
  PN532_HSU pn532hsu(Serial2);
  PN532 nfc(pn532hsu);
#else 
...

動きました


Hello!
Found chip PN532
Firmware ver. 1.6
Waiting for an ISO14443A Card ...
Found an ISO14443A card
  UID Length: 4 bytes
  UID Value:  D3 6A 93 05

Seems to be a Mifare Classic card (4 byte UID)
Trying to authenticate block 4 with default KEYA value
Sector 1 (Blocks 4..7) has been authenticated
Reading Block 4:
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0