1. Summary
  2. Files
  3. Support
  4. Report Spam
  5. Create account
  6. Log in

NXC: RFID-Sensor values?

Discussion specific to the intelligent brick, sensors, motors, and more.

NXC: RFID-Sensor values?

Postby doc-helmut » 03 Nov 2010, 10:30

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?
regards,
HaWe
±≠≈αγδεωΔΦΣ∫√∅∞
NXC CHESS for NXT: http://www.mindstormsforum.de/viewtopic.php?f=70&t=6790
indispensable for NXC + EV3-C: easy + trouble-free network & sensor+motor remote control for rs485, BT, USB!
User avatar
doc-helmut
 
Posts: 2425
Joined: 29 Sep 2010, 14:25

Re: NXC: RFID-Sensor values?

Postby mightor » 03 Nov 2010, 10:38

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
| My Blog: I'd Rather Be Building Robots (http://botbench.com)
| RobotC 3rd Party Driver Suite: (http://rdpartyrobotcdr.sourceforge.net)
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)
User avatar
mightor
Site Admin
 
Posts: 1060
Joined: 25 Sep 2010, 15:02
Location: Rotterdam, Netherlands

Re: NXC: RFID-Sensor values?

Postby gloomyandy » 03 Nov 2010, 10:59

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
User avatar
gloomyandy
 
Posts: 320
Joined: 29 Sep 2010, 05:03

Re: NXC: RFID-Sensor values?

Postby doc-helmut » 03 Nov 2010, 12:23

thx to both of you for the help!
:)
regards,
HaWe
±≠≈αγδεωΔΦΣ∫√∅∞
NXC CHESS for NXT: http://www.mindstormsforum.de/viewtopic.php?f=70&t=6790
indispensable for NXC + EV3-C: easy + trouble-free network & sensor+motor remote control for rs485, BT, USB!
User avatar
doc-helmut
 
Posts: 2425
Joined: 29 Sep 2010, 14:25

Re: NXC: RFID-Sensor values?

Postby afanofosc » 03 Nov 2010, 13:49

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
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
User avatar
afanofosc
Site Admin
 
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN

Re: NXC: RFID-Sensor values?

Postby linusa » 03 Nov 2010, 13:52

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...
RWTH - Mindstorms NXT Toolbox for MATLAB
state of the art in nxt remote control programming
http://www.mindstorms.rwth-aachen.de
MotorControl now also in Python, .net, and Mathematica
User avatar
linusa
 
Posts: 228
Joined: 16 Oct 2010, 11:44
Location: Aachen, Germany

Re: NXC: RFID-Sensor values?

Postby mightor » 03 Nov 2010, 13:56

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
| My Blog: I'd Rather Be Building Robots (http://botbench.com)
| RobotC 3rd Party Driver Suite: (http://rdpartyrobotcdr.sourceforge.net)
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)
User avatar
mightor
Site Admin
 
Posts: 1060
Joined: 25 Sep 2010, 15:02
Location: Rotterdam, Netherlands

Re: NXC: RFID-Sensor values?

Postby hassenplug » 05 Nov 2010, 03:18

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
---> Link to lots of MINDSTORMS stuff under my picture --->
User avatar
hassenplug
 
Posts: 346
Joined: 27 Sep 2010, 03:05

Re: NXC: RFID-Sensor values?

Postby ronmcrae » 05 Nov 2010, 18:38

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.
ronmcrae
 
Posts: 33
Joined: 28 Sep 2010, 14:56


Return to Mindstorms Hardware

Who is online

Users browsing this forum: No registered users and 1 guest