Page 1 of 1

NXC: RFID-Sensor values?

Posted: 03 Nov 2010, 10:30
by HaWe
I'm looking for the command to read RFID-Sensor values (Codatex). If I enter "RFID" and press F1 I can't find any help topic.
Can someone help please?

Re: NXC: RFID-Sensor values?

Posted: 03 Nov 2010, 10:38
by mightor
Google search + "rfid sensor nxc" = http://www.codatex.com/index.php?en_NXC (top link)

A word to the wise, this sensor is very, very bitchy to work with. Sometimes it will return bogus values, sometimes nothing at all.

Regards,
Xander

Re: NXC: RFID-Sensor values?

Posted: 03 Nov 2010, 10:59
by gloomyandy
Another word to the wise... Be very careful with using the low level i2c interface with this sensor. It is very easy to corrupt the firmware on the device (I managed to do this to two sensors while getting the sensor working with leJOS), you can get hold of a firmware update program, but it's best not to have to!

Andy

Re: NXC: RFID-Sensor values?

Posted: 03 Nov 2010, 12:23
by HaWe
thx to both of you for the help!
:)

Re: NXC: RFID-Sensor values?

Posted: 03 Nov 2010, 13:49
by afanofosc
The latest BricxCC test release includes Codatex RFID API functions in NXCDefs.h which are documented in the NXC help files. I still need to add a sample program for them. Here's the sample code that the API functions were based on:

Code: Select all


/*
char RFIDInit(const byte port)
{
  byte buf[] = {0x04, 0x32};
  I2CWrite(port, 0, buf);
  char status = I2CCheckStatus(port);
  while (status > 0)
    status = I2CCheckStatus(port);
  return status;
}

char RFIDMode(const byte port, const byte mode)
{
  return I2CSendCommand(port, CT_ADDR_RFID, mode);
}

byte RFIDStatus(const byte port)
{
  byte result;
  ReadI2CRegister(port, CT_ADDR_RFID, CT_REG_STATUS, result);
  return result;
}

bool RFIDRead(const byte port, byte & output[])
{
  byte inbuf[] = {CT_ADDR_RFID, CT_REG_DATA};
  byte count = 5;
  return I2CBytes(port, inbuf, count, output);
}

void RFIDStop(const byte port)
{
  RFIDInit(port);
  Wait(10);
  RFIDMode(port, RFID_MODE_STOP);
}

bool RFIDReadSingle(const byte port, byte & output[])
{
  RFIDInit(port);
  Wait(15);
  RFIDMode(port, RFID_MODE_SINGLE);
  Wait(250);
  return RFIDRead(port, output);
}

bool RFIDReadContinuous(const byte port, byte & output[])
{
  RFIDInit(port);
  Wait(15);
  if (RFIDStatus(port) != 1) {
    RFIDMode(port, RFID_MODE_CONTINUOUS);
    Wait(250);
  }
  return RFIDRead(port, output);
}
*/

task main()
{
  SetSensorLowspeed(S1);
  
  while (true) {
    byte data[];
    
    if (RFIDReadContinuous(S1, data)) {
      for(int i = 0; i < 5; i++) {
        byte x = data[i];
        NumOut(0, LCD_LINE1-(i*8), x);
      }
    }
    else
      TextOut(0, LCD_LINE1, "RFID Read Failed", true);
    Wait(500);
  }
}
John Hansen

Re: NXC: RFID-Sensor values?

Posted: 03 Nov 2010, 13:52
by linusa
While I noticed the bitchyness of the CODATEX RFID sensor at first, it's now working stable with our MATLAB Toolbox AFAIK (and I think we've got 10 or 20 sensors of them, something in that magnitude).

This Tutorial by Ralph Hempel helped me a lot: http://www.hempeldesigngroup.com/lego/p ... fidsensor/ , together with the NXC code.

I ended up doing my own test. I think I've seen once that the returned ID was simply WRONG. But I could never ever reproduce this invalid ID, since then I either get no reading (ID tag too far away) or the correct ID. Are you SURE it's a hardware problem, Xander?

Anyway, the code I ended up with is this:
http://www.mindstorms.rwth-aachen.de/tr ... OpenRFID.m
http://www.mindstorms.rwth-aachen.de/tr ... /GetRFID.m

I know most of you do MATLAB, but all you need to know is that % is the comment sign. I tried to document what I did, maybe it's helpful for somebody...

Re: NXC: RFID-Sensor values?

Posted: 03 Nov 2010, 13:56
by mightor
I am pretty sure it was a hardware problem. I have a protocol analyser that tells me what is coming down the line :) It was a sporadic thing. The driver I've made is pretty stable. I haven't used this sensor since I'm done with the driver, though.

Image

- Xander

Re: NXC: RFID-Sensor values?

Posted: 05 Nov 2010, 03:18
by hassenplug
My PSumo robots use RFID cards, so I've seen hundreds of cards scanned by kids.
http://www.teamhassenplug.org/sumo/PSumo.html

There are a few different types of id's I've seen.
1) all zeros
2) all 8s
3) valid ID

It's set-up so if the ID is not recognized, the card can simply be scanned again.

Steve

Re: NXC: RFID-Sensor values?

Posted: 05 Nov 2010, 18:38
by ronmcrae
I use RFID cards in my ATM machine programmed in NXC. I had significant problems when the brick is first powered up and the program runs the first time. It always takes several read attempts (usually between 4 and 7) before any card will return valid data. After it works it continues to work for the rest of time until the brick is power cycled. I messed with the program for a long time but nothing I did changed the symptoms. If the program is stopped and restarted without cycling power on the brick then the first card will always be read correctly.

Ron.