I'm totally stumped trying to figure out how to read input to the SDA/SCL GPIO pins on the Pi.
Context: I have a Wiegand 26 RFID reader that I would like to read data from. The idea is that I get the bits from the reader, parse/interpret them as Wiegand, and from there I can do a number of things. For now, I'm only concerned with troubleshooting this part, even though my setup is part of a larger system.
References: I have been using the Pi Doorman website as a guide, and I am using his C program that consumes the WiringPi library. I followed the instructions to install the WiringPi library and I compile wiegand.c with the switches, as shown on the website.
There are two parts I know I need to debug, the circuit and the code.
The Circuit: The circuit is shown in the image/attachment below. I have a Revision 1 Pi, which I verified by writing a small program to call the method that returns the revision from including wiringpi.h
. I got some help from some of the electronics folks, as this is not my wheelhouse. As you can see, the Pi Cobbler is used, and we connect the ground from the 12V power supply to the reader to one of the Pi ground pins. 5V comes out of the reader on D0 (green) and D1 (white), which we step down to 3.3V, before attaching to SDA and SCL, respectively. This is also how it is described in the comment in wiegand.c.
The comment also notes the voltage is held high on both data lines, so I tested with a multimeter and saw that close to 3.3V was going into the Pi Cobbler pins for each line. Also, we hooked up the lines to an oscilloscope, and when I swipe the RFID card, as described, the voltage drops to 0V briefly. That gives us confidence is the circuit is accurate, but feel free to review the image and let me know if you have any pointers, especially if you've gotten this successfully working.
The Code: The wiegand.c
program, seems to be written well. It's basically two threads that hold on the waitForInterrupt
on each data line, indefinitely, until bits are read. A counter is triggered, which more or less tries to collect all the bits possible from a pulse.
I compiled the code per Pi Doorman instructions, and ran it. It prompts me to use standard site code, I say Y
and then hit enter. When I swipe the RFID card, nothing appears.
There are some things I did to debug the code, mostly print statements. I didn't get very far, except to confirm the code should work the way it's written. Like I said above, I downloaded the source for the WiringPi library and inspected the methods to see what was happening behind the scenes, and verified I had a Revision 1 Pi with a small program to rule that out. Also, in the /sys/class/gpio/
folder on the Pi, there is gpio0
and gpio1
symlinks defined, so I think I have strong evidence I have a Revision 1 board.
I took a closer look at the wiringPiSetupSys
function that is one of the first things called by wiegand.c
. There's a loop in here:
for (pin = 0 ; pin < 64 ; ++pin)
{
sprintf (fName, "/sys/class/gpio/gpio%d/value", pin) ;
sysFds [pin] = open (fName, O_RDWR) ;
}
So, there's something that happens here. When I go back to wiegand.c
and add some code to each thread, to print out the return value of the waitForInterrupt
function, it's -2
. waitForInterrupt
basically pulls the value out from the file descriptor array, so the -2
is ultimately the return value from the open()
call here in the setup function.
I don't know what that means, but it's probably a safe guess the open()
call for read/write failed, just because it's C convention to return negative values for things like that. So if I can't open the pin for read/write, I can't read data.
I should also note: the compilation and running of wiegand.c
was done under the root user, so I don't think this is a permissions issue. Additionally, I'm running wheezy debian on this Pi, in case that matters.
So, a couple of questions: - Where do I go from here, in terms of tracking down what the error means, or modifying the code to narrow this down further? - Has anyone successfully used the Raspi and this software to read data in this manner, from an RFID reader like this or something similar?
I hope I haven't left anything out, but let me know if I need to provide some additional info.