Serial communication between 2 Arduinos, 2 Computers and a PixHawk

Hi,
I'd like to use 2 arduinos for monitoring, but I need you help to see if it is possible or not to make.

I have on computer a software that is named Mission planner that can be connected directly to an hardware card (PixHawk) by USB (that is transform into Serial).

  • The final goal of this project is to use Lora Modules to make the communication between Mission Planner and the PixHawk.
  • The first step for me is to do that without the Lora, only Serial communication:

To do that I use 2 arduinos (Mega and Duemilanove), two computers and a PixHawk (see image attached)

  1. The first computer is running Mission planner and is connected to the Adruino Duemilanove with the Serial port (by the USB)
  2. The Arduino Duemilanove is connected to the Arduino Mega with a SoftSerial named softSerialInterArduinos (on both Arduino it is SoftSerial)
    3, The Arduino Mega is connected to the PixHawk with another SoftSerial named softSerialArdupilot

---> Full diagram HERE

So I did that and of course it doesn't work....

Questions:
A) Can I have 2 SoftSerials on Arduino Mega?
B) Can I have 1 SoftSerial on Arduino Duemilanove?
C) Doe the Serial communication is fullduplex?
D) Can it works

On the Arduino Mega Side

#include <SoftwareSerial.h>

SoftwareSerial softSerialInterArduinos(12, 13); // 12=RX, 13=TX
SoftwareSerial softSerialArdupilot(10, 11); // 10=RX, 11=TX

int x = 0;
char c = ' ';
int y = 0;
char readByteInterArduinos = ' ';
char writtenByteInterArduinos = ' ';
char readByteArdupilot = ' ';
char writtenByteArdupilot = ' ';

void setup() {
  Serial.begin(57600);
  softSerialArdupilot.begin(57600);
  softSerialInterArduinos.begin(57600);
}

void loop() {

  //if(softSerialInterArduinos.available() && softSerialArdupilot.available() && Serial.available())
  if(true)
  {
  //Serial.print(" Healthy ");
    
  readByteInterArduinos = softSerialInterArduinos.read();
  readByteArdupilot = softSerialArdupilot.read();

  if(readByteInterArduinos!=0xFFFFFFFF){Serial.print(" readByteInterArduinos");Serial.print(readByteInterArduinos); }
  
  softSerialInterArduinos.write(&readByteArdupilot,1);
  softSerialArdupilot.write(&readByteInterArduinos,1);
  }
}

On the Arduino Duemilanove Side

#include <SoftwareSerial.h>

SoftwareSerial softSerialInterArduinos(2, 3); // 2=RX, 3=TX

int x = 0;
char c = ' ';
int y = 0;
char readByteInterArduinos = ' ';
char writtenByteInterArduinos = ' ';
char readByteArdupilot = ' ';
char writtenByteArdupilot = ' ';

void setup() {
  Serial.begin(57600);
  softSerialInterArduinos.begin(57600);
}

void loop() {

  //if(softSerialInterArduinos.available() && Serial.available())
  if(true)
  {
    readByteInterArduinos = softSerialInterArduinos.read();
    readByteArdupilot = Serial.read();
    softSerialInterArduinos.write(&readByteArdupilot,1);
  }
 
}

A few questions:
Where is the problem located; meaning does the 2nd PC echo the serial communications?
Is the Lora module you are planning to use able to handle the data rate you would need to send all the mission planning data?

The issue is: the communication between the 2 Arduinos does not work (softSerialInterArduinos), but I can see data received between PixHawk and Arduino Mega on softSerialArdupilot.
Theoretically the Lora module (2.4 Ghz if I need speed) is able to handle the data rate (Crossfire radio use Lora system 900 MHz / 2.4 Ghz and is able to manage it), I can go slower (9600), but of course I feel it will be a complete second projet to use the Lora module

1 Like

May help, but you'll be disappointed. Only one receiving software serial will work. I haven't looked into it, but I suspect the root cause is blocking code. Watching an input for serial comms is time-intensive. You'll have to dig deeper, but I suspect if you really want multiple serial, you'd be better to use something like a Mega, which has multiple hardware serial ports. Others will likely have better advice.
C

1 Like

Sorry, browsed your info further - why software serial for two ports on a Mega? I thought it had multiple hardware serial, which can be used independently?
I think that's your problem. You need to implement at least one of those using the actual ports on the Mega, not using soft serial.

C

