Hi everyone I was trying to understand why I can't make Arduino Mega 2560 Serial work properly. I tried this simple code (connecting TX pin 12 with RX pin 11) in order to check Serial.read() and Serial.write(). Once the code is uploaded and I open the serial monitor I get only "NotAvailable".
On the Arduino board the TX light is on while the RX is always off.
#include <SoftwareSerial.h>
SoftwareSerial test(11,12); //Rx Tx
void setup() {
test.begin(9600);
Serial.begin(9600);
}
void loop() {
if (test.available() > 0)
{
Serial.println(test.read());
}
else
{
Serial.println("NotAvailable");
test.write(15);
}
}
I also tried this sketch (without using SoftwareSerial.h library) and here I'm getting on the monitor is the number "10".
Of course pin connected are TX pin1 and RX pin0.
void setup() {
Serial.begin(9600);
}
void loop() {
if (Serial.available() > 0)
{
Serial.println(Serial.read());
}
else
{
Serial.println("Not Available");
Serial.write(15);
}
}
The problem is that in the first i'm not receiving anything and in the second the value is always the same (even if i change the number 15 with a char or another number).
Do you have any suggestion?
Thank you.