My teacher just gave me a NFC tag v1.0 for a project. I have to use my phone to unlock a door.
I searched on internet and I just found this code:
#include "NfcTag.h" #include <Wire.h> NfcTag nfcTag; int led = 5; bool flag = false; bool preFlag = false; void setup(){ Serial.begin(9600); pinMode(led,OUTPUT); nfcTag.init(); } void loop(){ flag = nfcTag.readByte(EEPROM_I2C_LENGTH-1) == 0xff?true:false; if(flag != preFlag){ Serial.println("get remote NFC control signal!"); if(flag == true){ Serial.println("led will light up!"); digitalWrite(led,HIGH); }else{ Serial.println("led will turn dark!"); digitalWrite(led,LOW); } preFlag = flag; } delay(5*1000); }
This come from their wiki: http://wiki.seeed.cc/Grove-NFC_Tag/
I can connect with the phone and use it to change blocks. The problem is that when I try it, the LED just doesn’t work at all. I tried the LED and he is working, I also tried the Digital pin on the Arduino UNO with the LED and it works as well. Also, the monitor doesn’t show any off those printLn.
I used this way to connect them:
SCL – RX
SDA – TX
GND – GND
5V – VCC
I also used a code to debug, but no matter what address I use to readByte, I will always get the number 127 even after using the phone to change it with the app.
#include "NfcTag.h" #include <Wire.h> NfcTag nfcTag; bool flag = false; bool preFlag = false; void setup() { // put your setup code here, to run once: Serial.begin(115200); Serial.println("starting sequence"); nfcTag.init(); } void loop() { // put your main code here, to run repeatedly: Serial.println("checking for nfc"); //flag = nfcTag.readByte(EEPROM_I2C_LENGTH-1) == 0xff?true:false; //Serial1.println(flag); Serial.println(nfcTag.getICNumber()); Serial.println(nfcTag.getAFI()); Serial.println(nfcTag.getRFU()); Serial.println(nfcTag.getMemoryVolume()); Serial.println("result:"); Serial.println(nfcTag.readByte(EEPROM_I2C_LENGTH-1)); //I tried changeing manualy the value, but the output still 127. delay(2000); }
Output:
checking for nfc 127 127 32639 8355711 result: 127
If I could put the LED working, I have already a transistor with a power converter on the exit of the pin5, so the door can be unlocked.
By the way, I don’t know why sometimes the NFC doesn’t work and after some tries it start working again.
Any help will be appreciate π Thanks.