Hello,
I got a arduino UNO and a RFID Module for Xmas.
I can set the RFID Module in to read mode and can also send a standby command.
I am now trying to get my code to read the ID from the Tag and Print to Serial all on one line.
This is what I have do so far.
#include <SoftwareSerial.h> //Include softSerial in the project
SoftwareSerial mySerial(10, 11); //softSerial rx, tx Pins
int incomingByte = 0; //incoming serial data
void setup()
{
//Start Hardware serial comms
Serial.begin(9600);
//start software comms
mySerial.begin(9600);
}
void loop()
{
//Send HEX command to mySerial
int inByte = Serial.read();
switch (inByte){
case 'r':
Serial.println("Auto read card Enabled");
mySerial.write(0x02);
break;
case 'p':
Serial.println("Standby Mode Enabled");
mySerial.write(0xab); //Not sure if there is a better way to send this all at once?
mySerial.write(0x02); //Not sure if there is a better way to send this all at once?
mySerial.write(0x10); //Not sure if there is a better way to send this all at once?
break;
}
//Send data only when received data
if (mySerial.available()) {
//Read the incomming byte:
incomingByte = mySerial.read();
//Send what come from mySerial to serial
Serial.print(incomingByte, HEX);
}
delay(100);
}
This is what I get in Serial with this code.
ac
d0
2 <- Should be 02, but shows it as only 2?? Same with other ID's that start with a 0
4a
I want it to read -> acd0024a then a new line.
I think I need to do something with "if (mySerial.available())" like <4 or >4. I'me not sure, Also a buffer flush?
This is the RFID module -> http://www.ebay.co.uk/itm/140642657638
Any help would be much appreciated.
--Mick--