Problem with SoftwareSerial

Hi,
I have problem with sentence SoftwareSerial. I get to where the first message is displayed. No reception work.
I’m trying to use the serial port RX2 and TX2 Mega2560 arduino.
This is my code:

#include <SoftwareSerial.h>
int ledPin=13;
int entrada;
SoftwareSerial mySerial(17, 16); // RX, TX
void setup()
{
mySerial.begin(9600);
pinMode(ledPin,OUTPUT);
pinMode(17, INPUT);
pinMode(16, OUTPUT);
mySerial.println(“Para prender el led, presiona H”);
}
void loop()
{
if(mySerial.available()>0)
{
entrada=mySerial.read();
if(entrada==‘H’)
{
digitalWrite(ledPin, HIGH);
mySerial.println(“A presionado la tecla H”);
delay(100);
mySerial.println(" “);
mySerial.println(“Vuelve a presionar”);
}
if(entrada==‘L’)
{
digitalWrite(ledPin,LOW);
mySerial.println(“A presionado la tecla L”);
delay(100);
mySerial.println(”");
mySerial.println(“Vuelve a presionar”);
}
}
}

It does work. Use the serial port and TX0 RX0 Mega2560 arduino.
#include <SoftwareSerial.h>
int ledPin=13;
int entrada;
//SoftwareSerial mySerial(19, 18); // RX, TX
void setup() {
Serial.begin(9600);
pinMode(ledPin,OUTPUT);
Serial.println(“Para prender el led, presiona H”);
}
void loop() {
if(Serial.available()>0){
entrada=Serial.read();
if(entrada==‘H’){
digitalWrite(ledPin, HIGH);
Serial.println(“A presionado la tecla H”);
delay(100);
Serial.println(" “);
Serial.println(“Vuelve a presionar”);
}
if(entrada==‘L’){
digitalWrite(ledPin,LOW);
Serial.println(“A presionado la tecla L”);
delay(100);
Serial.println(”");
Serial.println(“Vuelve a presionar”);
}
}
}

1) Wrong place to put this, it should be in Programming Questions 2) Code tags! 3) Why are you trying to use Software Serial on a board that has 4 UART ports? Why not just use Serial1, Serial2 or Serial3.begin(...)?

4) Unless you plan on using a bluetooth module or some other form of Serial connection, the Serial monitor is only set to use Serial.begin(...), and as far to my knowledge, it can't be changed.

Hello. thanks for the help you. I am trying to adapt this example to my project.

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

I'll try what you indicate me.

So choose two pins other than one that are already set a UART ports. Most common are pins 2 and 3

One observation:

void setup()
{
  mySerial.begin(9600);
  pinMode(ledPin,OUTPUT);
  pinMode(17, INPUT);   <<< should be INPUT_PULLUP
  pinMode(16, OUTPUT);
  mySerial.println("Para prender el led, presiona H");
}

Or better still lose the pinMode() calls for 16 and 17 completely, the
SoftwareSerial library handles those.

So choose two pins other than one that are already set a UART ports. Most common are pins 2 and 3

Pay attention to which pins are capable of software serial on the Mega. Pins 2 and 3 are NOT.

Then, pay attention to the fact that you have three unused hardware serial ports on the Mega, and spend some time learning how to change the sketch to one of the HARDWARE serial ports rather than forcing the Mega to do software serial.