0

I am trying to store integer values of RFID tag numbers sent over bluetooth serial into an array so that the tag will be identified by the reader when passed by it.

while (Genotronex.available() > 2) { 
    int n; 
    for (n =0; n<10 ; n++){  // should read 10 Tags 
        int i; 
        for(i = 0 ; i < 3; i++){ 
            BluetoothData[i] = Genotronex.read(); 
            y[i] = BluetoothData[i] - '0'; // convert data received from BT to integer 

            x[n] = y[0]*100+y[1]*10+y[2]*1; // tag number of 3 digits 
        }
    }
} 
delay(100);// prepare for next data ... 

if(str[0] == x[n])  //if passed tag has the same number sent from BT 
{ 
    Serial.print("Helllo World!\n"); 
    Serial.print(n); 
} 
Ôrel
  • 7,044
  • 3
  • 27
  • 46
looney
  • 1
  • 1
  • `x[n]` should be out of the `i` loop scope. You should test if `BluetoothData[i]` is `<='9'`. Why `y` and `BluetoothData` ? – Ôrel Sep 17 '15 at 04:01
  • n stucks on 0 i don't get why! y stores 3 digit integers read from BT since BT sends only one char byte each time. Why should i test that ? – looney Sep 17 '15 at 05:30
  • `BluetoothData` store 3 `bytes` in your code – Ôrel Sep 17 '15 at 05:41
  • What data are you sending over Bluetooth? How is str[0] defined? x? – Hans Kilian Sep 17 '15 at 12:07
  • i'm sending rfid tag numbers over bluetooth so that i can create a sort of tag number database. str[0] is the first pair of tag numbers. x[n] is an array of integers that should contain the tag numbers of multiple rfid cards. – looney Sep 17 '15 at 13:45
  • Could you be more specific? Show the code that defines the variables and tell us what exact bytes you're sending, including any line feeds etc. Also, your comment says 'read 10 tags' but you only store 1 byte. The RFID tags I've seen have 5 byte ids. Can you explain why you only store one byte? – Hans Kilian Sep 18 '15 at 07:14

1 Answers1

0

If your logic is right the only error I find is that x[n] assignation is inside loop.

for (n =0; n<10 ; n++){  // should read 10 Tags 
    for(i = 0 ; i < 3; i++){ 
        BluetoothData[i] = Genotronex.read(); 
        y[i] = BluetoothData[i] - '0'; // convert data received from BT to integer 
    }
        x[n] = y[0]*100+y[1]*10+y[2]*1; // tag number of 3 digits 
}//end n->for loop

Try this.

jabujavi
  • 477
  • 5
  • 15
  • Thank you but assigning x[n] outside the loop still doesn't solve it. n has to increase each time allowing to store multiple values read from BT but i can't figure out why n attain its value at 0 ! – looney Sep 17 '15 at 13:40
  • See my code. The modification that I exposed before is in order to fix the overwriting of x array. – jabujavi Oct 19 '15 at 16:12