LCD - 1602A - Cut comma numbers of

Hey Guys,
sorry for my bad English I´m from Germany and have a lot to learn back in the TechWorld :slight_smile:

Ive made a “copy + paste” Sketch to send Sensor Data to HomeAssistant and also to LCD 1602A.

The Problem ist the Sensor Sends like: " 8.343.646.757.343.758" but I need “8.34” as Result.

But I´m too Stupid try now about four Hours to made it.

JsonObject& prepareResponse(JsonBuffer& jsonBuffer) {
JsonObject& root = jsonBuffer.createObject();
---->    avgValue=0;
  for(int i=2;i<8;i++)                     
    avgValue+=buf[i];
  float phValue=(float)avgValue*5.0/1024/6;
    phValue=3.5*phValue;[/b]              <---------------------
    root["temperature0"] = dht0.readTemperature();
    root["humidity0"] = dht0.readHumidity();
    root["temperature1"] = dht1.readTemperature();
    root["humidity1"] = dht1.readHumidity();
    root["temperature2"] = dht2.readTemperature();
    root["humidity2"] = dht2.readHumidity();
---->   root["PH"] = phValue; <-------------
     {
      {
    lcd.clear();  //Clears the LCD screen and positions the cursor in the upper-left corner
    lcd.setCursor(1,0);                   // set the cursor to column 15, line 1
    for (int positionCounter2 = 0; positionCounter2 < 16; positionCounter2++)
    {
      // lcd.scrollDisplayLeft();             //Scrolls the contents of the display one space to the left.
      lcd.print("Aktueller PH =  "[positionCounter2]); // Print a message to the LCD.
      delay(250);                          //wait for 250 microseconds
    }

    // lcd.clear();  //Clears the LCD screen and positions the cursor in the upper-left corner.   
    
    lcd.setCursor(0,1);                    // set the cursor to column 15, line 0
    for (int positionCounter1 = 0; positionCounter1 < 16; positionCounter1++)
    {
--->    lcd.print(  (phValue,2 )     [positionCounter1]); // Print a message to the LCD. <-------------------
      delay(250);                          //wait for 250 microseconds[/b]
    } 
    
    lcd.setCursor(1,0);                    // set the cursor to column 15, line 1
    for (int positionCounter3 = 0; positionCounter3 < 16; positionCounter3++)
    {
      lcd.print(" @  00:00 Uhr   "[positionCounter3]); // Print a message to the LCD.
      delay(250);                          //wait for 250 microseconds
    }
}
return root; 
    }
}

I have marked the Cells (I think there wrong) with an Arrow in the Code

The ERROR that Arduino IDE Gives:

/Volumes/SSD/Arduino/SpFo/SpFo.ino: In function 'ArduinoJson::JsonObject& prepareResponse(ArduinoJson::JsonBuffer&)':
SpFo:80: error: invalid types 'int[int]' for array subscript
       lcd.print(  (phValue,2)     [positionCounter1]); // Print a message to the LCD.
                                                    ^
Bibliothek ArduinoJson-5.13.0 in Version 5.13.0 im Ordner: /Volumes/SSD/Arduino/libraries/ArduinoJson-5.13.0  wird verwendet
Bibliothek DHT_sensor_library in Version 1.3.0 im Ordner: /Volumes/SSD/Arduino/libraries/DHT_sensor_library  wird verwendet
Bibliothek LiquidCrystal in Version 1.0.7 im Ordner: /Applications/Arduino.app/Contents/Java/libraries/LiquidCrystal  wird verwendet
exit status 1
invalid types 'int[int]' for array subscript

Now i wont Give Up (Display is built in table already :wink: ) and ask here.

I think someone could help me.

Very big Thank you …

Best Greetings

Ned

Hey Guys,
when nobody has an answer, perhaps somebody has an idea or a way i can go to find the issue ...

Best Greetings

Ned

The Problem ist the Sensor Sends like: " 8.343.646.757.343.758" but I need "8.34" as Result.

    float result = atof( " 8.343.646.757.343.758");  
//atof() will skip the leading space and parse characters while legal
// e.g. result = 8.343;
//
// a subsequent Serial.print(), printf(), dtostrf() will give you "8.34" if you specify 2-decimals
//
// note that Serial.print(8.345, 2); would give "8.35" to 2-decimals i.e. it rounds up or down.
//

The above "trick" relies on atof() and similar functions stopping when they run out of legal characters.
You could perform your own procedure by starting from the left, looking for a period, then accepting 2 characters to the right of the decimal point.

It is easy enough to use the standard C library functions like atof(), printf()
Or you can manipulate with C string functions.

Of course C++ has the String class. Arduino does not do String very well.

Untested.

David.

Hey,
thank you a lot.

I will test it when the new display arrived.

the other one was burned or something @ half.
I think i have wrong wired ...

Will report you ...

Greetings