wiegand26 protocol on picaxe - help please.

zebulon

Member
Hi folks,

A few weekS ago, I bought a RFID Reader that output his datas using wiegand26 protocol.

Since 3 days, I try to communicate with the reader, but can't get it to work.

Some of my attempts show me "0" or "1" as I set trace in the program.

I put some of my code below.

If a kind soul could take a look to my code, I'd be grateful.

Code:
#picaxe 18M2
symbol x = B0
symbol cpt = B1
symbol ok = B2

setfreq  M4

sertxd("CONTROL RFID", 13, 10)

setint not %00000011, %00000011 ' déclenche une interruption si les bits 0 (OU) 1 sont égale à 0 (par ex: 10 ou 01. 00 ne se produit jamais)

let ok = 0

debut:

' DATA0 connecté sur B.0 et DATA1 connecté sur B.1

	'If pinB.0 = 1 and pinB.1 = 1 Then ' etat de repos

		if ok = 1 then

			setint OFF

			gosub affiche

			setint not %00000011, %00000011

		endif

	'endif

	goto debut
	
interrupt:

	if pinB.1 = 1 and pinB.0 = 0 then
		inc cpt
		poke cpt,"0"
	Else
		if pinB.1 = 0 and pinB.0 = 1 then
			inc cpt
			poke cpt,"1"
		endif
	End If

	if cpt = 28 then
		let ok = 1
		setint OFF 'not needed I think
	else
		setint not %00000011, %00000011 ' Ré-arme les interruptions
	endif
	return

affiche:
	sertxd("Affichage ID :",13,10)
	for x = 3 to 28
		peek x, cpt
		'if cpt <> 0 then
			sertxd(cpt)
		'endif
	next x

	sertxd(13,10)

	for x = 3 to 28
		poke x, 0
	next x

	let cpt = 2 ' re-initialise le compteur de digits
	let ok = 0

	return
DATA0 of the Reader is connected to B.0
DATA1 of the Reader is connected to B.1
Ground of the electronic assembly and ground of the Reader are common.
There are leds on the reader and a buzzer and all seems to be ok when i pass the card in front of the reader (the green led flashes and the buzzer play a sound)

I remember yet (i'm not at home), i have pull-up resistors for the DATA0 and DATA1 set to 10K. I read a datasheet this morning where it talk to use 4,7K.
Could this be the explanation ?

So, what is wrong ?
It seems I miss some interrupt.
I tried to set the frequency up to M32 (and reset it at M4 just before the sertxd command and to M32 after), but it was not better.

Any help would be much appreciate.
Thanks,
Guillaume
 
Last edited:

zebulon

Member
Hi again,

I spent 3 hours to get something that starts to work.

Here is the Code : ...


Code:
#picaxe 18M2

symbol x = B0

symbol cpt = B1

symbol ok = B2
symbol nb_byte = 14



' let dirsB = %00000000 ' (tout en entrée)

setfreq  M4

sertxd("CONTROL RFID", 13, 10)

setfreq  M32


let ok = 0
let cpt = 2

'let bptr = 2


setint not %00000011, %00000011 ' déclenche une interruption si les bits 0 (OU) 1 sont égale à 0 (par ex: 10 ou 01. 00 ne se produit jamais)



debut:

	pause 5000

	goto debut

	

' Quand une interruption est déclenchée car les pins sont différentes de 11 (NOT %00000011), il faut tester quelle est la combinaison (10 ou 01)

interrupt:

	if pinB.1 = 1 and pinB.0 = 0 then

		inc cpt

		poke cpt,"0"

	Else

		if pinB.1 = 0 and pinB.0 = 1 then

			inc cpt

			poke cpt,"1"

		endif

	End If

	if cpt = nb_byte then

		gosub affiche

	endif

	setint not %00000011, %00000011 ' Ré-arme les interruptions

	return



affiche:

	' bptr = 1 ' initialise le pointeur d'adresse

	' if @bptr = 0 then : return : endif ' si l'adresse suivante contient 0

	' sertxd(#@bptr) ' envoi sur le port série l'octet pointé par @bptr

setfreq  M4

	sertxd("ID = ")

	for x = 3 to nb_byte

		peek x, cpt

		'if cpt <> 0 then

			sertxd(cpt)

		'endif

	next x

	sertxd(13,10)

setfreq  M32

	for x = 3 to nb_byte

		poke x, 0

	next x

	let cpt = 2 ' remet le compteur de bits à 0

	let ok = 0
	pause 1000

	return
I tried several successive values for nb_byte variable.
2 problems :
1) I never get 2 times (except extremely rare case) the same data.
2) I didn't receive more than 12 bits at a time or perhaps the missing bits are lost. (in wiegand26, I expect to receive 26 bits)

I'm waiting for your suggestions.

Guillaume
 
Last edited:

zebulon

Member
Hi MPep,

I was posting and don't see you message at time.
I hope you understand my bad english.

So, here are some link I follow to understand this protocol.
The dealer didn't give me a datasheet with the reader (eBay seller !). Just that it is wiegand26 complient.

