Shop OBEX P1 Docs P2 Docs Learn Events
Wiegand Input — Parallax Forums

Wiegand Input

JumpkickJumpkick Posts: 19
edited 2008-12-02 07:49 in BASIC Stamp
Is anyone familiar with designing some software to·read the Wiegand protocol?·I have purchased a Basic Stamp Discovery Kit (USB) with a BS2 microcontroller.

I have tried the following:

I have DATA0 in input0, DATA1 in input1.

serialData VAR Byte
SHIFTIN IN0, IN1&IN0, MSBPRE, [noparse][[/noparse]serialData]

I get different bytes when an actual card is read, but the bytes are never consistent with something that I would consider being a valid Facility Code and Card Number.

Can someone please help?
«1

Comments

  • BeanBean Posts: 8,129
    edited 2006-02-10 16:41
    I not a BS2 expert, but I don't think it can read wiegand data.

    The problem is that the weigand device provides that clock and the BS2 SHIFTIN command the BS2 provides the clock.
    Using some kind of external "helper" chip you could probably do it.

    I have read wiegand the the SX chip using SX/B.

    Wiegand format:

    Both DATA0 and DATA1 are normally high.
    IF DATA0 goes low for about 40uSec then a 0 is clocked in.
    IF DATA1 goes low for about 40uSec then a 1 is clocked in.
    There is about 2mSec between pulses.

    With one of the faster stamps you might be able to pull it off, but putting a diode and cap on each of the lines to act as a "pulse stretcher" so the stamp has a chance to see the low pulse.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "SX-Video·Module" Now available from Parallax for only $28.95

    http://www.parallax.com/detail.asp?product_id=30012

    "SX-Video OSD module" Now available from Parallax for only·$49.95
    http://www.parallax.com/detail.asp?product_id=30015

    Product web site: www.sxvm.com

    "Ability may get you to the top, but it takes character to keep you there."


    Post Edited (Bean (Hitt Consulting)) : 2/10/2006 4:46:37 PM GMT
  • JumpkickJumpkick Posts: 19
    edited 2006-02-10 16:45
    I am looking to get some SX-28 chips soon. Do you happen to have your Wiegand SX/B code available?
  • BeanBean Posts: 8,129
    edited 2006-02-10 16:47
    You'll need the SX-Key or SX-blitz to program the SX-28 chips.
    I'll try to find the code for you.

    [noparse][[/noparse]edit]
    This is probably not the place to be posting SX/B code. Maybe one of the moderators will move the thread if they feel so inclined.

      ' Edited Feb 10, 2006 12:38PM EST
     
      Data0 VAR RA.0
      DATA1 VAR RA.1
     
      gotID VAR Bit
      bitcnt VAR Byte
      byteCnt VAR Byte
      rfid VAR Byte (3)
    
     
      gotID = 0
      bitCnt = 255 ' Skip first parity bit
      byteCnt = 0
    
     
    Reader_Wait:
      IF Data0 = 1 THEN
        IF  Data1 = 1 THEN Reader_Wait
      ENDIF
      IF Data1 = 0 THEN 
        dataBit = 1
        DO
        LOOP UNTIL Data1 = 1
      ELSE
        dataBit = 0
        DO
        LOOP UNTIL Data0 = 1
      ENDIF
      IF bitCnt <> 255 THEN
        rfid(byteCnt) = rfid(byteCnt) << 1
        rfid(byteCnt).0 = dataBit
      ENDIF
      INC bitCnt
      IF bitCnt = 8 THEN
        bitCnt = 0
        INC byteCnt
      ENDIF
      IF byteCnt < 3 THEN Reader_Wait
      gotID = 1
    
    

    This is NOT a complete program, just a snippet to show reading wiegand data.
    Sorry about all the comments too [noparse];)[/noparse]

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "SX-Video·Module" Now available from Parallax for only $28.95

    http://www.parallax.com/detail.asp?product_id=30012

    "SX-Video OSD module" Now available from Parallax for only·$49.95
    http://www.parallax.com/detail.asp?product_id=30015

    Product web site: www.sxvm.com

    "Ability may get you to the top, but it takes character to keep you there."


    Post Edited (Bean (Hitt Consulting)) : 2/10/2006 5:39:38 PM GMT
  • JumpkickJumpkick Posts: 19
    edited 2006-02-10 16:52
    That would be much appreciated.
  • JumpkickJumpkick Posts: 19
    edited 2006-02-14 23:43
    Using the code you supplied I am unable to get any consistent data. I have an LED hooked up to blink when 3 bytes are received, but without anything being read by the reader, the LED still blinks. I have the following code:

    '
    ' Device Settings
    '

    DEVICE SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
    FREQ 4_000_000


    '
    ' IO Pins
    '

    DATA0 VAR RA.0
    DATA1 VAR RA.1
    GREENLED VAR RC.7


    '
    ' Variables
    '

    dataBit VAR Bit
    bitcnt VAR Byte
    byteCnt VAR Byte
    rfid VAR Byte (3)

    bitCnt = 255 ' Skip first parity bit
    byteCnt = 0


    ' =========================================================================
    PROGRAM Start
    ' =========================================================================

    '
    ' Program Code
    '

    Start:
    GOTO Main

    Main:
    'Check Low On Data0
    IF Data1 = 0 THEN
    'Wait For High On Data1
    dataBit = 1
    DO
    LOOP UNTIL Data1 = 1
    ELSE
    'Wait For High On Data0
    dataBit = 0
    DO
    LOOP UNTIL Data0 = 1
    ENDIF

    'Check For Parity Bit
    IF bitCnt <> 255 THEN
    rfid(byteCnt) = rfid(byteCnt) << 1
    rfid(byteCnt).0 = dataBit
    ENDIF

    'Increase Bit Count
    INC bitCnt

    '8 Bits = 1 Byte
    IF bitCnt = 8 THEN
    bitCnt = 0
    INC byteCnt
    ENDIF

    'Check For Required 3 Bytes
    IF byteCnt < 3 THEN
    LOW GREENLED
    ELSE
    HIGH GREENLED
    byteCnt = 0
    ENDIF

    GOTO Main
  • stamptrolstamptrol Posts: 1,731
    edited 2006-02-15 00:31
    Jumpkick,

    I did some work with Wiegand code from a proximity card reader with a BS2 or BS2sx . Its not a pretty thing to work with, but in the end it did the trick. I wrote it down for safe keeping, now just have to find it.

    Seems to me, the card reader would let you select whether the output was sent in async serial ( RS-232) or synchronous where you supplied a clock pulse. The serial version is what I used, 2400 baud, I think.

    Will get back to you.

    Tom
  • BeanBean Posts: 8,129
    edited 2006-02-15 00:47
    Jumpkick,
    Is seems you missed the first 3 lines of code right after "ReaderWait:"
      IF Data0 = 1 THEN
        IF  Data1 = 1 THEN Reader_Wait
      ENDIF
    
    

    This keeps the program from continuing unless one of data lines is low.
    Your code is shifting in a "0" on every loop through the code.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "SX-Video·Module" Now available from Parallax for only $28.95

    http://www.parallax.com/detail.asp?product_id=30012

    "SX-Video OSD module" Now available from Parallax for only·$49.95
    http://www.parallax.com/detail.asp?product_id=30015

    Product web site: www.sxvm.com

    "Ability may get you to the top, but it takes character to keep you there."
    ·
  • stamptrolstamptrol Posts: 1,731
    edited 2006-02-15 01:20
    Jumpkick,

    OK, found my notes from 2002.

    1. It was an HID RF proximity card reader.

    2. The Wiegand code output could be set to either serial or sync. I used serial.

    3. I tested it at 4800 on a BS2 and 9600 on a BS2sx. Just used SERIN to watch for CR or LF. Then, the next burst is grabbed as STR in an 18 byte array. I think the leading zeros were constant so they could also be used as a WAIT parameter inthe SERIN.

    4. As an example, card number 31926 sends a string that looks like this:

    00 00 04 D6 F9 6C 3F CR LF

    step 1: throw away CR and LF ( carriage return and line feed)
    step 2: the next pair ( 3F ) is the checksum and can also be disregarded , unless you really want the gymnastics to crunch it on the fly.
    step 3: the next two pairs are the card number ( F9 6C ), sort of. F9 6C = 63852
    step 4: take the value of those two pairs and divide by 2
    step 5: card number is 31926
    the 04 and D6 are facility numbers, which I didn't need to decode.

    Hope this helps.

    Tom
  • JumpkickJumpkick Posts: 19
    edited 2006-02-15 16:18
    Bean I added:

    IF Data0 = 1 THEN
    IF Data1 = 1 THEN
    GOTO Main
    ENDIF
    ENDIF

    But even with that the LED blinks green rather spontaneously. I was able to hook my reader to another manufacturers panel and it worked just fine so I don't know what is going on.

    Stamptrol:
    I am unable to use a serial interface per a requirement for the product. It has to be able to read Wiegand inputs. [noparse]:([/noparse]
  • BeanBean Posts: 8,129
    edited 2006-02-15 17:06
    Jumpkick,
    Can you attach your complete program. I'll look at it.
    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "SX-Video·Module" Now available from Parallax for only $28.95

    http://www.parallax.com/detail.asp?product_id=30012

    "SX-Video OSD module" Now available from Parallax for only·$49.95
    http://www.parallax.com/detail.asp?product_id=30015

    Product web site: www.sxvm.com

    "Ability may get you to the top, but it takes character to keep you there."
    ·
  • JumpkickJumpkick Posts: 19
    edited 2006-02-15 17:16
    Reader.sxb attached.
  • JumpkickJumpkick Posts: 19
    edited 2006-02-15 18:08
    What is your layout for connecting a wiegand reader to the board itself?
  • BeanBean Posts: 8,129
    edited 2006-02-15 18:17
    Jumpkick,
    · Try this code.
    · Make sure you have the ground wire connected between the reader and the SX.
    ·
    · If the reader is operating from the same power source as the SX then it should be okay.
    · If the reader is operating from a seperate supply then you need to connect the ground wires together.
    · Other than that just connect the DATA0 and DATA1 wires to the SX pins. You might want to use a 1K resistor just to protect the pin.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "SX-Video·Module" Now available from Parallax for only $28.95

    http://www.parallax.com/detail.asp?product_id=30012

    "SX-Video OSD module" Now available from Parallax for only·$49.95
    http://www.parallax.com/detail.asp?product_id=30015

    Product web site: www.sxvm.com

    "Ability may get you to the top, but it takes character to keep you there."


    Post Edited (Bean (Hitt Consulting)) : 2/15/2006 6:20:33 PM GMT
  • JumpkickJumpkick Posts: 19
    edited 2006-02-15 18:21
    That may be the problem. Currently I have the wiegand powered outside the board and Data0 and Data1 plugged into RC.0 and RC.1 respectively. Where can I connec the reader to the board to use the same power source?
  • BeanBean Posts: 8,129
    edited 2006-02-15 18:26
    Just connect the ground of the supply for the SX to the ground of the reader's power supply.
    You'll need three wires between the SX and reader: DATA0, DATA1, and GROUND.
    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "SX-Video·Module" Now available from Parallax for only $28.95

    http://www.parallax.com/detail.asp?product_id=30012

    "SX-Video OSD module" Now available from Parallax for only·$49.95
    http://www.parallax.com/detail.asp?product_id=30015

    Product web site: www.sxvm.com

    "Ability may get you to the top, but it takes character to keep you there."
    ·
  • JumpkickJumpkick Posts: 19
    edited 2006-02-15 18:58
    That looks to work GREAT! When I put a 1k resistor in between it never reads. However if I go directly into the input itself, everything appears okay. Thank you very much for all your help on this project. I really appreciate it.
  • JumpkickJumpkick Posts: 19
    edited 2006-02-15 19:04
    Next I am thinking on how I can output the numbers via serial to a PC for evaluation.
  • BeanBean Posts: 8,129
    edited 2006-02-15 19:26
    Use this code and from the IDE choose "DEBUG" then choose "POLL".
    When you swipe a tag the WATCH window should show the siteID and the cardID for that tag.

    Bean.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "SX-Video·Module" Now available from Parallax for only $28.95

    http://www.parallax.com/detail.asp?product_id=30012

    "SX-Video OSD module" Now available from Parallax for only·$49.95
    http://www.parallax.com/detail.asp?product_id=30015

    Product web site: www.sxvm.com

    "Ability may get you to the top, but it takes character to keep you there."
  • JumpkickJumpkick Posts: 19
    edited 2006-02-15 19:32
    Not sure why, but nothing is enabled on the debug screen.
  • BeanBean Posts: 8,129
    edited 2006-02-15 19:40
    Try changing OSC4MHZ to OSCXT2 on the DEVICE line.
    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "SX-Video·Module" Now available from Parallax for only $28.95

    http://www.parallax.com/detail.asp?product_id=30012

    "SX-Video OSD module" Now available from Parallax for only·$49.95
    http://www.parallax.com/detail.asp?product_id=30015

    Product web site: www.sxvm.com

    "Ability may get you to the top, but it takes character to keep you there."
    ·
  • JumpkickJumpkick Posts: 19
    edited 2006-02-15 19:57
    It just says running and you are unable to press any of the buttons.
  • JumpkickJumpkick Posts: 19
    edited 2006-02-15 20:06
    This is the card I have:

    005-56164

    Yields:

    225 1 118

    ??
  • BeanBean Posts: 8,129
    edited 2006-02-15 20:26
    Hmmm,
    You should get 5 for siteID and 56164 for cardID. Not sure what's going on there.

    Do you get the same values everytime ?

    Do you have another card ? What values to you get for it ?

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "SX-Video·Module" Now available from Parallax for only $28.95

    http://www.parallax.com/detail.asp?product_id=30012

    "SX-Video OSD module" Now available from Parallax for only·$49.95
    http://www.parallax.com/detail.asp?product_id=30015

    Product web site: www.sxvm.com

    "Ability may get you to the top, but it takes character to keep you there."
    ·
  • JumpkickJumpkick Posts: 19
    edited 2006-02-15 21:29
    Even more weird. I get the same values for every card.

    005-56166
    005-56164
    005-56170
  • BeanBean Posts: 8,129
    edited 2006-02-15 23:31
    Hmmm, Are you using SX/B version 1.42.01 ?
    Try setting them to zero before the routine maybe they are just not getting updated.
    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "SX-Video·Module" Now available from Parallax for only $28.95

    http://www.parallax.com/detail.asp?product_id=30012

    "SX-Video OSD module" Now available from Parallax for only·$49.95
    http://www.parallax.com/detail.asp?product_id=30015

    Product web site: www.sxvm.com

    "Ability may get you to the top, but it takes character to keep you there."
    ·
  • JumpkickJumpkick Posts: 19
    edited 2006-02-15 23:58
    Okay, I figured out part of the problem. Some of the cards we are using are 26bit and some of them are 34 bit and some of them I have no idea. I have figured out the pattern for at least one format which is:

    siteid = rfid(0)
    cardid(0) = rfid(2)
    cardid(1) = rfid(1)

    I can't seem to figure out the other two formats that I am dealing with. I am stumped right now as to how to program the SX to identify which format and properly return the siteID and cardID.
  • BeanBean Posts: 8,129
    edited 2006-02-16 00:10
    My code is for the 26 bit format.
    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "SX-Video·Module" Now available from Parallax for only $28.95

    http://www.parallax.com/detail.asp?product_id=30012

    "SX-Video OSD module" Now available from Parallax for only·$49.95
    http://www.parallax.com/detail.asp?product_id=30015

    Product web site: www.sxvm.com

    "Ability may get you to the top, but it takes character to keep you there."
    ·
  • JumpkickJumpkick Posts: 19
    edited 2006-02-16 00:14
    I thought I was doing 26 bit but apparently not. Any suggestions?
  • BeanBean Posts: 8,129
    edited 2006-02-16 02:32
    Your probably going to need a logic analyzer or at least an oscilloscope to see what your trying to decode.
    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "SX-Video·Module" Now available from Parallax for only $28.95

    http://www.parallax.com/detail.asp?product_id=30012

    "SX-Video OSD module" Now available from Parallax for only·$49.95
    http://www.parallax.com/detail.asp?product_id=30015

    Product web site: www.sxvm.com

    "Ability may get you to the top, but it takes character to keep you there."
    ·
  • Washer MedicWasher Medic Posts: 39
    edited 2006-02-16 04:46
    Hi I have bin trying to interface a commercial rfid reader with a bs2. It uses 26-bit Wiegand format its my understanding it consists of a parity bit, 8-bit facility code, 16-bit user ID, and parity bit, for a total of 26 (1+8+16+1=26) bits unfortunately im in well over my head but I thought I would share my research so far in the hope it might help you
    ·

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    There's nothing a good wack with a hammer won't fix

    Darn I let the white smoke out again
Sign In or Register to comment.