RS232 to TTL converter for weighing, but Serial Write Can't show perfect data

I am want to display my weighing scale, so to make it I use max 3232 and communication running normal.
But i have some problem when I serial monitor, data appear not perfect, so I try to hyperterminal and the data appears perfect.

My arduino code is

#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11    ); // RX, TX   <------<<<< use the pins you want

void setup()
{
  Serial.begin(9600);
  mySerial.begin(9600);

}


void loop()
{
    while (mySerial.available())
    {

      Serial.print((char)mySerial.read()); //Serial.write(mySerial.read());   // You can also use:     Serial.print((char)mySerial.read());
      //delayMicroseconds(200);
    }

}

and my wiring

TX scale Converter max3232
TX DB9 Pin 3
GND DB9 Pin 5 (GND)

Converter max3232 Arduino UNO
Pin TTL RX Pin D10
VCC 5V
GND GND

this my weighing scale

this serial monitor

my config hyperterminal

data at hyperterminal



data ASCII from scale

Converter max3232 Arduino UNO Pin TTL RX Pin D10

You forgot the ground.

++Karma; // For correctly posting code and lots of other information on your first post.

PerryBebbington: You forgot the ground.

++Karma; // For posting code and lots of other information on your first post.

oh sorry i forgot to write hehe I already connect GND and VCC

According to the image of the data format, there are only 7 databits and a parity; that's also how you configured your terminal program. You can't configure Serial monitor for that.

You should also setup your SoftwareSerial for that format but data formats it's not supported by SoftwareSerial. Best option for that is to use a board with two or more serial ports.

If you don't care about the parity bit, then set it to 0 before sending to the serial monitor. Software serial expects to see 8 bits, no parity, 1 stop bit, so the parity bit will be input as the most significant bit of an 8-bit value.

sterretje: According to the image of the data format, there are only 7 databits and a parity; that's also how you configured your terminal program. You can't configure Serial monitor for that.

You should also setup your SoftwareSerial for that format but data formats it's not supported by SoftwareSerial. Best option for that is to use a board with two or more serial ports.

OK, what board with two serial port? actually i want show the scale data to java program (netbeans)

david_2018: If you don't care about the parity bit, then set it to 0 before sending to the serial monitor. Software serial expects to see 8 bits, no parity, 1 stop bit, so the parity bit will be input as the most significant bit of an 8-bit value.

how to set it? do you mean SERIAL_8N1 ?

I want to show the data to java like this

|500x301

devjavus: how to set it? do you mean SERIAL_8N1 ?

Serial.write(mySerial.read() & 0x7F);

@OP what board with two serial port?

Arduino mega for example.

TX scale Converter max3232 TX DB9 Pin 3 GND DB9 Pin 5 (GND)

Usually, the receive pin in the db9 is PIN number 2, is the above wiring correct? Also the serial configuration is different.

Regards

david_2018: Serial.write(mySerial.read() & 0x7F);

david_2018: Serial.write(mySerial.read() & 0x7F);

Thankyou so much brother... now i get perfect data

|500x301

can you explain about "0x7F"?

abdelhmimas: @OP what board with two serial port?

Arduino mega for example.

abdelhmimas: @OP what board with two serial port?

Arduino mega for example.

ok thank for your suggest.

abdelhmimas: TX scale Converter max3232 TX DB9 Pin 3 GND DB9 Pin 5 (GND)

Usually, the receive pin in the db9 is PIN number 2, is the above wiring correct? Also the serial configuration is different.

Regards

yeah pin numer 2 is RX max3232

Serial.write(mySerial.read() & 0x7F);

can you explain about "0x7F"?

mySerial.read() returns the ASCII character in the format of a parity bit in the most significant bit followed by seven data bits. The & symbol is the bitwise logical AND operator. 0x7F is hexidecimal for the binary number 01111111, which when ANDed with the ASCII character will set the most significant bit to 0 and leave the other bits unchanged.

The scale is sending ASCII characters as seven data bits, a parity bit, and a stop bit. Software serial expects eight data bits followed by a stop bit, which causes the parity bit to appear as part of the data, which is then removed by setting the parity bit to zero.

david_2018: Serial.write(mySerial.read() & 0x7F);

mySerial.read() returns the ASCII character in the format of a parity bit in the most significant bit followed by seven data bits. The & symbol is the bitwise logical AND operator. 0x7F is hexidecimal for the binary number 01111111, which when ANDed with the ASCII character will set the most significant bit to 0 and leave the other bits unchanged.

The scale is sending ASCII characters as seven data bits, a parity bit, and a stop bit. Software serial expects eight data bits followed by a stop bit, which causes the parity bit to appear as part of the data, which is then removed by setting the parity bit to zero.

really brilliant.

david_2018: Serial.write(mySerial.read() & 0x7F);

mySerial.read() returns the ASCII character in the format of a parity bit in the most significant bit followed by seven data bits. The & symbol is the bitwise logical AND operator. 0x7F is hexidecimal for the binary number 01111111, which when ANDed with the ASCII character will set the most significant bit to 0 and leave the other bits unchanged.

The scale is sending ASCII characters as seven data bits, a parity bit, and a stop bit. Software serial expects eight data bits followed by a stop bit, which causes the parity bit to appear as part of the data, which is then removed by setting the parity bit to zero.

ahh, I see , thankyou for your help.. Is it possible I send data to serial without "ST," just take +0000.150 Kg to serial monitor?

Your current code (opening post) simply echoes to the PC what is received on mySerial. You can e.g. start the echoing after you have detected the the comma after ST and stop echoing after you have detected the linefeed.

Alternatively, as demonstrated in below linked thread, you can collect the data first (basically read till the linefeed) and next send the message starting at the character after the comma.

You might get some ideas from Robin's updated Serial Input Basics thread.

Hey @devjavus I faced similar issues and solved here - https://forum.arduino.cc/index.php?topic=590774.0

devjavus: I want to show the data to java like this

|500x301

Devjavus, I am interested in your Java code, can you post? Thank you

sterretje: Your current code (opening post) simply echoes to the PC what is received on mySerial. You can e.g. start the echoing after you have detected the the comma after ST and stop echoing after you have detected the linefeed.

Alternatively, as demonstrated in below linked thread, you can collect the data first (basically read till the linefeed) and next send the message starting at the character after the comma.

You might get some ideas from Robin's updated Serial Input Basics thread.

ok thankyou so much

AnshumanFauzdar: Hey @devjavus I faced similar issues and solved here - https://forum.arduino.cc/index.php?topic=590774.0

yeah I read your thread first for wiring and make sure my module its ok, but i have any problem about 7bit data hehehe thankyou so much

abdelhmimas: Devjavus, I am interested in your Java code, can you post? Thank you

I got from internet too, basic java to arduino

you can get from this