Hello,
So I'm using an Arduino UNO with an Adafruit SD shield and RFID shield. I'm trying to store the value of the RFID tag onto the SD card. Anytime I try to use the shields together I cannot get them to run at the same time. Is this a code problem or a hardware problem?
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_PN532.h>
#include <SD.h>
#include <Arduino.h>
#include <Wire.h>
#include "RTClib.h"
#define PN532_SCK (2)
#define PN532_MOSI (3)
#define PN532_SS (4)
#define PN532_MISO (5)
#if defined(ARDUINO_ARCH_SAMD)
#define Serial SerialUSB
#endif
#define PN532_IRQ (2)
#define PN532_RESET (3)
Adafruit_PN532 nfc(PN532_IRQ, PN532_RESET);
RTC_Millis rtc;
const int chipSelect = 10;
String inputString = "";
const int id = 7;
void setup(void) {
Serial.begin(115200);
nfc.begin();
uint32_t versiondata = nfc.getFirmwareVersion();
if (! versiondata) {
Serial.print("PN53_NF");
while (1); // halt
}
nfc.setPassiveActivationRetries(0xFF);
// configure board to read RFID tags
nfc.SAMConfig();
#ifdef ESP8266
Wire.pins(2, 14);
#endif
rtc.begin(DateTime(F(__DATE__), F(__TIME__)));
inputString.reserve(200);
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
return;
}
Serial.println("card initialized.");
}
void loop(void) {
boolean success;
uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 };
uint8_t uidLength;
success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength);
if (success) {
for (uint8_t i = 0; i < uidLength; i++)
{
Serial.print(uid[i], HEX);
}
File dataFile = SD.open("datalog.txt", FILE_WRITE);
if (dataFile) {
DateTime now = rtc.now();
dataFile.print(now.year(), DEC);
dataFile.print('/');
dataFile.print(now.month(), DEC);
dataFile.print('/');
dataFile.print(now.day(), DEC);
dataFile.print(' ');
dataFile.print(now.hour(), DEC);
dataFile.print(':');
dataFile.print(now.minute(), DEC);
dataFile.print(':');
dataFile.print(now.second(), DEC);
dataFile.print(" ");
dataFile.print(uid[0]);
dataFile.print(uid[1]);
dataFile.print(uid[2]);
dataFile.print(uid[3]);
dataFile.print(uid[4]);
dataFile.print(uid[5]);
dataFile.println(uid[6]);
dataFile.close();
}
else {
Serial.println("Error Opening File");
}
inputString = "";
}
else
{
Serial.println("CNTREAD");
}
}