Serial pin assignments:

  • Serial: 0 (RX) and 1 (TX); Serial 1: 19 (RX) and 18 (TX); Serial 2: 17 (RX) and 16 (TX); Serial 3: 15 (RX) and 14 (TX). Used to receive (RX) and transmit (TX) TTL serial data. Pins 0 and 1 are also connected to the corresponding pins of the ATmega16U2 USB-to-TTL Serial chip.

Hope this helps.

1 Like

yes you're right ! thanks

1 Like

(post deleted by author)

Hi
I coded two simpler programs, using the Serial ports of the Arduino mega: Serial, Serial2 and Serial3, only 1 SoaftSerial on Duemilanove side:

Receiver (Arduino mega)

uint8_t val;

void setup() {
  Serial.begin(9600); //PC Monitoring
  Serial2.begin(9600); //Arduinos
  Serial3.begin(9600); //PixHawk
}

void loop() {
  byte n = Serial2.available();
  if(n >= 1) 
  {
    val = Serial2.read();
    Serial3.write(val);
    if(val!=0xFF){Serial.print(">>>"); Serial.println(val, HEX); }

    val = Serial3.read();
    Serial2.write(val);
    if(val!=0xFF){Serial.print("<<<");Serial.println(val, HEX); }
  }
  
}

Sender (Arduino Duemilanove)

#include <SoftwareSerial.h>

SoftwareSerial SUART(5, 6); //RX = 5, TX = 6

uint8_t val;

void setup() 
{
  // Begin the Serial at 9600 Baud
  Serial.begin(9600);
  SUART.begin(9600);   
}

void loop() 
{
  val = Serial.read();
  SUART.write(val);

  val = SUART.read();
  Serial.write(val);
}

But according to the log the communication is going only on one way (only >>> and no <<<) :

