RFID storing data read from serial into an array

Hi everyone,

I've been trying to send tag numbers of 3 digits from bluetooth HC-05 and store it into an array of integers x[n] so that i can create a sort of tag numbers database sent over bluetooth on arduino .

But n doesn't increment and it stucks on 0 and thus i can't give access to more than one tag via bluetooth !!

Please Help !!!!!!!

here is the code so far :

void loop() {
uchar i, tmp, checksum1;
uchar status;
uchar str[MAX_LEN];
uchar RC_size;
uchar blockAddr; //Selection operation block address 0 to 63
String mynum = "";

str[1] = 0x4400;
//Find tags, return tag type
status = myRFID.AddicoreRFID_Request(PICC_REQIDL, str);
if (status == MI_OK)
{
Serial.println("RFID tag detected");
Serial.print(str[0],BIN);
Serial.print(" , ");
Serial.print(str[1],BIN);
Serial.println(" ");
}

//Anti-collision, return tag serial number 4 bytes
status = myRFID.AddicoreRFID_Anticoll(str);
if (status == MI_OK)
{
checksum1 = str[0] ^ str[1] ^ str[2] ^ str[3];
Serial.println("The tag's number is : ");
//Serial.print(2);
Serial.print(str[0]);
Serial.print(" , ");
Serial.print(str[1],BIN);
Serial.print(" , ");
Serial.print(str[2],BIN);
Serial.print(" , ");
Serial.print(str[3],BIN);
Serial.print(" , ");
Serial.print(str[4],BIN);
Serial.print(" , ");
Serial.println(checksum1,BIN);

// put your main code here, to run repeatedly:
while (Genotronex.available() >2){

int n;
for (n =0; n<10 ; n++){

int i;
for(i = 0 ; i < 3; i++){ BluetoothData = Genotronex.read();

  • // if number 1 pressed ....*
    _ y = BluetoothData - '0';_

_ x[n] = y[0]*100+y[1]*10+y[2]*1;_

}}}
delay(100);// prepare for next data ...

* // Should really check all pairs, but for now we'll just use the first*
* if(str[0] == x[n]) //You can change this to the first byte of your tag by finding the card's ID through the Serial Monitor*
* {*
* Serial.print("Helllo World!\n");*
* Serial.print(n);*

* }*
* Serial.println();*
* delay(1000);*
* }*

* myRFID.AddicoreRFID_Halt(); //Command tag i*
}

I suspect that the "while (Genotronex.available() >2)" statement should be within the "for(n=0" loop rather than the way you have put it.

The way your program is at the moment if there are less than 3 characters to read then that test will fail and the program begins again at the top of "loop()"- which is why n appears to be stuck at zero.

A better approach might be to let loop() do its thing and just count up to n reads eg

void loop(){
    static int n =0;
    int x[10];

    while (Genotronex.available() >2){
       // read 3 bytes into y[]

    }
    if (n<10) {
        x[n] = y[0]*100+y[1]*10+y[2]*1;
        n++;
    }; 
    
}

This will read the first 10 tags in. If you want to keep reading tags and forget the old ones simply reset n to zero once it reaches 10.

Thanks for your reply but unfortunately it didn't work :frowning:

The code I've posted above used to work properly for only one tag so when i send the tag number over bluetooth and then pass it over the RFID it reads it and prints "hello world" but when i send a different tag number and pass its corresponding card it replaces the first one .. So yeah, i want to send ID number of lets say 10 tags and when i pass any of them the "hello world" should be printed because they are within the array x[n] !

When i upload your code it looks like arduino doesn't receive anything from bluetooth !

  • static int n =0;*

int x[10];

  • while (Genotronex.available() >2){*

  • // read 3 bytes into y[]*

  • int i;*
    _ for(i = 0 ; i < 3; i++){ BluetoothData = Genotronex.read();_

y = BluetoothData - '0';
* }*
* if (n<10) {*
_ x[n] = y[0]100+y[1]10+y[2]1;
n++;

} };*_

delay(100);// prepare for next data ...

* // Should really check all pairs, but for now we'll just use the first*
* if(str[0] == x[n]) //You can change this to the first byte of your tag by finding the card's ID through the Serial Monitor*
* {*
* Serial.print("Helllo World!\n");*
* Serial.print(n);*
* }*

* Serial.println();*
* delay(1000);*
* }*

* myRFID.AddicoreRFID_Halt(); //Command tag i*
}

Please read this:-
How to use this forum
Because your post is breaking the rules about posting code.

Ok I'm sorry i didn't know about the code tags!

You can edit your post you know and make them right.
See how your code breakers into italics half way through. Code tags stop that.
And while you are at it post ALL the code so that it compiles.