Mega 2560 - Multiple Serial Connections

Hi,

I've had multiple Arduinos for some time, but in the past they've only had the 1 serial connection so I've never had to utilise multiple. I now have a project that I'll need to send and receive data over multiple serial connections from my Mega2560 and am not sure where to start. The serial info in the reference section only details using 1, the serial.XXX commands don't allow you to specify which serial ports to read/write to and a search hasn't found me much else :( Could someone please point me into the right direction for utilising the multiple serial connections the Mega has to offer - Preferably with some source code as well as detailed information.

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

The Arduino Mega has three additional serial ports: Serial1 on pins 19 (RX) and 18 (TX), Serial2 on pins 17 (RX) and 16 (TX), Serial3 on pins 15 (RX) and 14 (TX).

http://arduino.cc/en/Serial/Begin

Syntax

Serial.begin(speed)

Arduino Mega only: Serial1.begin(speed) Serial2.begin(speed) Serial3.begin(speed)

etc...

I think it is this simple:

If (Serial.available()>0){ // read serial port "0" dataport0 = Serial.read(); }

If (Serial1.available()>0){ // read serial port "1" dataport1 = Serial1.read(); }

If (Serial2.available()>0){ // read serial port "2" dataport2 = Serial2.read(); }

If (Serial3.available()>0){ // read serial port "3" dataport3 = Serial3.read(); }

Ahhh thank you both.

That first link from dxw00d was the one I looked at stating it had multiple serial ports (Which I knew) but not how to use them.

Thanks for the links, now I can get on with it :)

Hi , everyone , I am new to this , but I would appreciate any help as I am trying to use 485 ultrasound sensors linked to a 485 tranceiver and then arduino mega serial ports so I can link two identical 485 interface ultrasound sensors each on a different chip and then to a different port( serial 1, second on serial 2) for example ? Can they work together with no issues, I am afraid I havent got any written any code yet as I am gathering everything up in terms of connections and code but in practical principle can it be done and work ok, Thank you all,