Offline
Jr. Member
Karma: 0
Posts: 50
|
 |
« on: February 12, 2013, 01:06:08 pm » |
I'm trying to do something when rfid char match. here the code // RFID reader for Arduino // Wiring version by BARRAGAN <http://people.interaction-ivrea.it/h.barragan> // Modified for Arudino by djmatic // Re-Modified for Arduino and 125Khz JsxzLz RFID Kit from Ebay by Biohazard
// RFID reader comes with 11 pins: D3 D2 D1 Rest Mcst Gnd L1 L2 PC TX VCC // We need these to be connected: // Rest to Arduino pin 2 // Gnd to Arduino GND // L1 and L2 to the antenna // TX to Arduino RX0 // VCC To Arduino 5V
int val = 0; char code[14]; char michael[14] = {'4', 'B', '0', '0', '1', '0', '8', '5', '1', '3', '4', '7', '0', 'F'}; // 2 digits manufacture code // 10 digits card code // 2 digits parity bits
int bytesread = 0;
void setup() {
Serial.begin(9600); // RFID reader TX pin, Baud rate: 9600, Data bits: 8, stop bit: 1. pinMode(2,OUTPUT); // Set digital pin 2 as OUTPUT to connect it to the RFID RESET pin digitalWrite(2, HIGH); // Activate the RFID reader }
void loop() {
if(Serial.available() > 0) { // if data available from reader if((val = Serial.read()) == 10) { // check for header bytesread = 0; while(bytesread < 14) { // read 14 digit code if( Serial.available() > 0) { val = Serial.read(); if((val == 10)||(val == 13)) { // if header or stop bytes before the 10 digit reading break; // stop reading } code[bytesread] = val; // add the digit bytesread++; // ready to read next digit } } if(bytesread == 14) { // if 14 digit read is complete Serial.print("TAG code is: "); // possibly a good TAG Serial.println(code); // print the TAG code } bytesread = 0; digitalWrite(2, LOW); // deactivate the RFID reader for a moment so it will not flood delay(1500); // wait for a bit digitalWrite(2, HIGH); // Activate the RFID reader } } if (code = michael) { Serial.print("welcome michael"); }
} It give me this error when trying to copile it: error: invalid array assignment Checked on the net without any clue Thanks in advance
|
|
|
|
|
Logged
|
|
|
|
|
Queens, New York
Online
Edison Member
Karma: 28
Posts: 1556
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
|
 |
« Reply #1 on: February 12, 2013, 01:10:45 pm » |
What does bytesread get up to, 14 or less? Also something is wrong with this, "if (code = michael)" can you spot the mistake?
|
|
|
|
|
Logged
|
UNO, MEGA, NANO, 4x4 keypad, micro servos, RF transceivers, bluetooth, ultrasonic sensor, 20x4 I2C LCD, 3.2 TFT touch screen, L298N Dual motor driver, Voice Recognition 15W, Gameduino
Arduino Tutorials, coming soon.
"If your doing nothing, it does not mean your lazy, it just means your open for anything that suits you" - Unknown
|
|
|
|
Global Moderator
UK
Online
Brattain Member
Karma: 137
Posts: 19019
I don't think you connected the grounds, Dave.
|
 |
« Reply #2 on: February 12, 2013, 01:13:33 pm » |
Also something is wrong with this, "if (code = michael)" can you spot the mistake? Two things
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 311
Posts: 35476
Seattle, WA USA
|
 |
« Reply #3 on: February 12, 2013, 01:15:30 pm » |
Even if you fix the = problem (with ==), that is only going to compare the address where the two arrays start. It will NOT compare the contents of the arrays. You could use memcmp() to see if the data is the same. You can not use strcmp() since you do not have strings (NULL terminated arrays of chars). Serial.println(code); // print the TAG code This is wrong, too, because code is not a string. It is an array of chars, but it is NOT NULL terminated. And there is no room for the NULL terminator.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 50
|
 |
« Reply #4 on: February 12, 2013, 01:21:43 pm » |
My mistake, thanks for the ==. Don't no why i done that. Now the code working and it show me the 14 digit of the card in the serial monitor. I will try the memcmp() like you said and comeback to you thanks.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 50
|
 |
« Reply #5 on: February 12, 2013, 01:32:53 pm » |
It seems to work now but could you tell me how can i flush the array after print have been done cause now it always print after the good card have been pass. thanks
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Online
Brattain Member
Karma: 137
Posts: 19019
I don't think you connected the grounds, Dave.
|
 |
« Reply #6 on: February 12, 2013, 01:38:22 pm » |
Can't you just set the index, and write a zero into the first location in the array?
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 311
Posts: 35476
Seattle, WA USA
|
 |
« Reply #7 on: February 12, 2013, 01:41:01 pm » |
Can't you just set the index, and write a zero into the first location in the array? Even better would be to make the arrays one element larger and keep them NULL terminated as data is added. That way you can safely use them as strings (including using the more intuitive strcmp()).
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 50
|
 |
« Reply #8 on: February 12, 2013, 02:26:28 pm » |
Got it work now, just one last thing, here the code: // RFID reader for Arduino // Wiring version by BARRAGAN <http://people.interaction-ivrea.it/h.barragan> // Modified for Arudino by djmatic // Re-Modified for Arduino and 125Khz JsxzLz RFID Kit from Ebay by Biohazard
// RFID reader comes with 11 pins: D3 D2 D1 Rest Mcst Gnd L1 L2 PC TX VCC // We need these to be connected: // Rest to Arduino pin 2 // Gnd to Arduino GND // L1 and L2 to the antenna // TX to Arduino RX0 // VCC To Arduino 5V
int val = 0; char code[14]; char michael[14] = {'4', 'B', '0', '0', '1', '0', '8', '5', '1', '3', '4', '7', '0', 'F'}; char emilie[14] = {'0', '5', '0', '0', '1', '5', '1', '5', '6', '7', '3', '9', '0', 'D'};;
// 10 digits card code // 2 digits parity bits
int bytesread = 0;
void setup() {
Serial.begin(9600); // RFID reader TX pin, Baud rate: 9600, Data bits: 8, stop bit: 1. pinMode(2,OUTPUT); // Set digital pin 2 as OUTPUT to connect it to the RFID RESET pin digitalWrite(2, HIGH); // Activate the RFID reader Serial.println("rfid ready to read"); }
void loop() { boolean e_card = true; boolean m_card = true; if(Serial.available() > 0) { // if data available from reader if((val = Serial.read()) == 10) { // check for header bytesread = 0; while(bytesread < 14) { // read 14 digit code if( Serial.available() > 0) { val = Serial.read(); if((val == 10)||(val == 13)) { // if header or stop bytes before the 10 digit reading break; // stop reading } code[bytesread] = val; // add the digit bytesread++; // ready to read next digit } } if(bytesread == 14) { // if 14 digit read is complete if( memcmp(code, michael,14) != 0) m_card = false; if( memcmp(code, emilie,14) != 0) e_card = false; if (m_card) { Serial.println("welcome Michael"); } else if (e_card) { Serial.println("welcome Emilie"); } else; { Serial.println("Unknow tag"); } } bytesread = 0; digitalWrite(2, LOW); // deactivate the RFID reader for a moment so it will not flood delay(1500); // wait for a bit digitalWrite(2, HIGH); // Activate the RFID reader } } } Why i always getting unknow tag event if it a valide one. If i pass a good one it also print in unknow tag rfid ready to read welcome Emilie Unknow tag Thanks
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 311
Posts: 35476
Seattle, WA USA
|
 |
« Reply #9 on: February 12, 2013, 02:31:17 pm » |
else; { Serial.println("Unknow tag"); } What's that semicolon doing after the else statement?
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 50
|
 |
« Reply #10 on: February 12, 2013, 02:33:44 pm » |
Thanks, sorry for the newbie question, thanks everything is working.
|
|
|
|
|
Logged
|
|
|
|
|
|