A simple card reader using two pins of the Arduino.
A travel in time to the old days when programs were typed on punch cards.
Each card represents a Byte, characters can be seen in the terminal of the Arduino IDE .
In the following diagram you can see the timing.
When the CLOCK changes from LOW to HIGH the DATA is loaded.
The Sketch:
/* PunchCardReader Arduining.com 29/06/2011 */ #define clock 8 //clock input in digital pin 8. #define data 9 //data input in digital pin 9. byte Byte; //store the incoming 8 bits. void setup() { digitalWrite(clock, HIGH); // Connect Pull-Up resistor. digitalWrite(data, HIGH); // Connect Pull-Up resistor. Serial.begin(9600); } void loop() { Byte=0; while(digitalRead(clock)==0); //wait for card in(rising edge). delay(20); //debounce for(int i=0; i<8 ;i++){ while(digitalRead(clock)==1){}; //wait for a falling edge. delay(20); //debounce while(digitalRead(clock)==0); //wait for a raising edge. delay(20); //debounce Byte= Byte << 1; Byte= Byte | !(digitalRead(data)); Serial.print(!(digitalRead(data))); } while(digitalRead(clock)==1){}; //wait for card out. delay(20); //debounce Serial.print(" = "); Serial.println(Byte,BYTE); }
Enjoy the Youtube presentation:
I’m having problem using your code on Arduino 1.0.2.
The error says: the keyword ‘BYTE’ is no longer supported
What should I do?
I also have Arduino 0.22 because some libraries are no supported by the 1.0 and later versions of the IDE
Replace::
Serial.println(Byte, BYTE);
By:
Serial.write(Byte);
Serial.println(“”); // To send a LF
Will be desirable that the Arduino environment keep compiler backwards compatibility to avoid
rewriting old code. I think Arduino 1.0.3 solve this, I have to check.
Replace::
void setup() {
digitalWrite(clock, HIGH); // Connect Pull-Up resistor.
digitalWrite(data, HIGH); // Connect Pull-Up resistor.
Serial.begin(9600);
}
By:
void setup() {
pinMode(strobe, INPUT_PULLUP);
pinMode(databit, INPUT_PULLUP);
Serial.begin(115200); //use 115200 for stellaris of texas instrument
}
Hi, very nice project! Is it possible to use a more user friendly java text interface for the output? I’m gonna use this for educational purpose, and I’d like to show the output more stylish, you know?
Thanks.
I noticed that the holes for the clock line are located slightly forward of the holes for the data on the cards. Why is that?
When the CLOCK paperclip open the contact the DATA paperclip is in the middle of the data hole area. In this way a correct reading is ensured.