I have Arduino Duemilanove + Wiegand26 reader Smartec ST-PR160EK (pic above) and my task is to write sketch which is able to distinguish key press from card touch. Result must be sended in com port like "button: 5" or "card: 123456". For working with Wiegand I use this library.
When card is presented you got 26 bytes. E.g. when you got tag id #7357893 it means that there was such sequence of bytes: 111000001000101110001011. Example sketch here.
At particular reader model frequency of data is 416 Hz (T~2.59 ms):
Empirically I find out that minimum delay between pressing two buttons is 300 ms (let's call it "interframe delay")
Difficulties are:
All data is sending by same wire at same port. So now way to combine two example sketches listed below - anyway it will trigger if(reader2Count>=8) condition at loop().
At now I think the most perspective and universal solution is to use timer and check is reader2Count variable changed during 3 ms (not necessarily 3ms - any time that is > T and < "interframe delay" is ok). If no change - start to process collected bites. I wrote a working sketch but I have no idea why it's working only once (for next time use need to reset controller).
You use the millis() timer to recover the current time count and store that when ever something is received by the Weagand interface. Then you need to look at this and see if a time has elapsed before you decide if it is a card or a digit.
button code can be either 7 or 8 bit
I doubt it, I think there might be a leading zero suppression that is causing you to think that.
Link fixed, please take a look. I saw that immediately after posting, but was able to correct only after 5 min cause I'm newbie at this forum.
Grumpy_Mike:
You use the millis() timer to recover the current time count and store that when ever something is received by the Weagand interface. Then you need to look at this and see if a time has elapsed before you decide if it is a card or a digit.
You mean that timer was overflow? I don't think so. I use this library for setting timer and as I understood it use millis(). This number will overflow (go back to zero) after approximately 50 days.
Grumpy_Mike:
I doubt it, I think there might be a leading zero suppression that is causing you to think that.
I'm sure in it, there is no leading zero at protocol. Wiegand26 lib that I use collects data this way (when no data pin is HIGH):
No I never said that at all. I suggested using the millis() NOT the timer library.
I'm sure in it, there is no leading zero at protocol.
Sorry that makes no sense. I talked about leading zero suppression.
However I have looked at your code but can not understand what the timer library is doing. Have you read this How to use this forum
It asks you to post links to any library you use so that others can reproduce what you have done.
Dear Mike, seems like you missed something. I posted links to all libraries that I use. For your convenience I can do it once again: http://playground.arduino.cc/Code/Timer