Page 1 of 1
WiringPi and Raspberry
Posted: Fri Mar 06, 2015 9:49 am
by mrdebug
Hi. Does anybody use WiringPi? Which kind of idea have you got on it?
I'm using WiringPi for manage a wiegand 26 rfid readers. Sometimes I have more than 26 bits but, by verifying an oscilloscope, the reader sends only 26 clear bits.
The reader sends all bits in 30 or 40 milliseconds. It it too fast for WiringPi or do you think is a problem related to Raspberry Pi?
Re: WiringPi and Raspberry
Posted: Fri Mar 06, 2015 10:42 am
by joan
It's not a problem with wiringPi as such, it is more of a problem with relying on Linux interrupts to be always serviced in a timely fashion.
My
pigpio library works without relying on Linux timing and is more likely to give reliable results.
C/C++/Python Wiegand examples at
http://abyz.co.uk/rpi/pigpio/examples.html
Re: WiringPi and Raspberry
Posted: Tue Apr 21, 2015 10:30 am
by mrdebug
Hi. Now I'm trying to implement your library PIGPIO.
In order to have my function called each time (and only if) a gpio changes state I have to setup:
gpioSetMode(InputData0, PI_INPUT);
gpioSetPullUpDown(InputData0, PI_PUD_UP);
gpioSetAlertFuncEx(InputData0, OnData0, this);
and then
void OnData0(int, int level, uint32_t, void *opaque) {
if (level!= PI_TIMEOUT) ((QThlpt*)opaque)->OnData(0);
}
Is it true? Have I to implement a timeout?
Re: WiringPi and Raspberry
Posted: Tue Apr 21, 2015 11:28 am
by joan
It's safest to implement a timeout. Otherwise what will you do when a code has too few or too many bits.
I used it because I don't have a Wiegand device and wanted to generate arbitrary length codes for testing purposes.
It may be quickest just to adapt the C++ example I linked to in the post.
Re: WiringPi and Raspberry
Posted: Tue Apr 21, 2015 3:00 pm
by mrdebug
Ok I have added this line of code:
gpioSetWatchdog(InputData0, 1000);
but for me is not completely clear.
Using WiringPi my function will be called when the level goes to 0.
By timeout at 1000 I think that my function will be called every 1000 milliseconds if nothing happens, but immediately if a bit will come?
I have made a device based on Raspberry Pi with 2 wiegand interfaces and 4 relays. The goal is to use it in access control contest and in a device with rfid readers.
For me is very important to have it working perfectly because I hope it will be my core business.
Now, with WiringPi sometimes i have more than 26 bits from a wiegand reader. I hope to resolve the problem with your library. If that can be I can order to made a lot of this devices.
Regards.
Re: WiringPi and Raspberry
Posted: Tue Apr 21, 2015 3:12 pm
by joan
What I generally do is set the watchdog when the first bit is received. The watchdog will trigger x milliseconds after the last bit is received (and every x milliseconds thereafter until cancelled).
For instance if at least a bit every millisecond was expected I'd probably set a 3ms watchdog. When the watchdog triggered (report with gpio level 2) then I'd know the code was complete. I'd then cancel the watchdog and check the code for correctness (right number of bits etc.).
Slightly more complicated for Wiegand as you'd have to timeout data0 and data1.
Re: WiringPi and Raspberry
Posted: Tue Apr 21, 2015 7:59 pm
by mrdebug
I have just finished to implement your library. I confirm. Your library works better than wiring pi in a wiegand contest.
Thanks for your work.
Re: WiringPi and Raspberry
Posted: Thu Apr 23, 2015 1:15 pm
by mrdebug
One more question:
If I have more than one programs that implement PIGIO how have I to inizialize? For example when I run the firs program I can call
gpioInitialise
without problems. But when I run it from the second program I obtain an error.
Witch is the right way?
Re: WiringPi and Raspberry
Posted: Thu Apr 23, 2015 1:37 pm
by joan
mrdebug wrote:One more question:
If I have more than one programs that implement PIGIO how have I to inizialize? For example when I run the firs program I can call
gpioInitialise
without problems. But when I run it from the second program I obtain an error.
Witch is the right way?
There may only be one copy of the library running at any one time (for a variety of reasons, but at its simplest hardware clocks are being altered and only one program should be in control at any one time).
A natural solution is to launch the library as a daemon (sudo pigpiod) and use the socket or pipe interface to get the information you need. Many programs may talk to the daemon at the same time.
That is how the Python module works. It is also how pigs works. From C there is a library specially for communication with the daemon, i.e.
libpigpiod_if. x_pigpiod_if.c is an example of its use.
Whatever method you use you will still receive the timestamped gpio events.