ok so i have had my Mega for a couple years collecting dust and the rfid reader whitch i could never get working but no more slacking off XD!! Now i plan on getting it working ! Since i have an Arduino Mega, copying and paste codeing wont work here so this is what i uploaded to my mega
#include <SoftwareSerial.h>
int val = 0;
char code[10];
int bytesread = 0;
#define rxPin 22 // RFID reader SOUT pin connected to Serial RX pin at 2400bps to digital pin 22
#define txPin 23 // nothing connected
void setup()
{
Serial.begin(2400); // Hardware serial for Monitor 2400bps
pinMode(24,OUTPUT); // Set digital pin 24 as OUTPUT to connect it to the RFID /ENABLE pin
digitalWrite(24, LOW); // Activate the RFID reader
}
void loop()
{
SoftwareSerial RFID = SoftwareSerial(rxPin,txPin);
RFID.begin(2400);
if((val = RFID.read()) == 10)
{ // check for header
bytesread = 0;
while(bytesread<10)
{ // read 10 digit code
val = RFID.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 == 10)
{ // if 10 digit read is complete
Serial.print("TAG code is: "); // possibly a good TAG
Serial.println(code); // print the TAG code
}
bytesread = 0;
delay(500); // wait for a second
}
}
(modified by moderator)
nothing happens when i swipe any rfid tag by please help
also your are redefining the serial connection on every loop and since your using an arduino mega as Grumpy_Mike suggested you could use one of the hardware serial ports and to check how many chars you have incoming on your serial port use Serial.available()
yes you are right, and since i am sure you have noticed i have ZERO coding knowledge. I just fount this on code on Aquino's website with a Google search and pasted it i know i have a lot more learning to do! could you please give me an example of what i should put in my code?
Connect the RFID reader to pins 14 and 15, and use Serial1 instead of the SoftwareSerial instance.
Paul Mike and every one else thank you for taking your time to help me. I know i am a little bit clueless when it comes to PBasic or Arduinos code so your input is deeply appreciated!
Paul you said to connect to pins 14 and 15 I am not even sure if i am connecting the device correctly
Please can you give some more detail as i don't understand
Here is how i have it connected now at home
Parallax RFID Arduino Mega ATMEGA1280
VCC 3V Pin
/ENABLE Digital pin 24
SOUT Digital Pin 22
GND GND on the Arduino
i dont know why in the code on Arduino Playground - PRFID WHY is the TX pin Declared ???? If you Like i can Post some pics or a video if you like!
Connect the RFID reader to pins 14 and 15, and use Serial1 instead of the SoftwareSerial instance.
Then is this how i should do it???????
Parallax RFID Arduino Mega ATMEGA1280
VCC 5V Pin
/ENABLE Communication TX PIN 1
SOUT Communication RX PIN 0
GND GND on the Arduino
Then is this how the code should look like
#include <Serial1.h>
int val = 0;
char code[10];
int bytesread = 0;
#define rxPin 0 // RFID reader SOUT pin connected to Serial RX pin at 2400bps to digital pin 22
#define txPin 14 // DO I TAKE A WIRE AND CONNECT IT TO RX pin 0 ?????
void setup()
{
Serial.begin(2400); // Hardware serial for Monitor 2400bps
pinMode(1,OUTPUT); // Set communication pin 1 as OUTPUT to connect it to the RFID /ENABLE pin
digitalWrite(1, LOW); // Activate the RFID reader
}
void loop()
{
Serial1 RFID = Serial1(rxPin,txPin);
RFID.begin(2400);
if((val = RFID.read()) == 10)
{ // check for header
bytesread = 0;
while(bytesread<10)
{ // read 10 digit code
val = RFID.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 == 10)
{ // if 10 digit read is complete
Serial.print("TAG code is: "); // possibly a good TAG
Serial.println(code); // print the TAG code
}
bytesread = 0;
delay(100); // wait for a second
}
}
No this is an enable pin and has to be placed low to enable the reader, it should not be connected to the TX line but any general output pin.
Then should i connect it to Communication TX PIN 14
and is my code correct like this
#include <Serial1.h>
int val = 0;
char code[10];
int bytesread = 0;
#define rxPin 0 // RFID reader SOUT pin connected to Serial RX pin at 2400bps to digital pin 22
#define txPin 1 // DO I TAKE A WIRE AND CONNECT IT TO RX pin 0 ?????
void setup()
{
Serial.begin(2400); // Hardware serial for Monitor 2400bps
pinMode(14,OUTPUT); // Set communication pin 1 as OUTPUT to connect it to the RFID /ENABLE pin
[glow=yellow,2,300]digital[/glow]Write(14, LOW); // Activate the RFID reader also should i take out the digital?
}
void loop()
{
Serial1 RFID = Serial1(rxPin,txPin);
RFID.begin(2400);
if((val = RFID.read()) == 10)
{ // check for header
bytesread = 0;
while(bytesread<10)
{ // read 10 digit code
val = RFID.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 == 10)
{ // if 10 digit read is complete
Serial.print("TAG code is: "); // possibly a good TAG
Serial.println(code); // print the TAG code
}
bytesread = 0;
delay(100); // wait for a second
}
}
You are aware that the IDE has a button labeled Verify, right? Why are you posting code that hasn't a snowballs chance in .... of compiling?
There is no Serial1.h file. Serial1 is an instance of the HardwareSerial class. It is already defined.
You do not create an instance of the Serial1 class called RFID. The RX and TX pins for Serial1 are known to the Serial1 instance, and they are not pins 0 and 1.
Even in the old code, creating a new instance of the SoftwareSerial class every pass through loop was stupid. Whoever wrote the code you started with was clueless.
Get rid of the first line in loop. Get rid of the #include statement.
Change all occurrences of RFID to Serial1. Move the Serial1.begin() statement to setup() where it belongs.
i am trying to learn with this project
after following your instructions i am still very confused and the code still dose not work
here is the revised code
int val = 0;
char code[10];
int bytesread = 0;
void setup()
{
Serial.begin(2400); // Hardware serial for Monitor 2400bps
pinMode(14,OUTPUT); // Set communication pin 1 as OUTPUT to connect it to the RFID /ENABLE pin
digitalWrite(14, LOW); // Activate the RFID reader also should i take out the digital?
}
void loop()
{
Serial1.begin(2400);
if((val = Serial1.read()) == 10)
{ // check for header
bytesread = 0;
while(bytesread<10)
{ // read 10 digit code
val = Serial1.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 == 10)
{ // if 10 digit read is complete
Serial.print("TAG code is: "); // possibly a good TAG
Serial.println(code); // print the TAG code
}
bytesread = 0;
delay(100); // wait for a second
}
}
my sout pin is connected to rx 0
my /enable pin is connected to tx3 14
Why are you still calling Serial1.begin() in loop()?
my sout pin is connected to rx 0
my /enable pin is connected to tx3 14
Why? Have you yet to figure out that SOUT is the OUTPUT from the RFID reader, so it needs to go to a Serial IN?
Have you not figured out that /enable needs to go to a digital pin that you set LOW?
Didn't Grumpy_Mike point out that pin 14 is associated with Serial3, not Serial1? You can use either one, but you must use the one that you connect SOUT to. And DO NOT connect SOUT to RX0.