Reading serial port from ham radio doesnt work

Hey, im trying to read the frequency of my TS-590sg, i’ve been trying things for like 2 weeks but im unable to communicate through the COM port.

From the examples that i tried it seems that you need to send the command IF; and the radio will response you with the frecuency, so now if i monitor the Seríal am only getting IF; repeating again and again but nothing about what i need.

Actually im using MEGA2560 and TTL-RS232 converter, i’ve tried from Serial and Serial1, still the same result, RX led is not even blinking…

Heres my code:

int  inByte= -1;             // incoming byte from serial RX

char buffer[100];             // string for incoming serial data -- a buffer

int  bufferPos = 0;          // string index counter


void setup() {
  Serial.begin(57600); //  setup serial speed

}

void loop() {
 Serial.flush();  // 

 Serial.print("IF;");
 delay(200);

 if (Serial.available() > 0) {
  inByte = Serial.read();
  read_if();
  
  }

}

void read_if () {

  if (inByte == 'I') {

    while (bufferPos != 38) {

      if (Serial.available() > 0) {

        buffer[bufferPos] = inByte;

        bufferPos++;

        inByte = Serial.read();

        if (inByte == ';') break;

      }

    }

String str_if = buffer;

String qrg ;



qrg = str_if.substring(5,10);


if ((qrg[0] == '0')&&(qrg[1] == '1'))

{

  Serial.println("160");
}


if (qrg[1] == '3')

{
  Serial.println("80");
}
for (int c = 0; c < bufferPos; c++) {

      buffer[c] = 0;

    }
    bufferPos = 0;

  }
}

Hope you guys could help me, thank you in advance

siox:
From the examples that i tried it seems that you need to send the command IF; and the radio will response you with the frecuency, so now if i monitor the Seríal am only getting IF; repeating again and again but nothing about what i need.

Where are you getting this information? Do you have documentation you can link for us?

siox:

 Serial.flush();  //

This doesn't do what you think it does. That being said, it's probably not causing the issue, just fyi.

Also:
1.) Don't use "S"trings
2.) Try using the Arduino as a "pass-through" device. As in it doesn't do any extra processing other than relaying raw serial characters between your serial monitor and the radio. This eliminates any possible errors in the Arduino software and allows you to do some testing.
3.) Can you post your schematic?

Try the second example in Serial Input Basics but using Serial1 for the input from your ham radio.

...R

Hey, thank you for the quick reply.

Im only using a serial cable directly to TTL-RS232 converter, and some dupont cables directly to MEGA:

RS232 TX → arduino Serial RX
RS232 RX → arduino Serial TX

3.3v to VCC

The code that i’ve used are here:

and this is from the same author:

I have another project and they’re using the same method apparently, so im lost right now…

Robin2:
Try the second example in Serial Input Basics but using Serial1 for the input from your ham radio.

...R

Thanks for the reply, i have no idea what do you mean. Should i use Serial1 for the input from the radio and Serial for the output?

Not sure if you did find TS-590STS-590SG PC CONTROL COMMAND Reference Guide

Using Serial on an Uno or Mega for communication with other devices is in general confusing because that port is basically reserved for communication with the PC. So below uses Serial1 of the Mega.

I suggest that you start simple; the below code sends IF; over Serial1 and next reads data from Serial1 and prints it on Serial; it will only send IF; again when a semi-colon is read from Serial1.

char inByte;        // incoming byte from serial RX
char buffer[100];   // string for incoming serial data -- a buffer
int  bufferPos = 0; // string index counter


void setup()
{
  Serial.begin(57600);  //  connection to PC
  Serial1.begin(57600); //  connection to radio; adjust to needs
}

void loop()
{
  // variable to know if command was send
  static bool isSend = false;

  // if  command not send
  if (isSend == false)
  {
    // send it
    Serial1.print("IF;");
    isSend = true;
  }

  // if a byte available
  if (Serial1.available() > 0)
  {
    // read and print
    inByte = Serial1.read();
    Serial.print(inByte);
    // if it's terminating semicolon
    if (inByte == ';')
    {
      // indicate that no command was send / ready to send another command
      isSend = false;
      // you can add a bit of a delay here for testing
      delay(1000);
    }
  }
}

Once you get that working (read: get the expected result), you can make life more complicated :wink:

Oh, and before you get too deep into the use of String (capital S) objects, stay away from them; they can cause unexpected problems at run time when your code becomes more complicated.

sterretje:
Not sure if you did find TS-590STS-590SG PC CONTROL COMMAND Reference Guide

Using Serial on an Uno or Mega for communication with other devices is in general confusing because that port is basically reserved for communication with the PC. So below uses Serial1 of the Mega.

I suggest that you start simple; the below code sends IF; over Serial1 and next reads data from Serial1 and prints it on Serial; it will only send IF; again when a semi-colon is read from Serial1.

char inByte;        // incoming byte from serial RX

char buffer[100];  // string for incoming serial data -- a buffer
int  bufferPos = 0; // string index counter

void setup()
{
  Serial.begin(57600);  //  connection to PC
  Serial1.begin(57600); //  connection to radio; adjust to needs
}

