前提・実現したいこと
RFID-RC522 をArduinoで使い複数のタグを区別したいです
特に参考サイトの上2つのサイトを実現したいです
###参考サイト
Arduinoで複数のNFCタグを区別する
https://qiita.com/yuji_miyano/items/f00f9e3f2edc8025b704
非接触ICタグで遊ぼう!ArduinoでRFIDリーダRC522を使う方法
https://dotstud.io/blog/arduino-use-rfid-reader/
ESP-WROOM-02とRFID-RC522で非接触Lチカ
https://qiita.com/daxanya1/items/b9c2b971a946c8bf063e
Arduinoで近距離無線通信 RFID-RC522 NFC
https://bokunimo.net/arduino/rfid.html
発生している問題・エラーメッセージ
特に変更した所は
1、UIDを自分の持っているIDに変更
2、IDタグが3つしかないのでその他は削除(サイトは7つのID)
シリアルモニターの画面が下記の状態からカードをかざしても何も変化ありません
Firmware Version: 0x92 = v2.0 Scan PICC to see UID, SAK, type, and data blocks... 00 00 00 00 00 00
該当のソースコード
#include <SPI.h> #include <MFRC522.h> #define RST_PIN 9 // Configurable, see typical pin layout above #define SS_PIN 10 // Configurable, see typical pin layout above #define UID1 "22 5S 8K 88" // DumpInfo.inoで読み取ったUIDを記入 #define UID2 "22 25 A1 1E" // DumpInfo.inoで読み取ったUIDを記入 #define UID3 "1D DB 88 D7" // DumpInfo.inoで読み取ったUIDを記入 MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance MFRC522::MIFARE_Key key; void setup() { Serial.begin(9600); // Initialize serial communications with the PC while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4) SPI.begin(); // Init SPI bus mfrc522.PCD_Init(); // Init MFRC522 mfrc522.PCD_DumpVersionToSerial(); // Show details of PCD - MFRC522 Card Reader details Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks...")); dump_byte_array(key.keyByte, MFRC522::MF_KEY_SIZE); } void loop() { // Look for new cards if ( ! mfrc522.PICC_IsNewCardPresent()) { return; } // Select one of the cards if ( ! mfrc522.PICC_ReadCardSerial()) { return; } String strBuf[mfrc522.uid.size]; for (byte i = 0; i < mfrc522.uid.size; i++) { strBuf[i] = String(mfrc522.uid.uidByte[i], HEX); // (E)using a constant integer if(strBuf[i].length() == 1){ // 1桁の場合は先頭に0を追加 strBuf[i] = "0" + strBuf[i]; } } String strUID = strBuf[0] + " " + strBuf[1] + " " + strBuf[2] + " " + strBuf[3] + " " + strBuf[4] + " " + strBuf[5] + " " + strBuf[6]; if ( strUID.equalsIgnoreCase(UID1) ){ // 大文字小文字関係なく比較 Serial.println("1"); } else if ( strUID.equalsIgnoreCase(UID2) ){ Serial.println("2"); } else if ( strUID.equalsIgnoreCase(UID3) ){ Serial.println("3"); } } /** * Helper routine to dump a byte array as hex values to Serial. */ void dump_byte_array(byte *buffer, byte bufferSize) { for (byte i = 0; i < bufferSize; i++) { Serial.print(buffer[i] < 0x10 ? " 0" : " "); Serial.print(buffer[i], HEX); } }
試したこと
1、UIDの記述の仕方が間違っているのか検討してみたのですが…何も変わらず
2、サンプルプログラムを動かしてタグの情報を読み取る事は出来ていると思いますので配線処理で間違っているとは考えにくいと思います…
補足情報(FW/ツールのバージョンなど)
Arduino 1.8.5
Arduino nano
windows 10