RFID module software serial + serial read
greetings all!
im having bit of issue applying conditional value printed in serial monitor. have rfid module found here:
http://www.elechouse.com/elechouse/index.php?main_page=product_info&cpath=90_93&products_id=2156
it arduino source code, , not having problems getting module work. stated, trying add conditional once specific tag id printed in serial monitor (as doing), print message.
code below addition commented:
thanks ahead of time ^_^
im having bit of issue applying conditional value printed in serial monitor. have rfid module found here:
http://www.elechouse.com/elechouse/index.php?main_page=product_info&cpath=90_93&products_id=2156
it arduino source code, , not having problems getting module work. stated, trying add conditional once specific tag id printed in serial monitor (as doing), print message.
code below addition commented:
code: [select]
#include <softwareserial.h>
softwareserial myserial(2, 3); //pin2 rx, pin3 tx
int cmd[64];
int comlen =0;
int out_flag =0;
string result = string('77 08 92 73' ,dec);
int resulting = '4d085c49';
//byte c;
void setup()
{
serial.begin(9600);
myserial.listen();
serial.println("serial number displayed here if card detected module:\n");
// set data rate softwareserial port
myserial.begin(9600);
delay(10);
myserial.write(0x02); //send command rfid, please refer rfid manual
}
void loop() // run on , on
{
while (serial.available())
{
int = serialreadhexdigit();
//serial.println(a);
if(a>=0){
cmd[comlen] = a;
comlen++;
}
delay(10);
}
for(int i=0; i<comlen; i+=2){
int c = myserial.write( cmd[i]*16 + cmd[i+1]);
}
comlen =0;
byte c;
while (myserial.available()) {
c = myserial.read();
if (c<16) serial.print("0");
serial.print(c ,hex); //display serial number in hex
//serial.print(" ");
out_flag =1;
/////////// addition /////////////////////////////
if(serial.available())
{
c = serial.read();
if (c == resulting){
serial.println("im in");
}
}
//////////////////////////////////////////////////
}
if (out_flag >0) {
serial.println();
out_flag = 0;
}
}
int serialreadhexdigit()
{
byte c = (byte) serial.read();
if (c >= '0' && c <= '9') {
return c - '0';
}
else if (c >= 'a' && c <= 'f') {
return c - 'a' + 10;
}
else if (c >= 'a' && c <= 'f') {
return c - 'a' + 10;
}
else {
return -1; // getting here bad: means character invalid
}
}
thanks ahead of time ^_^
start off using auto format tool , re-posting code make readable.
Arduino Forum > Using Arduino > Programming Questions > RFID module software serial + serial read
arduino
Comments
Post a Comment