some guideance for 2 serail port project

Hello ,
I want to connect to a serial device , read data and add some data , send it to another serial device.

can I use 2 arduino pro mini for this?

the reading code is almost working on the pro-mini
the sendgin code is almost working on another pro-mini
the code is just to see I know how to read and how to send
I just want to know how can I "connect" them :slight_smile:

any idea?

  • it doesn't have to be Pro-mini ......

Thanks ,

Use an Arduino with 2 (or more) hardware serial ports, then there is no need to connect them.

would arduino Mega do the job?

david1234:
would arduino Mega do the job?

Yes.

OK ,

I thought of something :

can't I do this in the pro mini -

in the loop I will listen to "device1" when I get from him end char , I will send the data to device2?

the data is going to change once every 5 min ~

will it work?

or I have to have 2 hardware serial ports?

Thanks,

in the loop I will listen to "device1"

Using the hardware serial port?

I will send the data to device2?

How? You can't use the same hardware serial port to talk to the second device.

If "device1" only sends and "device2" only receives and they both use the same baud rate and character format you can use the single hardware serial port for both.

device1 is 115200 sending only
device2 is 4800 reading only
same format

still a problem ?

david1234:
device1 is 115200 sending only
device2 is 4800 reading only
same format

still a problem ?

Yes. You can't set the TX and RX sides of the hardware serial port to separate baud rates.
You could use SoftwareSerial to send the data to "device2" at 4800 baud and use the hardware serial port to receive from "device1" at 115200.

david1234:
in the loop I will listen to "device1" when I get from him end char , I will send the data to device2?

the data is going to change once every 5 min ~

Do you mean that you get 1 message from "device1" every five minutes? Or at least there are large gaps between messages? If so, you could use this trick to switch baud rates between reading and writing:

   //  Message received from 'device1' and changes made in "char buffer[];"
  Serial.end();
  Serial.begin(4800); // 'device2' baud rate
  Serial.write(buffer);
  Serial.end();  // Includes a .flush() so it waits for the send buffer to empty
  Serial.begin(115200); // 'device1' baud rate
  // Go back to looking for the next message from 'device1'.
}

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data.

The technique in the 3rd example will be the most reliable.

You can send data in a compatible format with code like this

Serial.print('<'); // start marker
Serial.print(value1);
Serial.print(','); // comma separator
Serial.print(value2);
Serial.println('>'); // end marker

...R

Yes this is what I need:

send the data to "device2" at 4800 baud and use the hardware serial port to receive from "device1" at 115200.

Device1 is sending message every 5 min , sometime even more - could be 1 hour even...
and only after I get the message I need to add some data - and send it to device 2
they never will work together , only Half-duplex on each side .
I will start working on it - and ask here when I will have more questions

I just wanted to know I can do it 1 arduino , so I will not waste time...

Thanks ,

david1234:
I just wanted to know I can do it 1 arduino , so I will not waste time...

Yes, you can do it with one Arduino. Just use either of the two methods I described.