I’m building a RFID card system for my high school, where students swipe ID cards (with RFID tags implanted) at Arduinos hooked up to Parallax RFID readers. Using a Wifly shield, the Arduino then notifies the central server that the tag has been swiped (using a HTTP GET request to a php page). The system works fine when the Arduino is plugged into a computer. When it’s running on external power, however (or even a USB cord plugged into the wall), the system initially works fine, but after an hour or so (it’s not always the exact same time period) the Arduino seems to crash: the Wifly shield dissasociates from the wireless network, and the Arduino won’t communicate with the RFID reader (over a serial connection). I’ve tried having the Arduino reset itself at certain intervals, but the problem persists. This has happened on multiple boards, so I don’t think mine is defective. Any help would be greatly appreciated, and the source code is copied below.
Thanks so much.
#include <Client.h>
#include <Configuration.h>
#include <Debug.h>
#include <ParsedStream.h>
#include <Server.h>
#include <SpiUart.h>
#include <WiFly.h>
#include <WiFlyDevice.h>
#include <_Spi.h>
byte server[] = { 10, 100, 0, 36 };
Client client(server, 80);
int val = 0;
char code[10];
int bytesread = 0;
unsigned long time=0;
void software_Reset()
{
asm volatile (" jmp 0");
}
void setup() {
Serial.begin(2400); // RFID reader SOUT pin connected to Serial RX pin at 2400bps
pinMode(2,OUTPUT); // Set digital pin 2 as OUTPUT to connect it to the RFID /ENABLE pin
digitalWrite(2, LOW); // Activate the RFID reader
//Start up the Wifly shield
WiFly.begin();
SpiSerial.print("$$"); delay(100); //readFromWifly();
SpiSerial.println(""); delay(100);
SpiSerial.println("set wlan ssid SSIDHERE"); delay(500);
SpiSerial.println("set wlna phrase PASSPHRASEHERE"); delay(500);
SpiSerial.println("join SSIDHERE"); delay(500);
}
void loop() {
//Every 5 minutes
time = millis() % 300000L;
if(time >= 0 && time <= 500) {
software_Reset();
delay(2000);
}
if(Serial.available() > 0) { // if data available from reader
if((val = Serial.read()) == 10) { // check for header
bytesread = 0;
while(bytesread<10) { // read 10 digit code
if( Serial.available() > 0) {
val = Serial.read();
if((val == 10)||(val == 13)) { // if header or stop bytes before the 10 digit reading
break; // stop reading
}
code[bytesread] = val; // add the digit
bytesread++; // ready to read next digit
}
}
digitalWrite(2, HIGH); //Deactivate the RFID reader
if(bytesread == 10) { // if 10 digit read is complete
//Tell the server
client.connect();
client.print("GET http://10.100.0.36/rfid/toggle.php?studentid=+");
client.print(code);
client.print("&Submit=Submit");
client.println();
bytesread = 0;
client.stop();
delay(3000); // wait for a bit
digitalWrite(2, LOW); // Activate the RFID reader
code[0]='0'; code[1]='0'; code[2]='0'; code[3]='0'; code[4]='0'; code[5]='0'; code[6]='0'; code[7]='0'; code[8]='0'; code[9]='0';
}
}
}
}