Go Down

Topic: Software Serial Example --- not working on MEGA. (Read 64 times) previous topic - next topic

Sally Shaper

May 19, 2017, 05:29 pm Last Edit: May 19, 2017, 06:17 pm by Sally Shaper
hi there,

I have a MEGA 2560, when i run the Software Serial Example,
I see only this in the Serial Monitor:

⸮⸮⸮⸮⸮⸮ ⸮

-- but not regular question marks, mirror image, backward question marks.


I don't see anything else.

It should print out 'goodnight moon'

  Serial.println("Goodnight moon!");


And i gather it should exchange some data between Serial and 'mySerial'

void loop() { // run over and over
  if (mySerial.available()) {
    Serial.println(mySerial.read());
  }
  if (Serial.available()) {
    mySerial.write(Serial.read());
  }
}


I have tried tinkering and ensure that both my Serial Monitor Window
and the baud rates specified in the code are the same:  4800.

When i do this, i at least get to see the 'Goodnight Moon' message.

If anyone has any insights into this problem, i would be very grateful
if you could whisper a hint or two. 

Thanks to anyone who replies.

Have a nice day :)








DrAzzy

Baud rate of Serial must match the baud rate you're using on the serial monitor.

You can use a different baud rate for the other serial ports.

Why are you using software serial on a Mega2560? You have three more hardware serial ports that avoid all the problems associated with software serial!

I can't assess why yours may not work as you have not posted all the code.

Also, read the "how to use this forum" thread which explains how to use code tags, please use them.
ATtiny core for 841+1634+828 and x313/x4/x5/x61/x7/x8 series Board Manager:
http://drazzy.com/package_drazzy.com_index.json
ATtiny breakouts (some assembled), mosfets and awesome prototyping board in my store http://tindie.com/stores/DrAzzy

pert

At line 34 in the SoftwareSerialExample sketch:
Code: [Select]
 Serial.begin(57600);
That configures Serial (which is connected to the USB jack on the Mega 2560) to run at 57600 baud.

At line 43 in the sketch:
Code: [Select]
 mySerial.begin(4800);
That configures the software serial port (which is on pins 10 and 11) to run at 4800 baud.

So the device connected to pins 10 and 11 needs to be communicating at 4800 baud but you need to set your Serial Monitor to 57600 baud.


If you need different baud rates you can just change those lines in the example.

-dev

Quote
Why are you using software serial on a Mega2560?
+1

Just use Serial1, Serial2 or Serial3 on pins 14-19.

Go Up