Go Down

Topic: Serial Communication only works for UNO(not MEGA) (Read 1 time) previous topic - next topic

no245

Hello!

The code example below have been working flawlessly on Arduino UNO for me, however, when it's put on Arduino MEGA 2560, it doesn't seem to work at all.
The code consists of two parts: the sender and the reciever. It's a quite simple setup consisting of one Arduino MEGA sending 'a' and 'b' continously through serial communication. The problem seems to occur with the other Arduino MEGA which is supposed to recieve the input and print it out in its own serial monitor.

Sender:
Code: [Select]
#include <SoftwareSerial.h>

#define rxPin 0
#define txPin 1

SoftwareSerial mySerial =  SoftwareSerial(rxPin, txPin);

void setup()  {
  // define pin modes for tx, rx, led pins:
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);
  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);
  mySerial.println("Hello Board 2");
}

void loop()
{
  //continously send out 'a' and 'b'.
  mySerial.print('a');
  delay(100);
  mySerial.print('b');
  delay(100);
}


Reciever:
Code: [Select]
#include <SoftwareSerial.h>

#define rxPin 0
#define txPin 1

SoftwareSerial mySerial =  SoftwareSerial(rxPin, txPin);

void setup()  {
  // define pin modes for tx, rx, led pins:
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);
  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);
  mySerial.println("Hello Board 1");
}

void loop()
{
  // listen for new serial coming in:
  char someChar = mySerial.read();
  // print out the character:
  mySerial.println(someChar);
  delay(100);
}


I'm using Arduino 1.0, and you can see from the example above, i'm using the SoftwareSerial library.
First time I've posted on the Arduino board, so let me know if I've let anything out.

Thanks :)

dxw00d

Why are you using the hardware serial pins for SoftwareSerial? Why not use hardware serial?

Check the reference page for pins that you can use on a Mega. http://arduino.cc/en/Reference/SoftwareSerial

cjdelphi

i've learnt not to touch pins 0/1 never... unless it's purely of no use eg LED show, use 2/3 to send and to recv 3/2 (whatever that translates into on the mega, i only have the uno and ether10)

no245

Thank you very much, it works now :)

I changed the the pin RX to one of those in the link you posted.

dxw00d


Go Up