So I didn't found a datasheet specifically for my reader.

I search the internet and the forum with keywords like "RFID, wiegand, protocol, R60" but didn't found something usable for me.

A link to the e*ay items (the one I bought) :
http://cgi.ebay.com/R60-Wiegand26-RFID-Reader-125KHz-w-Keypad-Black-/260438322502?pt=LH_DefaultDomain_0&hash=item3ca3556d46

A link to wikipedia :
http://en.wikipedia.org/wiki/Wiegand_interface

A link that describe the protocol (including chronogram) :
http://www.ibtechnology.co.uk/pdf/magswipe_dec.PDF

The pinout of my reader is as follow :
1 : 12V
2 : GND
3 : D0 / RX
4 : D1 / TX
5 : LED / CS
6 : SPEAK
7 : BELL
8 : BELL
9 : ALARM

I actually only use pin 1 to 4 thinking it is in wiegand format.
But now, writing this pinout, I realise that pin 3-4 are RX / TX and not only DATA0 / DATA1.
So perhaps a connection must be made to "tell" the reader to output wiegand26 data.

Guillaume
 
Last edited:

zebulon

Member
Hi all,

I think I found my mistake. I use B.0 and B.1.
But interrupts can only be considered on Port C on the 18M2. Am I true ?
I will give it a try tonight.

Guillaume
 

zebulon

Member
I tried with using the port C wich give better results, but I am having a few problems.

Here is the last version of my code
Code:
#picaxe 18M2
symbol x = B0
symbol cpt = B1
symbol ramstart = b3
symbol ramend  = b4
symbol val = b5

symbol nb_byte = 26

' Intialisation diverses
' ----------------------------
let ramstart = 6 ' Emplacement RAM 5
let ramend = ramstart + nb_byte - 1

setfreq  M16
sertxd("CONTROL RFID", 13, 10)

let cpt = ramstart - 1 ' Compteur du nombre de bits reçus

setint not %11000000, %11000000 ' déclenche une interruption si les bits 0 (OU) 1 sont différents de 1 (NOT 11)  (par ex: 10 ou 01. 00 ne se produit jamais)

debut:
	pause 200
	' debug
	goto debut

' Quand une interruption est déclenchée car les pins sont différentes de 11 (NOT %00000011), il faut tester quelle est la combinaison (10 ou 01)
interrupt:
	if pinC.6 = 0 then
		inc cpt
		poke cpt,"0"
	else
		inc cpt
		poke cpt,"1"
	endif

	if cpt = ramend then ' Si on a stocké le dernier bit, alors on affiche la chaine.
		gosub affiche
	endif
	setint not %11000000, %11000000 ' Ré-arme les interruptions sur les pin C.0 et C.1
	return

affiche:
	sertxd("ID = ")
	for x = ramstart to ramend
		peek x, val
		if val <> 0 then
			sertxd(val)
		endif
	next x

	sertxd(13,10)

	for x = ramstart to ramend
		poke x, 0
	next x
	let cpt = ramstart - 1 ' remet le compteur de bits à 0
	return
And the result when executing the program :

Code:
CONTROL RFID
ID = 00000000000000000000000000
ID = 00000000000000000000000000
ID = 00000000000000000000000000
ID = 00000000000000000000000000
ID = 00000000000000000000000000
I tried differents values for nb_byte and il is ok only with 26, so I guess I get the interrupts (bits) well.
( When I set nb_byte to 25 and under, I have to swipe the card at least twice in front of the reader to get the digits displayed )

An idea, please, 'cause I'm at wit's end.

Guillaume
 
Last edited:

zebulon

Member
Hi,
At page 216 of manual 2, I read :
"3) If the interrupt is re-enabled and the interrupt condition is not cleared within
the sub-procedure, a second interrupt may occur immediately upon the return
command."

How do I clear the interrupt condition ?
Do I have to take care of this ?

Guillaume
 

hippy

Ex-Staff (retired)
A link that describe the protocol (including chronogram) :
http://www.ibtechnology.co.uk/pdf/magswipe_dec.PDF
According to that, Wiegand Protocol is a sequence of pulses on one of two lines indicating if a 0 or a 1 bit. That seems simple enough.

The problem is that the pulses are of 50us duration with 2ms intervals between pulses. It will be very difficult to SETINT on a pulse that short and be able to tell which pulse it was when the interrupt routine is entered. By the time the interrupt has been entered the pulse will have passed, and it's not guaranteed you would catch all pulses.

You will need an X2 PICAXE with hardware interrupts ( HINT pins ) and would need to run it at high speed, likely 32MHz or 64MHz.

You may be better off trying to get the TX output working which I would guess is a serial output and easier to read, especially with an X2.
 

zebulon

Member
HI hippy,

Thanks for replying.

This should be as you say because I had better result with setting the setfreq at M16 or M32 than M8.

I have a 28x2 in stock, so I would give it a try.

