RS232 working from PC but not from Arduino

Hello.

I'm trying to read values from an industrial scale via sr232 and I've managed to get it working when connected to a pc, however when I connect it to an arduino, the arduino doesn't seem to be receiving anything. The scale is able to send the measured value when being prompted through commands or automatically after being toggled. Even when toggled the rx led of the sr232 to ttl module won't blink.

I've been going at this for a while and don't know if the problem lies within the code I've written or if its got something to do with the electronics.

For context,

  • The scale is analogic but uses a trasducer (specifically an aed9101d) to turn the signal digital, uses external 24V power.
  • Using an arduino uno.
  • Using a sr232 to ttl converter with a max3232 powered with the arduino.
  • Using 9600 bauds, 8 bits, even parity and 1 stop bit.
  • Using termite/serial port monitor from pc for debugging.
  • Small programs using serial communication between pc and arduino show no apparent issues.

The following is a small program I've tested with the pc which mimics the scale.

  • msv?; is the command sent to the scale.
  • Pin 4 is connected to a light.
  • Pin 7 is connected to a button.
void setup()  {
  pinMode(4,OUTPUT);
  pinMode(7,INPUT);

  Serial.begin(9600,SERIAL_8E1);
  Serial.setTimeout(2);
}
void loop() {

  if(digitalRead(7)){
    Serial.write("msv?;\n");
    delay(1000);
  }

  if(Serial.available()>0){


    int myInt = Serial.parseInt(SKIP_ALL,'\n');
    Serial.println(myInt);
    if(myInt>0){

      digitalWrite(4,HIGH);
      delay(1000);
      digitalWrite(4,LOW);
    }

  }
}

A picture of the general setup for clarity

Thanks,
Best regards.

1 Like

I'd like you to edit your post:

  1. Remove the picture of the code and
  2. Copy it instead, click on <code> and paste.
1 Like

Is the serial port of your scales set up to use any hardware handshaking? I think you can check this if you set your serial port flow control parameter in your PC terminal program to none (or similar).

Can you change your scale parameters to use no parity? If so, I would suggest using a software serial port to communicate with the scale rather than try and use the hardware serial port for both comms to the scale and serial printing.

1 Like

Are you using a null-modem (crossover cable)?

1 Like

I wasn't familiar with flow control so I've been using none.

As for the parity I've changed the code to the one below and it still works on pc with no visible changes when plugged to the scale.

#include <SoftwareSerial.h>
SoftwareSerial softSerial(10, 11);

void setup()  {
  
  pinMode(4,OUTPUT);
  pinMode(7,INPUT);

  Serial.begin(9600,SERIAL_8E1);
  Serial.setTimeout(2);

  softSerial.begin(9600);

}
void loop() {

  if(digitalRead(7)){
    softSerial.write("msv?;\n");
    delay(1000);
  }

  if(softSerial.available()>0){

    int myInt = softSerial.parseInt(SKIP_ALL,'\n');
    Serial.println(myInt);
    if(myInt>0){

      digitalWrite(4,HIGH);
      delay(1000);
      digitalWrite(4,LOW);
    }

  }
}

As far as I know its just a gender changer, both the ouput from the trasducer and the sr232 from the max3232 are female

You need a null-modem (crossover cable)
A null-modem cable swaps the RX and TX pins as well as the handshaking signals.

1 Like

On retrospective It does feel like talking to a wall, so it very well may be the handshaking signals you speak of. I'll rummage through the house and see if i find one or I'll get one tomorrow. I'll get back when I test it. Thank you.

Since it works, what settings is used?

Once you have the correct cable....

In the Arduino sketch, it may not be a great idea to 'force' a delay after the msv? is sent to the scale. It might be better to go straight to trying to read the serial output from the scale immediately without a delay.

When you say you have tested the Arduino code with the PC, do you simply mean from the serial monitor in the Arduino IDE? If so, you may be making an assumption about the timing of the response from the scale which is not accurately represented when you are simulating the communication with the Arduino from the serial monitor.

Another way to test this would be to write a separate piece of code (such as in Processing) that emulates the scale in terms of waiting for the msv? command and then responding with a value and try to get the Arduino to communicate with the Processing sketch. This may be a better simulation of how the scale really responds.

You can do this with a USB to RS232 cable, so that the Processing sketch on the computer really communicates with the Arduino in the same way that the scale would.

The standard for the scale is 9600 bauds, 8 bits, even parity and 1 stop bit. I'm not sure if there are any more parameters involved.

Your scale is connected to the software serial port? If so, using Serial.begin(9600,SERIAL_8E1); has no influence on that.

Note
Serial monitor can only do 8N1.

I've also tried to communicate with the scale with no delays to no avail. I added the delay afterwards with the addition of the physical button to not send several instances of the command when I press it.

I've handled communication with the computer through a sr232 to usb adapter with no connection to arduino IDE, but I've done the simulation of weights by manually inputting a number and hitting enter in the termite terminal as I'm only trying to check if comms work.

Also, I think I've found a null modem but It's also female to female so I'll see if I can splice it.

I did change the scale to 8N1 when I swapped to software serial

It was indeed the null modem,

forever grateful good sir.

1 Like

Have a nice day!