Repeated reads on RFID Reader

Still a bit complex. What does this do?

void setup()
{
Serial.begin(9600);
}

void loop()
{
if (Serial.available()>0)
  {
  int data1=Serial.read();
  Serial.println((char) data1);
   } 
}

wildbill: Still a bit complex. What does this do?

void setup()
{
Serial.begin(9600);
}

void loop() { if (Serial.available()>0)   {   int data1=Serial.read();   Serial.println((char) data1);   } }

Similar behavior...it reads multiple times if I hold the card on it for longer. If I move the card away quickly enough, reads only once. But there doesn't seem to be a predictable behavior.

Well, that data sheet seems a bit vague, but I don't see anything there that indicates a way to change modes. Could it be that there are two versions of the reader? If so, you're going to have to solve it in software.

Yeah it is very unhelpful. I tried using the millis() function too...

void loop()
{
if ((Serial.available>0) && ((millis()-lastread)>5000))
  {
    data1=Serial.read;
     .....
     ....
  }
lastread=millis();
}

It simply waited for 5 seconds before reading from serial the first time, thereafter time between multiple reads was 5 seconds, even though I had moved the card away. Its like the serial buffer is storing stuff and giving a positive to Serial.available more than once....and there is no way to control when it should be emptied. I found this here, in the documentation for the Serial function: http://arduino.cc/en/Serial/Flush

flush() Description Waits for the transmission of outgoing serial data to complete. (Prior to Arduino 1.0, this instead removed any buffered incoming serial data.)

So earlier there was a way to clear the buffer after reading. Now there isn't.

Multiple reads. Card readers are supposed to do this. If you turned it off after first read, how would it detect the next card ?

You have to deal with it in software.

Given that the device has an RX pin, I would assume that there are commands you can send it - perhaps you can fix the mode that way. It doesn't look easy to find any documentation for how that works though. Perhaps try sending enter or question mark & see if it emits any help text.

Boardburner2:
Multiple reads.
Card readers are supposed to do this.
If you turned it off after first read, how would it detect the next card ?

You have to deal with it in software.

I guess you are right.

wildbill:
Given that the device has an RX pin, I would assume that there are commands you can send it - perhaps you can fix the mode that way. It doesn’t look easy to find any documentation for how that works though. Perhaps try sending enter or question mark & see if it emits any help text.

Its frustrating that they don’t have good documentation. But will try this and get back to you. I spent a lot of time last night trying to stop it from reading the serial.
At one point, I added a line to print the Serial.available() value on the monitor - the number of bytes available at the buffer. One thing I noticed was this - at first read, the number of bytes available was around 52, then on each subsequent ‘automatic’ read, i.e. the multiple reads, the number of bytes decreased. I did a number of reads, and the results were consistent…the number of bytes are decreasing. Now this might be normal or obvious behavior, but what I understand is the serial buffer is filling up beyond the 14 bytes the ID card sends.

To counter this, I tried using the readbytesuntil() function, but sadly that seems to take only char arguments. I was thinking of reading bytes until the terminating number (last number of the cards ID) has been read. Is there a way to use this function?

Thanks, UJ

