Hi there, i have a ESP8266 based weatherstation with a suite of sensors attached including a dht11 temperature / humidity hydrometer. It displays this data on a 0.96" OLED via i2c using the ssd1306 library:
#include "SSD1306Wire.h"
#include "OLEDDisplayUi.h"
#include "Wire.h"
However, trying to display the percent ‘%’ symbol on screen is causing me a major headache. I’m trying to display the temperature and humidity using sprintf_P to format the string and display it on the oled via the display functions:
char buff2[5];
sprintf_P(buff2, PSTR("%.02f %%"), humidity); //results like 23.500001
display->drawString(26 + x, 30 + y, String(buff2));//humidity;
However the I can’t get the format string correct to escape the percentage symbol ‘%’. I have tried % and %% to no avail. The esp8266 seems to default to using the format string from the previous command which is wrong:
sprintf_P(buff, PSTR("%.02f °C"), temperature); //results like 23.500001
display->drawString(30 + x, 15 + y, String(buff));//temperature;
Can anyone please tell me howto display this correctly?
The full code for the function is:
display->setContrast(162, 31, 0); //usually 255, dim to save screen
display->setTextAlignment(TEXT_ALIGN_CENTER);
display->setFont(ArialMT_Plain_10);
display->drawString(64 + x, 5 + y, "Living Room");
display->setFont(ArialMT_Plain_16);//ArialMT_Plain_24);
//unused code:
//char result[8]; // Buffer big enough for 7-character float
//dtostrf(temperature, 6, 2, result); // Leave room for too large numbers!
char buff[16];
sprintf_P(buff, PSTR("%.02f °C"), temperature); //results like 23.500001
display->drawString(30 + x, 15 + y, String(buff));//temperature;
Serial.print("Temperature buffer: ");
Serial.println(String(buff));
//display->drawString(90 + x, 15 + y, String(Light));//light;
memset(buff, 0, sizeof(buff));//clear array
char buff2[5];
sprintf_P(buff2, PSTR("%.02f %%"), humidity); //results like 23.500001
display->drawString(26 + x, 30 + y, String(buff2));//humidity;
Serial.print("humidity buffer: ");
Serial.println(String(buff2));
Also, the digits of the float humidity are displayed in the wrong place, the correct display in totality should be ‘55.77 %’
The actual display is ''77 0.00 °C" (see attachment)
I dont really understand the printf functions, so any hints and tips are much appreciated!
Thanks in advance,
Garreth