Hi there,
I am having problems using a NFC Shield from Seeed studio (v2.1) in combination with an Ethternet shield w5100.
Last year I managed to get it to work but now I'm trying to do exactly the same but now it does not work anymore...
My computer got formatted so the Arduino software and libraries got lost, so I downloaded everything I needed and changed some things in the code.
Here is my setup:
First Arduino Uno R3 then Seeed studio NFC shield v2.1 and on top the Ethernet shield w5100.
The NFC shield CS is modified by scraping the connection to D10 on the SS selector. So pin 9 is the SPI select pin.
What does work and what not?
- When I detach the Ethernet shield the NFC Shield is being found and works
- With the Ethernet shield on top, the ethernet shield works but the NFC chip/shield is not found
Here is my code, any help is welcome!
#include <PN532.h>
#include <SPI.h>
#include <Ethernet.h>
/*Chip select pin can be connected to D10 or D9 which is hareware optional*/
#define PN532_CS 9
#define ETHNET_CS 10
#define SD_CS 4
PN532 nfc(PN532_CS);
String game = "chest";
String parameter1 = "reference=" + game;
String parameter2 = "&serial=";
String parameter = parameter1 + parameter2;
char tagIdString [11]= "0271778560";
/* Network Settings */
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x3B, 0xB9 }; // MAC address
IPAddress ip(192,168,192,188); // Static IP if DHCP fails
IPAddress server(192,168,192,22); // numeric IP for Google (no DNS)
byte client_server[] = { 192, 168, 192, 22 }; //Manual setup only
int client_port = 80;
EthernetClient client;
/* Chip select routine */
void spiSelect(int CS) {
// disable all SPI
digitalWrite(PN532_CS,HIGH);
digitalWrite(ETHNET_CS,HIGH);
// enable the chip we want
digitalWrite(CS,LOW);
delay(1000);
}
/* Startup routine */
void setup(void) {
/* Start serial output */
Serial.begin(57600);
Serial.println("Arduino Powered On");
pinMode(PN532_CS,OUTPUT);
pinMode(ETHNET_CS,OUTPUT);
pinMode(SD_CS,OUTPUT);
// disable SD
digitalWrite(SD_CS,HIGH);
// disable the ethernet SPI here so just NFC is active
spiSelect(PN532_CS);
// NFC uses LSB first so we have to explicitly set that
SPI.setBitOrder(LSBFIRST);
/* Initialise NFC reader */
nfc.backupSPIConf();
nfc.begin();
nfc.RFConfiguration(0x14); // default is 0xFF (try forever; ultimately it does time out but after a long while
// modifies NFC library to set up a timeout while searching for RFID tags
uint32_t versiondata = nfc.getFirmwareVersion();
if (! versiondata) {
Serial.print("Didn't find PN53x board");
while (1); // halt
}
Serial.print("Found chip PN5");
Serial.println((versiondata>>24) & 0xFF, HEX);
Serial.print("Firmware ver. ");
Serial.print((versiondata>>16) & 0xFF, DEC);
Serial.print('.');
Serial.println((versiondata>>8) & 0xFF, DEC);
Serial.print("Supports ");
Serial.println(versiondata & 0xFF, HEX);
nfc.SAMConfig();
// disable the NFC SPI here so just network is active
spiSelect(ETHNET_CS);
// ethernet uses the default MSB first so making sure that is set
SPI.setBitOrder(MSBFIRST);
/* Initialise Network */
Serial.println("Sending DHCP request");
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
Serial.println("Setting static IP address instead");
Ethernet.begin(mac, ip);
Serial.print("Arduino IP is ");
Serial.println(Ethernet.localIP());
}
else {
Serial.println("Obtained DHCP lease");
Serial.print("Arduino IP is ");
Serial.println(Ethernet.localIP());
}
/* Configure web client */
if (client.connect(client_server, client_port)) {
Serial.println(F("Making HTTP Call"));
client.println(F("POST /app_dev.php/api/v1/scoreboards.json HTTP/1.1"));
client.println(F("Host: 192.168.192.22"));
client.println(F("Content-Type: application/x-www-form-urlencoded"));
client.print(F("Content-Length: "));
String total_parameter = parameter + tagIdString;
const char *str = total_parameter.c_str();
Serial.println(str);
client.println(strlen(str));
client.println(F("Connection: close\r\n"));
client.println(str);
} else {
Serial.println("Connection failed");
}
}
/* Main program loop */
void loop(void) {
// disable the ethernet SPI here so just NFC is active
spiSelect(PN532_CS);
// NFC uses LSB first so we have to explicitly set that
SPI.setBitOrder(LSBFIRST);
/* look for MiFare type cards */
uint32_t id;
id = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A);
if (id != 0) {
Serial.print("Read card #");
Serial.println(id);
}
// disable the NFC SPI here so just network is active
spiSelect(ETHNET_CS);
// ethernet uses the default MSB first so we need to switch back
SPI.setBitOrder(MSBFIRST);
// check ethernet is still working
Serial.print("Arduino IP is ");
Serial.println(Ethernet.localIP());
}