Go Down

Topic: Parallax RFID 28440 - Storing values (Read 396 times) previous topic - next topic


Hi all,

First time posting but have been wandering these forums for a while. 

This snippet of code has been around for a while and I have adapted mine from http://playground.arduino.cc/Learning/ParallaxRFIDreadwritemodule (second snippet / new tags). 

My setup is currently an Arduino Uno and WiFi shield, to be able to query the data drawn from the tag and of course a parallax R/W module.

Currently my goal is to be able to read the byte data from a particular memory sector (32, being the ID) and save these into variables or an array.  So far I have tried type setting the val variable to strings and concatenating strings using the strcat method.  However I've found this method quite resource hungry as jiberish and other unwanted functions are called.

So finally I have tried to consolidate the 4 'pass-throughs' that are made where the values from the card is stored in val. My aim is to be able to store all the values to form a single integer, although this integer is not always the same length.

Another problem I've encountered is that, even with the vanilla code that was found in the playground, the reader tends to read a card more than once in a short space of time, usually up to 6 instances can be displayed in the serial monitor, this was leading to difficulties accurately populating an array.

Here is the code I'm currently working with, both the setup and loops and the various functions they call:
Main sketch:
Code: [Select]
void setup()
  Serial.begin(9600);  // opens serial port, sets data rate to 9600 bps
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  Serial.println("Initialised Serial Port at 9600bps"); // prints to the serial monitor upon initialisation 

void loop()

Code: [Select]

#include <SoftwareSerial.h> // SoftwareSerial to power the serial communications;

#define RFID_READ 0x01 // Enable READ
#define RFID_WRITE 0x02 // Enable WRITE
#define txPin 6 // Enable digital pin 6
#define rxPin 8 // Enable digital pin 8

#define readMemorySector 32 // Define variable for accessing various memory sectors on a card

// Initialise SoftwareSerial to input and output pins for mySerial
SoftwareSerial mySerial(rxPin, txPin);

int val; // Buffer to store value when reading from a card, before printing to the serial monitor
int runs = 0; // Run counter

void setupRFIDREAD()

  mySerial.begin(9600); // initialises the rxPin and txPin using mySerial
  pinMode(txPin, OUTPUT); // defines txPin as OUTPUT   
  pinMode(rxPin, INPUT);  // defines rxPIN as INPUT


void suppressAll() //suppresses the "null result" from being printed if no RFID tag is present
    if(mySerial.available() > 0)
    { mySerial.read();

void loopRFIDREAD()
  int val;
  int readCount;
  mySerial.print("!RW"); //To communicate with the RFID Read/Write Module, the user must first send a three-byte header string of !RW (in ASCII), followed by the desired single-byte command (in hexadecimal).
  mySerial.write(byte(RFID_READ)); //Initiates the read function.
  mySerial.write(byte(readMemorySector));  // Indicates whichSpace is to be read, currently the write function writes to Space 4, thus needing to read space 4. Default was 32 which is the unique identifier.
  if(mySerial.available() > 0)
    val = mySerial.read();  //The mySerial.read() procedure is called, but the result is not printed because I don't want the "error message: 1" cluttering up the serial monitor.
      if (val != 1)  //If the error code is anything other than 1, then the RFID tag was not read correctly and any data collected is meaningless. In this case since we don't care about the resultant values they can be suppressed.
int myArray[] = { 0 }; //all elements 0
int index = 0;

// Print the values in the val buffer sequentially, prefixing for easy reading
for (readCount = 0; readCount < 4; readCount++){

if(mySerial.available() > 0) {
     val = mySerial.read();
     myArray[index] = val;
     memset(myArray, 0, sizeof(myArray));

// Delay 750 milliseconds before next read and print cycle


Please let me know if you need more information or if I should be heading in another direction with this.


Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131