Problems using serial port (TX and RX)

Good evening,

I've bought a RFID module for my Arduino Leonardo. I have made an code that waits for an input of RDM630 (RFID module) by the serial port. However, when I passed the card by the antenna, the module's led blinked (saying that had occured a reading), but the Arduino's RX led didnt blink, and my code hasn't worked (It was supposed to write the card number on the serial monitor).

To check if the module was sending data for by it's TX pin, I connected a led on this port (that is active low), and the led that was normally on, oscillated when I passed the card, what I believe be the data sending.

I tried other people codes, some of them using virtual serial ports implemented in other digital pins (e.g. 6 e 7), but i got no result again...

I believe the problem is at the data recieving by the Arduino, once I tested the data sending of the module (at least, is what i think).

Has someone ever faced a problem like this before? Does the serial communication have to be initialized in some other way that is not Serial.begin(baudrate)?

Thank you very much!

Perhaps post your code?

my code is simple:

void setup(){
  Serial.begin(9600);
}

void loop(){
  int a = Serial.read();
  Serial.println(a);
  delay(500);
}

I believe the serial port is being used by the PC, because I write a data in the serial monitor and I see that it's printed. Maybe the problem is that the port (the only one I have) is dedicated only with the communication with the PC, and ignores the data from the module. How can I test if my module is correct if I need to print my results, and feed with eletricity my arduino using USB (dont know if interferes on the dedication of serial port).

PS: The final project that I am doing does not have an communication with PC

Thanks!

I think your problem is that the Serial class on the Leonardo only refers to the usb/serial connection. The TX/RX serial pins are controlled by by the Serial1 class.

dxw00d, I tried to google Serial class to find out more about it, but I couldnt find something intresting. Could you tell me more about it? There is any way to use UART's port (that usually is dedicated to the pc)?

sofiz:
I tried to google Serial class to find out more about it, but I couldnt find something intresting.

This is interesting:

http://arduino.cc/en/Reference/Serial

Guys, solved the problem!

I was supposing that the UART was dedicated to communication with the PC. However, in Leonardo version, the Atmel's chip is USB-built in, so, the UART is not dedicated to PC, and to gain access to data on the RX and TX pins (digital 0 and 1 pins) you have to instanciate the UART as Serial1. So, you inicialize Serial1.begin() and read/write using Seria1.read()...

Because of this USB-built in feature, you can even read the UART and print in the serial monitor, using the example below:

Serial.begin(57600);
Serial1.begin(9600);

/*your code*/

a = Serial1.read();
Serial.println(a);

/*your code*/

As dxw00d said then.


Rob