Mega, Echo Comms?

I have a project that I completed about 2 years ago and I’m looking to do some modifications to the Serial Communications.

I have an Amateur radio that communicates with an amplifier that I built. The Arduino Mega will query the radio for the current operating (Frequency) Band and if the operator changes bands, the Mega will change the amplifier to match the operating band (enables an Output on the Mega to switch a relay). The Mega also sends a Serial command back to the radio to change the output power.
This works fine.

However, I want to modify the Arduino Mega so that my Radio can talk to a PC for remote control purposes, operate the Radio over the Internet. For this case, the Arduino would only have to monitor those communications and in the case of a Band Change, occasionally interject the Power Change to the Radio if necessary)

I think that I can accomplish this if I can allow the PC to talk to the Radio via the Serial Port, but have the Mega in between the PC and radio:

PC-Serial Port <–> Port1: Arduino Mega () Port2 <–> Radio-Serial Port

where the Mega would basically echo All of the comms back and forth between the Port1 and Port2. During this, the Mega would monitor the comms FROM THE RADIO (I don’t think it would have to monitor anything from the PC) and in some cases, BREAK IN (stop the echo) and send a quick command to the Radio, then re-enable the echo of the communications.

  1. Is this concept possible?
  2. Is there a quick and easy way to echo the commands between the two Arduino Comm Ports back and forth that wouldn’t add too much delay?
  3. Is there a way to do the echo commands using an interrupt? I would still need to do some other processing in the meantime.
  4. Am I getting myself in too deep? :wink:

If I can get this to work, I would have to add the hardware to the Mega to add a 3rd Comm Port to emulate the code to make the amplifier work with the PC, but I don’t see where that should be a big problem.


Sir Michael

FYI that is normally called a "pass through" not an echo, which copies data back to its source. The logic is ridiculously simple:

if serial1.available
if serial2.available

Is there a way to setup the "Pass Through" using an interrupt?

Sir Michael

Is there a way to setup the "Pass Through" using an interrupt?

Sir Michael

...and why would you want to do that?

I would like to have it on an interrupt so that I don't have to keep checking to see if there is a message waiting to be passed. This would reduce the delay time between the PC and the radio.

But I guess I would need to know when the source message is complete.

Sir Michael

Any code that you write will run hundreds or thousands of times faster than serial can be transmitted and received. Using an interrupt here will not speed it up. Hardware serial on Arduino is already interrupt driven, so you would have a huge coding headache to re-write all the core functions… not a novice assignment.

I hope you wrote your code so that it is non-blocking? Then you can just insert the code I showed you into the loop() with all the other code you wrote, and it will run just fine, concurrently.

But, until we see your actual code, in code tags please, the discussion will remain purely academic (and possibly inconclusive or not very helpful).

No, it won't run that fast. There are quite a number of other things that happen in the loop. Checking Temperature, reading a number of inputs from the amplifier, reading the buttons, etc.

I did a fair amount of testing when I wrote the code, and I have a comment in the Display loop that indicates that the Display takes about 200ms to run. I'm using an Adafruit LCD Shield kit - 2 line, 16 char + 5-buttons, 2 wire I2C.

I was hoping that when ever a message was completed that it could trigger an interrupt, so that I could service the serial I/F, and get back to the normal routine.

Sir Michael