Edit Serial Data from weighing scale (Which format is it?)

Hey, I have a couple of interrelated doubts.

  1. When my weighing scale sends me data via RS232 (through MAX232), what format is that data in? I want to know what functions I need to use to edit this data because there are a lot of trailing zeros for instance. Also, there is the presence of the letter "g" as shown in the image which I don't want.

  2. How can I achieve this before I send the data to the LCD. I want my data to only display the weight up to 4 digits (9999). Moreover, I want to use this data that I am receiving to do something (in real life, move a piston, but in this case just glowing an LED will be enough).

#include <SoftwareSerial.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(8,9,4,5,6,7);


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

void setup()
{
  Serial.begin(9600);
  mySerial.begin(4800);
  lcd.begin(16,2);
  lcd.setCursor (0,0);
  lcd.write("P1");
    lcd.setCursor (4,0);
  lcd.write("P");
    lcd.setCursor (9,0);
  lcd.write("1");
    lcd.setCursor (13,0);
  lcd.write("0");
  

}


void loop() {

    if (mySerial.available()) {
      
      delay(100);
  
      lcd.setCursor(0,1);
      lcd.print(" ");
   
      while (mySerial.available() > 0) {


        int x= mySerial.read();
        Serial.write(x);
        lcd.write(x);
      
      }
      }
     









}

