Buongiorno a tutti quanti,
vorrei realizzare con questa scheda della Sparkfun Simultaneous RFID Tag Reader Hookup Guide - SparkFun Learn un sistema che mi permetta di aprire una porta quando rileva un tag RFID.
Ho scaricato il tool URA che mi permette di andare a settare la potenza di trasmissione e ricezione, vari altri parametri e andare a leggere l'ID e scrivere sulle memorie dei tag RFID.
Ho notato che ci sono anche delle librerie che permettono di interfacciare la scheda con un arduino UNO, vi allego l'esempio.
#include <SoftwareSerial.h> //Used for transmitting to the device
SoftwareSerial softSerial(2, 3); //RX, TX
#include "SparkFun_UHF_RFID_Reader.h" //Library for controlling the M6E Nano module
RFID nano; //Create instance
void setup()
{
Serial.begin(115200);
while (!Serial);
Serial.println();
Serial.println("Initializing...");
if (setupNano(38400) == false) //Configure nano to run at 38400bps
{
Serial.println("Module failed to respond. Please check wiring.");
while (1); //Freeze!
}
nano.setRegion(REGION_NORTHAMERICA); //Set to North America
nano.setReadPower(500); //5.00 dBm. Higher values may cause USB port to brown out
//Max Read TX Power is 27.00 dBm and may cause temperature-limit throttling
}
void loop()
{
Serial.println(F("Press a key to read user data"));
while (!Serial.available()); //Wait for user to send a character
Serial.read(); //Throw away the user's character
//Read the data from the tag
byte responseType;
byte myData[64];
byte myDataLength = sizeof(myData); //Tell readUserData to read up to 64 bytes
responseType = nano.readUserData(myData, myDataLength); //readUserData will modify myDataLength to the actual # of bytes read
if (responseType == RESPONSE_SUCCESS)
{
//Print User Data
Serial.print(F("Size ["));
Serial.print(myDataLength);
Serial.print(F("] User data["));
for (byte x = 0 ; x < myDataLength ; x++)
{
if (myData[x] < 0x10) Serial.print(F("0"));
Serial.print(myData[x], HEX);
Serial.print(F(" "));
}
Serial.println(F("]"));
}
else
Serial.println(F("Error reading tag data"));
}
//Gracefully handles a reader that is already configured and already reading continuously
//Because Stream does not have a .begin() we have to do this outside the library
boolean setupNano(long baudRate)
{
nano.begin(softSerial); //Tell the library to communicate over software serial port
//Test to see if we are already connected to a module
//This would be the case if the Arduino has been reprogrammed and the module has stayed powered
softSerial.begin(baudRate); //For this test, assume module is already at our desired baud rate
while (!softSerial); //Wait for port to open
//About 200ms from power on the module will send its firmware version at 115200. We need to ignore this.
while (softSerial.available()) softSerial.read();
nano.getVersion();
if (nano.msg[0] == ERROR_WRONG_OPCODE_RESPONSE)
{
//This happens if the baud rate is correct but the module is doing a ccontinuous read
nano.stopReading();
Serial.println(F("Module continuously reading. Asking it to stop..."));
delay(1500);
}
else
{
//The module did not respond so assume it's just been powered on and communicating at 115200bps
softSerial.begin(115200); //Start software serial at 115200
nano.setBaud(baudRate); //Tell the module to go to the chosen baud rate. Ignore the response msg
softSerial.begin(baudRate); //Start the software serial port, this time at user's chosen baud rate
}
//Test the connection
nano.getVersion();
if (nano.msg[0] != ALL_GOOD) return (false); //Something is not right
//The M6E has these settings no matter what
nano.setTagProtocol(); //Set protocol to GEN2
nano.setAntennaPort(); //Set TX/RX antenna ports to 1
return (true); //We are ready to rock
}
Quello che vorrei fare con arduino e che vi chiedo un aiuto, sarebbe di settare un pin digitale di arduino HIGH quanto la scheda rileva un tag che ha la stessa user memory memorizzata su arduino.
Vi allego lo sketch.
Vi ringrazio per quanto riuscirete a fare.
Cordiali saluti
Davide Raspanti
Example4_Read_User_Data.ino (3.64 KB)