go_away

Author Topic: RFID reader ID-20 and Axon II?  (Read 819 times)

0 Members and 1 Guest are viewing this topic.

Offline BANETopic starter

  • Supreme Robot
  • *****
  • Posts: 639
  • Helpful? 4
  • E=roboticsC^2
RFID reader ID-20 and Axon II?
« on: December 30, 2012, 07:11:18 PM »
Hello all,
Im working on a automatic door lock and need a RFID reader.  I've been looking at this one
https://www.sparkfun.com/products/8628
and wondering how hard it would be to use it with the axon II?  It only needs to read a card and turn on a relay; any ideas or thoughts?

Thanks!

Offline jwatte

  • Supreme Robot
  • *****
  • Posts: 1,343
  • Helpful? 81
Re: RFID reader ID-20 and Axon II?
« Reply #1 on: December 30, 2012, 07:46:24 PM »
Assuming you know how to speak serial (UART / TTL) on the Axon II, it should be easy.
You'll definitely want the version with the breakout board, btw!

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,660
  • Helpful? 169
    • Society of Robots
Re: RFID reader ID-20 and Axon II?
« Reply #2 on: January 04, 2013, 11:51:36 AM »
Connect power to power, ground to ground, and two data pins to Rx and Tx. Done.

To send commands to it, just use rprintf() at the proper baud rate to the desired UART. Done.

Reading back from it is a little harder. In a FOR loop, store the data into an array of char values:

char data[whatever];

for loop:
data=uartGetByte(UART3);

Offline BANETopic starter

  • Supreme Robot
  • *****
  • Posts: 639
  • Helpful? 4
  • E=roboticsC^2
Re: RFID reader ID-20 and Axon II?
« Reply #3 on: January 22, 2013, 07:31:04 AM »
Okay sorry for the delay but Ive finally got all my problems down to just reading in the bytes.  So what I want it to do right now is store the tag number and then display it on my 20x4 lcd screen. Here is my code im using which just prints garbage to the screen.  I think that Im not reading in the bytes correctly so the garbage is the random data from the blank array.
Any ideas?
Thanks in advance

update: also, ive hooked up TX from the ID-20 to my oscilloscope and it is outputing serial data when a card is read
Code: [Select]
#include "hardware.h"

// Initialise the hardware
void appInitHardware(void) {
initHardware();

}
// Initialise the software
TICK_COUNT appInitSoftware(TICK_COUNT loopStart){
// -------- Start Sparkfun serLCD-------
//turn on LCD
pin_high(LCD_Relay);
delay_ms(300);

rprintfInit( displayGetWriter(&LCD));
    displayBacklight(&LCD,TRUE);
// -------- End   Sparkfun serLCD-------
return 0;
}
// This is the main loop
TICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart) {
//////////Main Loop/////////////////////////////////////////

char tagString[13];
int index=0;
boolean reading = false;


//read from rfid
while(uartGetByte(ID20)!=-1){//do while data recieved non -1 data
int readByte=uartGetByte(ID20);//Assign byte read to a temp int

if(readByte == 2) reading = true; //begining of tag
    if(readByte == 3) reading = false; //end of tag

    if(reading && readByte != 2 && readByte != 10 && readByte != 13){//store the tag
      tagString[index] = readByte;
      index ++;
    }
}

//display data
for (int i=0;i<12;i++){//display data along collumns
displayGoto(&LCD,i,0);//display position
rprintf("%c",tagString[i]);
}

//clear screen
delay_ms(1000);
displayClear(&LCD);
return 0;
}
« Last Edit: January 22, 2013, 07:35:08 AM by BANE »

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,660
  • Helpful? 169
    • Society of Robots
Re: RFID reader ID-20 and Axon II?
« Reply #4 on: January 22, 2013, 10:03:06 AM »
You are reading in the bytes as 'int' but storing/printing them out as 'char'.

Change:
int readByte

to:
char readByte

and instead of:
(readByte == 2)

use:
(readByte == '2')

etc. etc.

or . . . you can just do this casting and it might just work with no other changes:
tagString[index] = (char)readByte;

Offline BANETopic starter

  • Supreme Robot
  • *****
  • Posts: 639
  • Helpful? 4
  • E=roboticsC^2
Re: RFID reader ID-20 and Axon II?
« Reply #5 on: January 22, 2013, 10:59:37 AM »
Okay I've done the casting method and same results.  I think my problem lays in being able to capture all the bytes.  Right now my capture loop stays open when RX != -1 but perhaps that's not reliable or something.  How can i do something similar to the "serial.available" in this code?
Code: [Select]
void loop(){

  char tagString[13];
  int index = 0;
  boolean reading = false;

  while(Serial.available()){

    int readByte = Serial.read(); //read next available byte

    if(readByte == 2) reading = true; //begining of tag
    if(readByte == 3) reading = false; //end of tag

    if(reading && readByte != 2 && readByte != 10 && readByte != 13){
      //store the tag
      tagString[index] = readByte;
      index ++;
    }
  }

  checkTag(tagString); //Check if it is a match
  clearTag(tagString); //Clear the char of all value
  resetReader(); //eset the RFID reader
}
« Last Edit: January 22, 2013, 11:22:55 AM by BANE »

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,660
  • Helpful? 169
    • Society of Robots
Re: RFID reader ID-20 and Axon II?
« Reply #6 on: January 22, 2013, 11:49:11 AM »
I think part of your problem is that your code is trying to do too much at once, making it hard to narrow down where the bug is.

Split up your code into tiny parts, and verify each part one at a time.

Another problem I see with your code is that your index is reset to 0:
int index=0;
whenever uartGetByte(ID20)==-1
(ie it escapes the while loop, and starts at the beginning again)

As your code runs way faster than the UART, this will mean you keep overwriting tagString[0], while the rest of the index remains as random character garbage.

Change this line:
while(uartGetByte(ID20)!=-1){

to something like:
Code: [Select]
while(readByte != 13){
     if(uartGetByte(ID20)!=-1)
     {
     //your other if statements here
     }

(I'm assuming 13 means the RFID number has been completed)

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,150
  • Helpful? 110
Re: RFID reader ID-20 and Axon II?
« Reply #7 on: January 22, 2013, 09:04:17 PM »
Your problem is here:
Code: [Select]
//read from rfid
while(uartGetByte(ID20)!=-1){//do while data recieved non -1 data
    int readByte=uartGetByte(ID20);//Assign byte read to a temp int

When the first uartGetByte gets something other than -1 you throw it away and then the second uartGetByte problem doesn't have the next character yet and so probably returns -1.
try something like:
Code: [Select]
int readByte;
while (readByte = uartGetByte(ID20), readByte !=-1){
    // You've now got the data in readByte
}
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

 


Get Your Ad Here