![WhatsApp Image 2021-07-05 at 6.19.42 PM (1)|666x500](upload://uFvZhBHEl3a5KLwfmf0olAgsHQ7.jpeg)
![WhatsApp Image 2021-07-05 at 6.19.42 PM|375x500](upload://4VnRoeK27T440MO0zrVUYnKmJxy.jpeg)


Post the images in a new post - they did not work in the original.

The scale's datasheet or user manual would probably help with this.

Why don't you tell us what your weighing scale is?

The images didn't show because they were inside code tags.

The scale seems to be sending:
"+0000006.4 9XX"
Does the scale have a display? What did the display say when this value was sent? Does the scale have a way to change units (pounds, grams, ounces, kilos...)? What units was it set for? Does the output change if you set to different units?

Given your sketch and the suggestion that it actually works, your scale sends a string of ASCII characters. You can fairly easily convert these back into, let's say, a float value and strip off anything you don't need. Look up 'ascii table' on Google. There are also several C++ functions to deal with character arrays which you may find useful. E.g. this one atof - C++ Reference

This is the display on the weighing scale. It does not change with other units, still comes as "+00000000xxx. {Unit}"

image

This is the data I found from the datasheet. I dont how to use this but. Hopefully you can help.

It's a Contech Weighing scale. I have provided the data sheet above.

Can you please guide me on how to use it? Any operations I do have no effect on the display. What exact operations do I need to do in order to strip off all the zeros, the "+" , the units as well as the weird symbols after them as can be seen in the image. Actually, even though the data is ASCII, the arduino is not accepting any ascii conversion or ascii manipulation functions.

Thanks.

Sorry i am new to this.

I suspect the 9 at the end of the line is a lowercase g.

G

...and "black" is actually "blank", aka "space"

Try this:

  if  (mySerial.available())
  {
    float grams = mySerial.parseFloat();
    Serial.write(grams);
    lcd.write(grams);
    
    // Read until you reach the Linefeed/Newline
    while (mySerial.read() != '\n') ;
  }
Arduino: 1.8.15 (Windows Store 1.8.49.0) (Windows 10), Board: "Arduino Uno"

C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\arduino-builder -dump-prefs -logger=machine -hardware C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware -tools C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\tools-builder -tools C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware\tools\avr -built-in-libraries C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\libraries -libraries D:\Documents\Arduino\libraries -fqbn=arduino:avr:uno -vid-pid=2341_0043 -ide-version=10815 -build-path C:\Users\JASH\AppData\Local\Temp\arduino_build_75032 -warnings=none -build-cache C:\Users\JASH\AppData\Local\Temp\arduino_cache_848622 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avr-gcc.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware\tools\avr -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware\tools\avr -prefs=runtime.tools.arduinoOTA.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware\tools\avr -prefs=runtime.tools.arduinoOTA-1.3.0.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware\tools\avr -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware\tools\avr -verbose D:\Desktop\newweight\newweight.ino

C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\arduino-builder -compile -logger=machine -hardware C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware -tools C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\tools-builder -tools C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware\tools\avr -built-in-libraries C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\libraries -libraries D:\Documents\Arduino\libraries -fqbn=arduino:avr:uno -vid-pid=2341_0043 -ide-version=10815 -build-path C:\Users\JASH\AppData\Local\Temp\arduino_build_75032 -warnings=none -build-cache C:\Users\JASH\AppData\Local\Temp\arduino_cache_848622 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avr-gcc.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware\tools\avr -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware\tools\avr -prefs=runtime.tools.arduinoOTA.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware\tools\avr -prefs=runtime.tools.arduinoOTA-1.3.0.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware\tools\avr -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware\tools\avr -verbose D:\Desktop\newweight\newweight.ino

Using board 'uno' from platform in folder: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware\arduino\avr

Using core 'arduino' from platform in folder: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware\arduino\avr

Detecting libraries used...

"C:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10815 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\variants\\standard" "C:\\Users\\JASH\\AppData\\Local\\Temp\\arduino_build_75032\\sketch\\newweight.ino.cpp" -o nul

Alternatives for SoftwareSerial.h: [SoftwareSerial@1.0]

ResolveLibrary(SoftwareSerial.h)

  -> candidates: [SoftwareSerial@1.0]

"C:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10815 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\variants\\standard" "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\libraries\\SoftwareSerial\\src" "C:\\Users\\JASH\\AppData\\Local\\Temp\\arduino_build_75032\\sketch\\newweight.ino.cpp" -o nul

Alternatives for LiquidCrystal.h: [LiquidCrystal@1.0.7]

ResolveLibrary(LiquidCrystal.h)

  -> candidates: [LiquidCrystal@1.0.7]

"C:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10815 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\variants\\standard" "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\libraries\\SoftwareSerial\\src" "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\\libraries\\LiquidCrystal\\src" "C:\\Users\\JASH\\AppData\\Local\\Temp\\arduino_build_75032\\sketch\\newweight.ino.cpp" -o nul

Using cached library dependencies for file: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\libraries\SoftwareSerial\src\SoftwareSerial.cpp

Using cached library dependencies for file: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\libraries\LiquidCrystal\src\LiquidCrystal.cpp

Generating function prototypes...

"C:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10815 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\variants\\standard" "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\libraries\\SoftwareSerial\\src" "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\\libraries\\LiquidCrystal\\src" "C:\\Users\\JASH\\AppData\\Local\\Temp\\arduino_build_75032\\sketch\\newweight.ino.cpp" -o "C:\\Users\\JASH\\AppData\\Local\\Temp\\arduino_build_75032\\preproc\\ctags_target_for_gcc_minus_e.cpp"

"C:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\\tools-builder\\ctags\\5.8-arduino11/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "C:\\Users\\JASH\\AppData\\Local\\Temp\\arduino_build_75032\\preproc\\ctags_target_for_gcc_minus_e.cpp"

Compiling sketch...

"C:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10815 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\variants\\standard" "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\libraries\\SoftwareSerial\\src" "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\\libraries\\LiquidCrystal\\src" "C:\\Users\\JASH\\AppData\\Local\\Temp\\arduino_build_75032\\sketch\\newweight.ino.cpp" -o "C:\\Users\\JASH\\AppData\\Local\\Temp\\arduino_build_75032\\sketch\\newweight.ino.cpp.o"

D:\Desktop\newweight\newweight.ino: In function 'void loop()':

newweight:31:23: error: call of overloaded 'write(float&)' is ambiguous

     Serial.write(grams);

                       ^

In file included from C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/Arduino.h:233:0,

                 from C:\Users\JASH\AppData\Local\Temp\arduino_build_75032\sketch\newweight.ino.cpp:1:

C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/HardwareSerial.h:129:20: note: candidate: virtual size_t HardwareSerial::write(uint8_t)

     virtual size_t write(uint8_t);

                    ^~~~~

C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/HardwareSerial.h:130:19: note: candidate: size_t HardwareSerial::write(long unsigned int)

     inline size_t write(unsigned long n) { return write((uint8_t)n); }

                   ^~~~~

C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/HardwareSerial.h:131:19: note: candidate: size_t HardwareSerial::write(long int)

     inline size_t write(long n) { return write((uint8_t)n); }

                   ^~~~~

C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/HardwareSerial.h:132:19: note: candidate: size_t HardwareSerial::write(unsigned int)

     inline size_t write(unsigned int n) { return write((uint8_t)n); }

                   ^~~~~

C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/HardwareSerial.h:133:19: note: candidate: size_t HardwareSerial::write(int)

     inline size_t write(int n) { return write((uint8_t)n); }

                   ^~~~~

Using library SoftwareSerial at version 1.0 in folder: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\libraries\SoftwareSerial 

Using library LiquidCrystal at version 1.0.7 in folder: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\libraries\LiquidCrystal 

exit status 1

call of overloaded 'write(float&)' is ambiguous


I am getting the above error

Try using print instead of write.

Sorry.

    Serial.print(grams);
    lcd.print(grams);

You should probably simplify things as much as possible during this debug stage. I would temporarily remove the LCD from the project until you get the serial comms with the scale sorted out. Just print the data received to the Serial Monitor. Maybe even print the received characters in HEX format to confirm they are all as expected and the protocol matches the documentation.

Also:

The 1990s just called and they want their baud rate back. There's no reason you shouldn't be using at least 115200 with the Serial Monitor (be sure to set that rate in the monitor also).

Yeah that's all right, I can remove the LCD for now. And yeah, I'll use 115200 :joy:. Thanks

2E202050DA2D30303030303030312E202050DA2D30303030303030312E202050DA2D30303030303030312E202050DA2B30303030303030302E202050DA2D30303030303030302E202050DA2B30303030303030302E202050DA2D30303030303030302E202050DA2B30303030303030302E202050DA2B30303030303030302E202050DA2B30303030303030302E

This is the output when I receive the data in HEX.

Try printing it as ASCII - I can see spaces (0x20) and decimal digits (0x30 - 0x39) and a full-stop (period) 0x2E.
Even a capital P