Thanks for the fast response and apologies for the lack of information.
We built a device consisting of an Arduino Duomilanove, an ethernet shield, three leds and two buttons and a barcodescanner (http://cgi.ebay.com/ws/eBayISAPI.dll?ViewItem&item=370308068184)
It works as follows:
- Visitor scans card
- Two leds (positioned near the two buttons) light up and the visitor is asked to push one of the buttons
- Visitor pushes button and a php request is send by the ethernetshield containing the answer.
This setup works perfectly for an hour or so and randomly stops scanning the right barcode as I mentioned before. When I reset the Arduino, everything runs fine again…
I already posted some other issues on this forum concerning the ethernet shield, but these problems are fixed. I can imagine there may be some flaws in the way we connected everything. Everything (LEDs, barcode scanner) draws power from the internal 5 volt line from the arduino, which is powered externally by a 9 Volt adapter. I will post the scheme tomorrow. I also can imagine that it is a simple case of cheap electronics (barcode scanner). We are already going to use a watchdog timer to reset the whole thing as soon as the barcodescanner makes a bad read.
The part of the code that reads the barcode information is as follows (datapin is 3, IRQ pin is 2):
// Add a char to the code buffer if possible, silently fails if not possible.
void addChar(char c) {
if (codeBufferI < sizeof codeBuffer) {
codeBuffer[codeBufferI] = c;
codeBufferI++;
}
}
void loop()
{
// Waiting for barcode
Serial.println(“Waiting for barcode”);
keyboard.begin(codeDataPin, codeIRQPin);
boolean done = false;
barcodeCheck = true;
int charCounter = 0;
while (!done) {
if (digitalRead(buttonAPin) == HIGH && digitalRead(buttonBPin) == HIGH) {
delay(500);
if(debugMode){
debugMode=false;
Serial.println(“Exiting debug mode”);
}
else{
debugMode=true;
Serial.println(“Entering debug mode”);
debug(5);
}
}
if (keyboard.available()) {
char c = keyboard.read();
if (c == PS2_ENTER || charCounter > CHARCOUNTER_TERMINATE){
if (c == PS2_ENTER && charCounter == CHARCOUNTER_TERMINATE) {
Serial.print("[Code succesfully scanned]"); // Code succesvol ingelezen.
}
if (charCounter > CHARCOUNTER_TERMINATE) {
Serial.print("[Code over CHARCOUNTER_TERMINATE chars, terminating]");
barcodeCheck = false;
}
if (c == PS2_ENTER && charCounter < CHARCOUNTER_TERMINATE) {
Serial.print("[Code under CHARCOUNTER_TERMINATE chars, terminating]");
barcodeCheck = false;
}
Serial.println();
addChar(’\0’); // End the string
strcpy(code, codeBuffer);
codeBufferI = 0;
Serial.print(code);
Serial.println();
done = true;
}
else {
addChar(c);
Serial.print(c);
}
charCounter++;
}
if (Serial.available() > 0) {
readSerialChar(Serial.read());
}
}
if(barcodeCheck){
debug(1);
}
else{
debug(2);
}
// Waiting for answer
Serial.println(“Waiting for answer”);
digitalWrite(ledAPin, HIGH);
digitalWrite(ledBPin, HIGH);
while (digitalRead(buttonAPin) == LOW && digitalRead(buttonBPin) == LOW) {
delay(10);
}
digitalWrite(ledAPin, LOW);
digitalWrite(ledBPin, LOW);
if (digitalRead(buttonAPin) == HIGH) {
// Geef antwoord “Ja”
doRequest(code, YES);
}
else {
// Geef antwoord “Nee”
doRequest(code, NO);
}
}