RS232 value reading Arduino mega

Hi Everyone,

I'm trying to read values from my Kern scale with RS232 with my Arduino Mega, i ve tried the codes online but none worked, therefore Im asking for help.

The scale uses an RS232 interface, so I bought an MAX3232 converter, I have checked the wiring, the RX on pin 3, TX on pin 2 and GND on pin 5. On the TTL side, I connect the VCC and GND to arduino, reads about 4V, and RX to RX1 on pin 19, and TX on TX1 on pin 18.

I have tried the code available online, but it doesnt give me any readings in the serial monitor.
The settings on my kern scale are:
7 digit data output
Continious data output
9600 bps
no parity bit

Yes i agree the wiring is a bit cursed
Thanks so much in advance, I ve been trying for at least a week now.




#include<SoftwareSerial.h>
SoftwareSerial SUART(19, 18);  //RX = 19, TX = 18

void setup()
{
  Serial.begin(9600);
  SUART.begin(9600);
  
}

void loop()
{
  byte n = SUART.available();
  if (n != 0)
  {
    char x = SUART.read();
    Serial.print(x);
  }
}

When you are using a mega2560 board, you don't need to use a software serial port. In this case simply use Serial1.

What is that short cable with the red wires doing? Is it simply a gender changer?

There appears to be 5 wires going to the 9-pin D-connector. Apart from TxD, RxD and GND, what are the other 2. Handshaking maybe?

You may need to re-jig that short cable to be a null modem cable (or a straight through cable) depending on how you currently have it configured.

Especially if parameters are like this?


Afaik software serial does just 8N1.

Also, did you set the baud rate on scale interface?

Hi, yes the short cable with red wires is just a gender changer, and the RS232, the top 5 pins from left to right is pins 1-5, rx on pin 3,tx-2, gnd-5, the others are not connected.


rejig them into a null modem cable? meaning switch the rx and tx side?
i just did that, but still getting no data from the scale

yes this is the scale im using Download
i couldnt change the data bit so i assume it is 8 bit, the 7 digit is the data digits


And yes, i ve changed it to 9600 baud rate on the scale

Can you expand on this? Pin 4 on a standard 9-pin D-connector is - I think - DTR, which is one of the hardware handshake lines. The serial adapter module you have does not support handshaking, so you need to make sure that the scale is not expecting any hardware handshaking, otherwise it will not communicate.

EDIT: Having just skimmed the manual, the scale does not appear to use any form of hardware handshaking. I guess you have it setup for continuous serial output?

If you change your Arduino code to use Serial1 instead of SoftwareSerial, then you can set the type of parity you need to match the scale setting.

If you set your scale to continuous output, then the only 2 signals you need from the connector are GND and TXD.

Have you tried using a serial terminal program on your PC to receive the serial output just to check that data is being sent?

Parity is fine but you need hardwareserial because you need 2 stop bits. 8N2

thanks so much, i rejigged the pin 2 and 3 on the rs232 and switched from an arduino mega to uno and used a code i got from another post which you also contributed to this post, and it just worked. here is my results.


But i still wonder why does my mega dont work? i have checked with an serial moniter on my pc and its getting no results at all.

void setup()
{
  Serial.begin(9600);     // USB Serial monitor
  Serial1.begin(9600);    // Serial1: TX1/RX1 (pins depend on your board)
}

void setup()
{
  Serial.begin(9600);                       // USB Serial Monitor
  Serial1.begin(9600, SERIAL_8N2);          // Serial1 with 8N2
}

void loop()
{
  if (Serial1.available())
  {
    char x = Serial1.read();
    Serial.print(x);                        // Echo to Serial Monitor
  }
}


ok this is completely solved. just this code, and it now works perfectly. Thank you 2 so much! this has been bothering me for a month now.

void setup() {
  Serial.begin(9600);       // USB serial for monitoring
  Serial1.begin(9600);      // Serial1 for the RS232 scale
}

void loop() {
  if (Serial1.available()) {
    Serial.write(Serial1.read());
  }
}