venkeeg
November 12, 2016, 7:53am
1
Hi,
I use an Arduino Mega 2560. Since today I have been experiencing a strange problem. The GPIO pins are able to take input and give output but nothing is displayed on the serial monitor .
Has anyone faced this ?
kindly suggest.
Regards,
Venkatesh.
Robin2
November 12, 2016, 8:53am
2
venkeeg:
kindly suggest.
Post your program. Without that we have no idea what you are trying to do.
How is the Mega connected to your PC?
...R
venkeeg
November 12, 2016, 2:54pm
3
Hi Robin,
Kindly find the code below. I am just trying to glow an LED for any character pressed on the bluetooth terminal installed on my mobile.
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10,11);
void setup()
{
pinMode(5,OUTPUT);
Serial.begin(9600);
mySerial.begin(9600);
}
void loop() // run over and over
{
if (mySerial.available())
{
char c = mySerial.read();
if(c >= 97 && c <= 122 || c >= 65 && c <= 90)
digitalWrite(5,HIGH);
Serial.write(c);
//Serial.println (c);
}
}
Regards.
Robin2
November 12, 2016, 4:25pm
4
Please use the code button </> so your code looks like this
and is easy to copy to a text editor. See How to use the Forum
Also please use the AutoFormat tool to indent the code for easier reading.
I will do it for you this time
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10,11);
void setup()
{
pinMode(5,OUTPUT);
Serial.begin(9600);
mySerial.begin(9600);
}
void loop() // run over and over
{
if (mySerial.available())
{
char c = mySerial.read();
if(c >= 97 && c <= 122 || c >= 65 && c <= 90)
{
digitalWrite(5,HIGH);
}
Serial.write(c);
//Serial.println(c);
}
}
Note that I have inserted a pair of {} for the second IF statement to clarify what it is supposed to do. I may not have done it as you intend.
Why are you using SoftwareSerial on a Mega when it has 3 spare HardwareSerial ports that work much better?
Put a message in setup() to prove that the printing is working - for example
Serial.println("My program is starting");
...R
Please use code tags when posting code. Edit your post, place [code]
before your code and [/code]
after your code.
Next you're using SoftwareSerial on a Mega. Why? You have 4 hardware serial ports available; use one of those.
I'm not quite sure of the operator precedence; try
if ((c >= 97 && c <= 122) || (c >= 65 && c <= 90))
venkeeg
November 13, 2016, 2:28am
6
Hi..
Thanks for the info.
is there a function to read the hardware serial ports ?
Regards.
You use exactly the same functions as for Serial; so e.g. Serial1.begin(), Serial1.read() and so on.
venkeeg
November 13, 2016, 4:55am
8
Used Serial2 ( pins 16,17) ..thanks a lot.