void loop()
{
  // variable to know if command was send
  static bool isSend = false;

// if  command not send
  if (isSend == false)
  {
    // send it
    Serial1.print("IF;");
    isSend = true;
  }

// if a byte available
  if (Serial1.available() > 0)
  {
    // read and print
    inByte = Serial1.read();
    Serial.print(inByte);
    // if it's terminating semicolon
    if (inByte == ';')
    {
      // indicate that no command was send / ready to send another command
      isSend = false;
      // you can add a bit of a delay here for testing
      delay(1000);
    }
  }
}



Once you get that working (read: get the expected result), you can make life more complicated ;)

Oh, and before you get too deep into the use of String (capital S) objects, stay away from them; they can cause unexpected problems at run time when your code becomes more complicated.

Thank you so much, thats the point, i only want to see anything from the radio, i saw the manual already, i even tried so many times using serial1, but the only what i get is IF;

Im trying your code and i only get IF; in the serial monitor. Not only from mine, i've even remote access to another setup like mine dropping the same result :frowning:

Instead of worrying about Strings, which is probably not an issue in this case, You might want to simply try skipping the arduino itself and only use its UART to communicate with the radio using the serial monitor. Is the radio RS232 or TTL?

zoomkat:
Instead of worrying about Strings, which is probably not an issue in this case, You might want to simply try skipping the arduino itself and only use its UART to communicate with the radio using the serial monitor. Is the radio RS232 or TTL?

It is RS232, how can i communicate, what software should i use? i have a serial port in the PC, i would connect the radio directly to the pc and see what happens

Is 57600 the correct line speed?

Make sure your cable between the radio and rs232 converter is not swapping the rx and tx lines.

TheMemberFormerlyKnownAsAWOL:
Is 57600 the correct line speed?

i can change it in the radio

siox:
Thanks for the reply, i have no idea what do you mean. Should i use Serial1 for the input from the radio and Serial for the output?

Yes. Using Serial for the output will allow you to see the stuff on the Serial Monitor

...R

david_2018:
Make sure your cable between the radio and rs232 converter is not swapping the rx and tx lines.

thanks, ill check it, but my friend is using the converter directly connected in the radio, im using cable tho

siox:
It is RS232, how can i communicate, what software should i use? i have a serial port in the PC, i would connect the radio directly to the pc and see what happens

That would defiantly something to try if your computer has an installed serial port. You would probably need a serial terminal program to send the test commands. Just curious, does the serial monitor see an active com port when the arduino is not attached to the computer?

Finally i've got response from the radio using a RT232 terminal, now i need it working on arduino.

I have the TTL-RS232 connected again to the Serial1, but with the code from above i only get IF; in the serial monitor.

Should i have to change something in the configuration of the arduino itself? i dont get why is not working :S

siox:
Finally i've got response from the radio using a RT232 terminal, now i need it working on arduino.

I have the TTL-RS232 connected again to the Serial1, but with the code from above i only get IF; in the serial monitor.

Should i have to change something in the configuration of the arduino itself? i dont get why is not working :S

So you got a frequency when using the RS232 adapter directly?

If you keep getting IF; in the serial terminal that means you might have mixed up Serial1 and Serial.

You want Serial1 to communicate with the radio. Serial will communicate with the PC via the USB cable and to your serial monitor.

Use Serial1 to send the IF; to the radio.
Once the radio responds back on Serial1 (the radio frequency), send that data back to the PC using Serial

If you want to experiment some, open the arduino IDE and open a new file and load that dummy code onto the arduino. This should basically take the arduino out of the picture. Then connect the arduino side of the TTL/rs232 adapter to the arduino with tx to tx, rx to rx, and ground to ground. Keep the adapter connected to the radio as previously connected. Open the serial monitor and try sending your test code (make sure the "no line ending" in the serial monitor is selected and the correct baud rate is set). See if you get a response from the radio.

bears0:
So you got a frequency when using the RS232 adapter directly?

If you keep getting IF; in the serial terminal that means you might have mixed up Serial1 and Serial.

You want Serial1 to communicate with the radio. Serial will communicate with the PC via the USB cable and to your serial monitor.

Use Serial1 to send the IF; to the radio.
Once the radio responds back on Serial1 (the radio frequency), send that data back to the PC using Serial

Hey, thanks for commenting. I've got the frequency connecting the radio directly to the PC and using a RS232 terminal software without RS232 adapater, i only use it when i have to connect the radio with arduino.

So, the point what i dont understand is why the Serial responds me with IF; when im sending it through Serial1?

zoomkat:
If you want to experiment some, open the arduino IDE and open a new file and load that dummy code onto the arduino. This should basically take the arduino out of the picture. Then connect the arduino side of the TTL/rs232 adapter to the arduino with tx to tx, rx to rx, and ground to ground. Keep the adapter connected to the radio as previously connected. Open the serial monitor and try sending your test code (make sure the "no line ending" in the serial monitor is selected and the correct baud rate is set). See if you get a response from the radio.

Hey, thanks for commenting. What do you mean about dummy code? is that posted above? In any case, ill swap the cables and lets see what happen, :slight_smile:

siox:
RS232 TX -> arduino Serial RX
RS232 RX -> arduino Serial TX
3.3v to VCC

You don't have a ground connected from Mega to adapter ?