Serial Communication

I need to read weight values form a digital balance (A&D FX-120i). If I connect the scale directly to my computer via a USB to RS232 converter the computer can send commands to the scale and the scale returns the weight.

If I connect my Uno to the computer via the USB to RS232 converter I can send command from the Uno to the PC and receive data from the PC, monitored via serial monitor.

Once I connect the Uno to the scale, using software serial and a ttl to RS232 shield I can receive data send from the scale to the Uno but once I send commands to the scale from to Uno no feedback is received. I think it might be a terminator issue? Please find my code below and advise.

The manual of the scale can be found here: https://scalenet.com/pdf/FX-i_Precision_Scales.pdf

#include <SoftwareSerial.h>

SoftwareSerial mySerial(6,5); // RX, TX
int i = 0;
char input; 

void setup() {

  Serial.begin(19200);
  mySerial.begin(19200);

  mySerial.flush();

}

void loop() {

    input = Serial.read();
  
    if(Serial.available()){
    Serial.println("IF I SEND A COMMAND ON SERIAL MONITOR");
    mySerial.write("Q\r\n");
    delay(50);
    String scaleOutput = mySerial.readStringUntil("\r");
    Serial.print("SCALE OUTPUT: ");

    }

  if (mySerial.available()) {
    Serial.println("IF I PRESS PRINT ON MY SCALE");
      bool negative = false;
      bool stable = false;
      String scaleOutput = mySerial.readStringUntil("\r");
      
        Serial.print("SCALE OUTPUT: ");
        Serial.print(scaleOutput);
        Serial.print("Comma: ");
        Serial.println(scaleOutput.indexOf("."));
      
      if ((scaleOutput.indexOf(".") == 8) || (scaleOutput.indexOf('.') == 9)) {
        if (scaleOutput.indexOf('ST') != -1) {
         //Serial.println("stable");
         stable = true;
       }
        
        String valueString = scaleOutput.substring(4, 12);

       Serial.print("Value String: ");
        Serial.println(valueString);

       
      float value = valueString.toFloat();
       if (negative) value = value * -1;
       Serial.print("Float: ");
       Serial.println(value, 3);

        Serial.print("Unit: ");
       Serial.println(scaleOutput.substring(12, 15));
        
    } 

  }

}

You are sending binary data to the scale, when it expects ascii characters:

mySerial.write("Q\r\n");

Try print instead of write:

mySerial.print("Q\r\n");

EDIT: It seems, that write can also write out string values, however it'd be worth a try.

smithchristof:
If I connect my Uno to the computer via the USB to RS232 converter [...]

Do you connect the Uno to the same cable as the Scale?
Directly or via the 232 shield?

If you connect the Uno directly to the same cable as the scale it looks to me like the scale is TTL as well...

And please provide:

  • What and how (software etc) do you send to the scale from the computer?
  • What do you expect back?
  • Link to the shield

[edit]
Ahh, yeah, and write expects a byte value.

Isn't this the same question as in your earlier Thread

Please click Report to Moderator and ask to have them merged so all the info is in one place.

...R

Too much hassle to merge across forum sections; other thread locked

LightuC:
EDIT: It seems, that write can also write out string values, however it'd be worth a try.

This unfortunately gives the same outcome

septillion:
Do you connect the Uno to the same cable as the Scale?
Directly or via the 232 shield?

If you connect the Uno directly to the same cable as the scale it looks to me like the scale is TTL as well...

And please provide:

  • What and how (software etc) do you send to the scale from the computer?
  • What do you expect back?
  • Link to the shield

[edit]
Ahh, yeah, and write expects a byte value.

The Uno is connected to the computer through the shield with the same cable

I make use of RsCom, the program that is provided with the scale. I downloaded it from the internet: WinCT & WinCT-Weight | Software | Products | A&D

I expect the following string: ST,+00001.27 GN

My shield is connected as follow:
VCC - 3.3V pin
RXD - pin 6
TXD - pin 5
GND - GND pin

One other thing that is weird, as soon as I connect my external 12V 1000mA and no longer use the usb cable as the only power source I cant even receive serial communication as I currently do.

Robin2:
Isn't this the same question as in your earlier Thread

Please click Report to Moderator and ask to have them merged so all the info is in one place.

...R

It is still the same question. Thanks. I did raise it with the Moderator.

smithchristof:
The Uno is connected to the computer through the shield with the same cable

Can you draw a diagramm of your connections? A simple paint drawing will do. Please also add your computer and the program it runs to the drawing. All connections should be visible in the drawing (also power and usb).

Please find a picture of my connection attached