I have connected an Arduino Micro (not Pro Micro) to an Magtek swipe reader.
- Data is connected to pin 3,
- Clock to pin 2
- And swipe_detect to pin 4.
Then I use this lib to read data from the magstripe reader
However, the magstripe reader reads very poorly. Half of the times, the card doesn't even register, because its skipping bits and then the card sentinel and checksums fail.
I suspect, this is because the Arduino Micro isn't processing the interrupts fast enough.
Is it possible to increase the interrupt resolution in some way?
Meaning, having it process interrupts faster? Or does the library process too many things in handle_clock() subroutine and this needs to be fixed?
The datasheet of the reader chip is: https://stripesnoop.sourceforge.net/devel/magtek6516.pdf
Code is:
#include <HID-Project.h>
#include <MagStripe.h>
int buttonpress;
int haspressed;
int tamper;
String code;
static const byte DATA_BUFFER_LEN = 108;
static char data[DATA_BUFFER_LEN];
MagStripe card;
void setup() {
sei();
pinMode(A0, INPUT_PULLUP); // ANALOG INPUT FOR BUTTONS (resistor network)
pinMode(12, OUTPUT); // ACCESS DENIED LED
pinMode(11, OUTPUT); // BUTTON PRESS LED
pinMode(10, OUTPUT); // DOOR UNLOCKED LED
pinMode( 9, OUTPUT); // SOUNDER/BEEPER
pinMode( 8, OUTPUT); // ALARM LED (Default low)
pinMode(13, INPUT_PULLUP); // TAMPER SWITCH, DETECTS IF READER IS BROKEN OFF THE WALL
digitalWrite(12, HIGH);
digitalWrite(11, HIGH);
digitalWrite(10, HIGH);
digitalWrite( 9, HIGH);
BootKeyboard.begin();
card.begin(2);
}
void loop() {
if (card.available()) {
short chars = card.read(data, DATA_BUFFER_LEN);
if (chars > 0) {
digitalWrite(11, LOW);
delay(100);
digitalWrite(11, HIGH);
BootKeyboard.print("CD/" + String(data) + " ");
}
memset(data, 0, DATA_BUFFER_LEN);
}
digitalWrite(11, HIGH);
buttonpress = int(12 - int(int( analogRead(A0) / 62 ) - 3));
delay(50); // BUTTON DEBOUNCE
if (buttonpress != int(12 - int(int( analogRead(A0) / 62 ) - 3))) {
buttonpress = -2;
}
if (buttonpress < 0) {
haspressed = 0;
} else {
if (haspressed == 0) {
digitalWrite(11, LOW);
delay(100);
digitalWrite(11, HIGH);
if (buttonpress == 10) {
code = "/";
}
if ((buttonpress == 11) && (code.length() > 0)) {
BootKeyboard.print("KP" + String(code) + " ");
if (code == "/<**SNIP** TAMPER RESET CODE>") {
tamper = 0;
BootKeyboard.print("TMPRST ");
}
code = "";
}
if ((buttonpress < 10) && (code.length() > 0)) {
code = code + String(buttonpress);
}
}
haspressed = 1;
}
digitalWrite(11, HIGH);
if (digitalRead(13) == 0) {
if (tamper == 0) {
BootKeyboard.print("TMPCLS ");
tamper = 1;
}
if (tamper == 2) {
digitalWrite(8, HIGH);
digitalWrite(9, LOW);
delay(100);
digitalWrite(8, LOW);
digitalWrite(9, HIGH);
}
} else {
if (tamper > 0) {
digitalWrite(8, HIGH);
digitalWrite(9, LOW);
delay(100);
digitalWrite(8, LOW);
digitalWrite(9, HIGH);
if (tamper == 1) {
BootKeyboard.print("TMPTRP ");
tamper = 2;
}
}
}
if (BootKeyboard.getLeds() & 1) {
digitalWrite(12, LOW);
} else {
digitalWrite(12, HIGH);
}
if (BootKeyboard.getLeds() & 2) {
digitalWrite(10, LOW);
} else {
digitalWrite(10, HIGH);
}
if (BootKeyboard.getLeds() & 4) {
delay(100);
digitalWrite(8, HIGH);
digitalWrite(9, LOW);
delay(100);
digitalWrite(8, LOW);
digitalWrite(9, HIGH);
}
}
Only thing deleted/censored from code is the Tamper reset code, which is written as '/' and then a 6 digit code.
interrupt resolution, so you ask about that, instead of asking about the actual problem