23:07:56.504 -> >>>BE
23:07:56.504 -> >>>42
23:07:56.504 -> >>>2
23:07:56.504 -> >>>0
23:07:56.541 -> >>>0
23:07:56.541 -> >>>0
23:07:56.541 -> >>>2
23:07:56.541 -> >>>1
23:07:56.541 -> >>>C5
23:07:56.579 -> >>>C
23:07:56.579 -> >>>FE
23:07:56.579 -> >>>6
23:07:56.579 -> >>>4F
23:07:56.579 -> >>>BE
23:07:56.579 -> >>>42
23:07:56.617 -> >>>2
23:07:56.617 -> >>>0
23:07:56.617 -> >>>0
23:07:56.617 -> >>>0
23:07:56.617 -> >>>2
23:07:56.617 -> >>>1
23:07:56.652 -> >>>54
23:07:56.652 -> >>>59
23:07:56.652 -> >>>FE
23:07:56.652 -> >>>6
23:07:56.652 -> >>>50
23:07:56.689 -> >>>BE
23:07:56.689 -> >>>42
23:07:56.689 -> >>>2
23:07:56.689 -> >>>0
23:07:56.689 -> >>>0
23:07:56.727 -> >>>0
23:07:56.727 -> >>>6
23:07:56.727 -> >>>1
23:07:56.727 -> >>>3C
23:07:56.727 -> >>>57
23:07:56.727 -> >>>FE
23:07:56.765 -> >>>6
23:07:56.765 -> >>>51
23:07:56.765 -> >>>BE
23:07:56.765 -> >>>42
23:07:56.765 -> >>>2
23:07:56.765 -> >>>0
23:07:56.803 -> >>>0
23:07:56.803 -> >>>0
23:07:56.803 -> >>>6
23:07:56.803 -> >>>1
23:07:56.803 -> >>>AD
23:07:56.803 -> >>>2
23:07:56.840 -> >>>FE
23:07:56.840 -> >>>6
23:07:56.840 -> >>>52
23:07:56.840 -> >>>BE
23:07:56.840 -> >>>42
23:07:56.878 -> >>>4
23:07:56.878 -> >>>0
23:07:56.878 -> >>>0
23:07:56.878 -> >>>0
23:07:56.878 -> >>>A
23:07:56.878 -> >>>1
23:07:56.915 -> >>>70
23:07:56.915 -> >>>1
23:07:56.915 -> >>>FE
23:07:56.915 -> >>>6
23:07:56.915 -> >>>53
23:07:56.915 -> >>>BE
23:07:56.953 -> >>>42
23:07:56.953 -> >>>4
23:07:56.953 -> >>>0
23:07:56.953 -> >>>0
23:07:56.953 -> >>>0
23:07:56.991 -> >>>A
23:07:56.991 -> >>>1
23:07:56.991 -> >>>E1
23:07:56.991 -> >>>54
23:07:56.991 -> >>>FE
23:07:56.991 -> >>>6
23:07:57.029 -> >>>54
23:07:57.029 -> >>>BE
23:07:57.029 -> >>>42
23:07:57.029 -> >>>4
23:07:57.029 -> >>>0
23:07:57.066 -> >>>0
23:07:57.066 -> >>>0
23:07:57.066 -> >>>6
23:07:57.066 -> >>>55
23:07:57.066 -> >>>0
23:07:57.066 -> >>>9
23:07:57.066 -> >>>0
23:07:57.104 -> >>>0
23:07:57.104 -> >>>6
23:07:57.104 -> >>>2
23:07:57.104 -> >>>1
23:07:57.104 -> >>>C
23:07:57.142 -> >>>1
23:07:57.142 -> >>>6
23:07:57.142 -> >>>0
23:07:57.142 -> >>>0
23:07:57.142 -> >>>FE
23:07:57.142 -> >>>0
23:07:57.175 -> >>>2C
23:07:57.175 -> >>>42
23:07:57.175 -> >>>1
23:07:58.959 -> >>>FE
23:07:58.959 -> >>>9
23:07:58.959 -> >>>5D
23:07:58.959 -> >>>BE
23:07:58.997 -> >>>0
23:07:58.997 -> >>>0
23:07:58.997 -> >>>0
23:07:58.997 -> >>>0
23:07:58.997 -> >>>0
23:07:59.034 -> >>>6
23:07:59.034 -> >>>8
23:07:59.034 -> >>>0
23:07:59.034 -> >>>0
23:07:59.034 -> >>>3
23:07:59.034 -> >>>A0
23:07:59.072 -> >>>B5
23:08:01.342 -> >>>FE
23:08:01.342 -> >>>9
23:08:01.342 -> >>>5E
23:08:01.380 -> >>>BE
23:08:01.380 -> >>>0
23:08:01.380 -> >>>0
23:08:01.380 -> >>>0
23:08:01.380 -> >>>0
23:08:01.380 -> >>>0
23:08:01.417 -> >>>6
23:08:01.417 -> >>>8
23:08:01.417 -> >>>0
23:08:01.417 -> >>>0
23:08:01.417 -> >>>3
23:08:01.417 -> >>>9E
23:08:01.455 -> >>>36
23:08:03.725 -> >>>FE
23:08:03.725 -> >>>9
23:08:03.725 -> >>>5F
23:08:03.725 -> >>>BE
23:08:03.725 -> >>>0
23:08:03.763 -> >>>0
23:08:03.763 -> >>>0
23:08:03.763 -> >>>0
23:08:03.763 -> >>>0
23:08:03.763 -> >>>6
23:08:03.763 -> >>>8
23:08:03.800 -> >>>0
23:08:03.800 -> >>>0
23:08:03.800 -> >>>3
23:08:03.800 -> >>>74
23:08:03.800 -> >>>48
23:08:06.062 -> >>>FE
23:08:06.099 -> >>>9
23:08:06.099 -> >>>60
23:08:06.099 -> >>>BE
23:08:06.099 -> >>>0
23:08:06.099 -> >>>0
23:08:06.099 -> >>>0
23:08:06.137 -> >>>0
23:08:06.137 -> >>>0
23:08:06.137 -> >>>6
23:08:06.137 -> >>>8
23:08:06.137 -> >>>0
23:08:06.137 -> >>>0
23:08:06.175 -> >>>3
23:08:06.175 -> >>>F8
23:08:06.175 -> >>>A4
23:08:08.476 -> >>>FE
23:08:08.476 -> >>>9
23:08:08.476 -> >>>61
23:08:08.476 -> >>>BE
23:08:08.476 -> >>>0
23:08:08.514 -> >>>0
23:08:08.514 -> >>>0
23:08:08.514 -> >>>0
23:08:08.514 -> >>>0
23:08:08.514 -> >>>6
23:08:08.514 -> >>>8
23:08:08.552 -> >>>0
23:08:08.552 -> >>>0
23:08:08.552 -> >>>3
23:08:08.552 -> >>>12
23:08:08.552 -> >>>DA

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.