Ok, I am chugging along on this project now. I have tried to do many things to get the RFID reader to read the card just once, but haven't been very successful. I tried:

  • Using time: Reading (Serial.read()) only if((Serial.available()>0 && (millis()-lastread)>5000)
  • No. of bytes in buffer:Reading only if the serial buffer has a fixed number of bytes (if Serial.available()==14...bad idea, I kind of new it before I tried, buts till
  • Using time, again: Here the Serial.read() is called, but the call to the function that compares the read card to the stored cards happens only if the difference between 'lastread ' and millis9) is more than 5000

The third function somewhat gives me what I want, as in I can hide from the 'user' that the card is being read more than once, but it doesn't make me happy...

So anyway, that's where I am at. .but I am kind of sick of the RF reader now. I am planning to start working on another project. My girlfriend's birthday is coming up in a couple months, and I want to make a lamp for her. RGB lamp, where she can set the color she wants from her mobile phone.

I have most of the stuff figured out:

  1. I will be using a simple RGB LED I have. I only need to pass R,G and B values to it thru PWM pins.
  2. For the mobile app, I am using Processing...since it makes using color just so easy. I have currently planned to have the processing sketch display a color wheel image on the phone screen, and I can use the color(mouseX, mouseY) function followed by red(), green() and blue() functions to get the RGB values.

I am stuck at the bluetooth module now. What can I use for the bluetooth? I want to have the lamp to be discoverable on our phones, but I want it so that it pairs only with my phone and her phone. Also, I want to keep the configuration part for the bluetooth simple, since I won't be around her to configure it from her phone (we live in different cities). I want it to be so that she scans the bluetooth devices on her phone, selects the lamp, pairs with it (all this ideally through the Processing app) and she can be on her way setting the color she wants.

Also, I wish to point out that I will be using a Arduino Nano in the lamp (i have the Nano as a spare) so using bluetooth shields is not really an option. I am planning on using this one: http://www.protocentral.com/wireless/173-protoblue-serial-bluetooth-adapter.html

Will it do the job? Thanks, uj

Any hints? :relaxed:

Why have you changed the title of the thread? And it still doesn’t mention RFID which seems to be the main topic being discussed?

…R

Robin2: Why have you changed the title of the thread? And it still doesn't mention RFID which seems to be the main topic being discussed?

...R

I should have changed it to RFID related earlier, but my present query is about Bluetooth modules. I didn't want to start another thread.

uberjoker: Any hints? :relaxed:

Well, I don't know what an RFID is but your link is to a plain-vanilla HC-06 bluetooth module, and it can run two way traffic between Android and Arduino just fine.

If you are new to that, this link may be useful.

http://homepages.ihug.com.au/~npyner/Arduino/GUIDE_2BT.pdf

uberjoker: I should have changed it to RFID related earlier, but my present query is about Bluetooth modules. I didn't want to start another thread.

Start as many threads as you like. Separate threads for separate topics are less confusing. Bear in mind that others will be learning from your questions and the answers they attract.

Changing the name of a thread (apart from to correct mistakes) makes it very difficult for people trying to find advice in a thread they had seen some time ago.

...R

Nick_Pyner:

uberjoker: Any hints? :relaxed:

Well, I don't know what an RFID is but your link is to a plain-vanilla HC-06 bluetooth module, and it can run two way traffic between Android and Arduino just fine.

If you are new to that, this link may be useful.

http://homepages.ihug.com.au/~npyner/Arduino/GUIDE_2BT.pdf

thanks! Yup this helps!

Robin2:

uberjoker:
I should have changed it to RFID related earlier, but my present query is about Bluetooth modules. I didn’t want to start another thread.

Start as many threads as you like. Separate threads for separate topics are less confusing. Bear in mind that others will be learning from your questions and the answers they attract.

Changing the name of a thread (apart from to correct mistakes) makes it very difficult for people trying to find advice in a thread they had seen some time ago.

…R

Ok, will do. Sorry for messing this up for everyone.

Hello everyone.

After fighting with the same problem, I managed to solve and avoid that even if we have readings, I do not save it to do the checks

we read the id.
we enter to check with our id
we set id to 0
and we generate a timeout until the rdm, although update () is available, it can save again what it is reading to id

and above all sorry for my poor English

#include <rdm6300.h>
#define RDM6300_RX_PIN 4 // pin for RX rmd6300

int AbrirCoche=5; //rele Abrir
int CerrarCoche=6; // rele Cerrar
int PinLedPuerta=9; // PinLedPuerta
long ID1=5722872; // Los Id a comprobar
long ID2=5722872; // Los Id a comprobar
long Idleido=1; // Id Leido
int aob=0; // encargado de variar entre abrir y cerrar estado 0 o 1
int xlog=0; // control del tiempo para no leer Id cuenta atras simple

Rdm6300 rdm6300;

void setup()
{
Serial.begin(9600);
pinMode(AbrirCoche,OUTPUT);
pinMode(CerrarCoche,OUTPUT);
pinMode(PinLedPuerta,OUTPUT);
rdm6300.begin(RDM6300_RX_PIN);
Serial.println("\n Preparado para leer rdm6300…");
}
void loop()
{
if (rdm6300.update())
{ if( xlog <= 0) {
Idleido = (rdm6300.get_tag_id());
Serial.println(Idleido);
digitalWrite(PinLedPuerta,HIGH);
delay(100);
digitalWrite(PinLedPuerta,LOW); } //end if( xlog <= 0)
} // end if (rdm6300.update())

// check ID

if(Idleido==ID1 && Idleido==ID2 )
{
if (aob == 1) { // Cerrar
digitalWrite(CerrarCoche,HIGH);
delay(100);
digitalWrite(CerrarCoche,LOW);
aob=0;
Serial.println(“Coche cerrado !!”); }
else { // Abrir
digitalWrite(AbrirCoche,HIGH);
delay(100);
digitalWrite(AbrirCoche,LOW);
aob=1;
Serial.println(“Coche abierto !!”); }
Idleido=0; // borramos IdLeido para evitar que vuelva a entrar
xlog=15; // ponemos contrador a 15* delay(100);
} // end if(Idleido==ID1 && Idleido==ID2 )

// control del tiempo hasta cual no guardara otro Id
delay(100);
xlog=xlog-1;
Serial.println(xlog);
} // fin Void loop

and with the variable of milis

#include <rdm6300.h>
#define RDM6300_RX_PIN 4 // pin for RX rmd6300

int AbrirCoche=5; //rele Abrir
int CerrarCoche=6; // rele Cerrar
int PinLedPuerta=9; // PinLedPuerta
long ID1=5722872; // Los Id a comprobar
long ID2=5722872; // Los Id a comprobar
long Idleido=1; // Id Leido
int aob=0; // encargado de variar entre abrir y cerrar estado 0 o 1
long lastread;

Rdm6300 rdm6300;

void setup()
{
Serial.begin(9600);
pinMode(AbrirCoche,OUTPUT);
pinMode(CerrarCoche,OUTPUT);
pinMode(PinLedPuerta,OUTPUT);
rdm6300.begin(RDM6300_RX_PIN);
Serial.println("\n Preparado para leer rdm6300…");
}
void loop()
{
if (rdm6300.update())
{ if((millis()-lastread)>2000) {
Idleido = (rdm6300.get_tag_id());
Serial.println(Idleido);
digitalWrite(PinLedPuerta,HIGH);
delay(100);
digitalWrite(PinLedPuerta,LOW); } //end if( xlog <= 0)
} // end if (rdm6300.update())

// check ID

if(Idleido==ID1 && Idleido==ID2 )
{
if (aob == 1) { // Cerrar
digitalWrite(CerrarCoche,HIGH);
delay(100);
digitalWrite(CerrarCoche,LOW);
aob=0;
Serial.println(“Coche cerrado !!”); }
else { // Abrir
digitalWrite(AbrirCoche,HIGH);
delay(100);
digitalWrite(AbrirCoche,LOW);
aob=1;
Serial.println(“Coche abierto !!”); }
Idleido=0; // borramos IdLeido para evitar que vuelva a entrar
lastread=millis();
} // end if(Idleido==ID1 && Idleido==ID2 )

} // fin Void loop