Handling data from an RS232 scale

I've fought with a scale in our lab to finally get something readable output over RS232 to Arduino. The code that finally worked is:

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

I'm not experienced with working with char variables, since most of my programming experience is using float, int, etc for simple math. The code above will output in the serial monitor data in the format "10.05kg". I need to convert this to a float value and delete the units (kg) so that I can use it to control other lines of code using if/then/else type logic. The "kg" is always two characters at the end of the char variable.

I have found some solutions that seem very complex, but it feels like there is probably a simple answer that I'm missing, hence the question. Thanks in advance!

The Serial.parseFloat() (or in your case softSerial.parseFloat()) function should have no problem returning the numeric value.

The search phrase "arduino serial.parsefloat examples" should find example applications.

For an in depth introduction to serial input, this tutorial and this one should be helpful.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.