About TX and RX, I don't know if it is possible. I didn't found any schematic or datasheet for the reader.
Maybe setting the pin 5 (LED/CS) to a high state (CS= perhaps Cable Select or something like this). I will try.

Is there a way to know how long (or how many cycle) a PICAXE instruction is ?
This would be interesting if it was in the PICAXE documentation. (just an idea for a futur release ;) )

Guillaume
 
Last edited:

hippy

Ex-Staff (retired)
The issue of PICAXE timing has been discussed on the forum in the past and the bottom line is that there is no definitive answer but a rule of thumb figure is around 250us for executing simple HIGH, LOW and similar commands at default operating speeds.
 

zebulon

Member
Ok, I understand.
Is it planned to add command like 'asm' to have the ability to directly include some pic asm command ?
Basicaly, a PIC instruction takes 1 to 2 cycles to execute( I know you know that ;) ), so at 4Mhz, the BSF or BCF (wich have a duration of 1 cycle) takes less than 1us (0,25 us precisely).
I presume that the HIGH or LOW does not only do a BSF or BCF, but if a guy know that he doesn't need to set the port to output direction ('cause he know how it is already set), the possibility of adding just an instruction like "ASM BSF,PORTB,5" would save time in the execution.
I don't know if I'm clear enough ?

Guillaume
 

hippy

Ex-Staff (retired)
The PICAXE is an interpreter chip which uses an internal assembler program ( the firmware ) to execute a tokenised Basic program; the benefits of that coming at the cost of a reduced execution speed - though the reduction, compared to other solutions, is not always as great as it may first appear. For most uses of the PICAXE and the target market in general it's not a problem.

There is no means to add PIC assembler commands to a Basic program and there are no plans to add such a capability.

In many cases higher-speed systems can be handled but it is a matter of choosing the right PICAXE and a suitable algorithm. In this case I suspect a PICAXE X2 will be suitable but I obviously haven't put that to the test. It's likely recognition that the Wiegand protocol can be difficult to deal with which led to card-swipe and access control systems incorporating serial outputs which control systems can more easily deal with.
 

zebulon

Member
According to that, Wiegand Protocol is a sequence of pulses on one of two lines indicating if a 0 or a 1 bit. That seems simple enough.

The problem is that the pulses are of 50us duration with 2ms intervals between pulses. It will be very difficult to SETINT on a pulse that short and be able to tell which pulse it was when the interrupt routine is entered. By the time the interrupt has been entered the pulse will have passed, and it's not guaranteed you would catch all pulses.

You will need an X2 PICAXE with hardware interrupts ( HINT pins ) and would need to run it at high speed, likely 32MHz or 64MHz.

You may be better off trying to get the TX output working which I would guess is a serial output and easier to read, especially with an X2.
As soon say, as soon tried ...

..... and .... tadaaaaaa ...... IT WORKS !!!!!!!

With the same code that I have previously published.

I used a 28X2 at 16Mhz.
It didn't work at the same speed on the 18M2.

I give a try at 8Mhz on the 28X2 but it didn't works.

I have just a question about SERTXD.
Because I use 16M, I set the serial line speed of the terminal window to 19200.
When I plug the PICAXE-28X2 to power supply, the program starts and it should display "CONTROL RFID", but it didn't. There was no problem on the 18M2.
Next, the ID = line appears normaly every time I swipe the card in front of the reader.

Is there a reason for thatit

With the same card swipping, I got already the same code, so I guess it's correct.
Trying another card, I got already the same different number.

So yet I can go further with my project.

Guilaume
 

fre_deri_co

New Member
Hi Zebulon!
a few days ago i bought a wiegand26 in ebay like you, but not exactly the same product (mine is http://www.ebay.com/itm/New-Mini-WG26-ID-EM-Proximity-Reader-125KHz-/250906808269?pt=LH_DefaultDomain_0&hash=item3a6b360fcd).
Today i started to trying working with it, when i saw that need something to "read" the signal to like i need.
My first question is the connection because it have 6 wires with diferent colors like i found in the internet.
my reader have red, black, green, white, grey and purple, in the internet i found similar but with yellow and blue instead of grey and purple.
i saw too that it is necessary two wires connected to ground and i don't know which one is to connect with black.

if it is possible you can say to me the connection you used with your picaxe 28x2.
Sorry my bad English, i appreciate any help.
Frederico Pereira [PT]
 

inglewoodpete

Senior Member
Do you have a URL for the technical manual of your RFID reader?

I see the EBay page for the RFID supplier asks you to contact xychen1996 [at] gmail [dot] com for hardware manual/software manual/SDK.
 

fre_deri_co

New Member
ahah!! Done!!!
i am using AXE201 PICAXE-28X2 Module, and it failed because the frequency was not enough, so i put it at em32 when is reading and at m8 when was sending to pc...

the connection i use red and black to dc supplies, green pinc.5 and white pinc.6.

i already asked the datasheet like inglewoodpete said.

Thanks for all your attention ^^d because the frequeni was not enouf
 
Top