I am having problems trying to print variables to a ssd1306 display using lcdgfx or ssd1306 library by lexus2k, there's an issue closed at lcdgfx repository about problems with displaying a variable
([OLED 0,96 - problem with displaying a variable · Issue #44 · lexus2k/lcdgfx · GitHub](OLED 0,96 - problem with displaying a variable · Issue #44 · lexus2k/lcdgfx · GitHub
also this one
displaying floating point numbers · Issue #42 · lexus2k/lcdgfx · GitHub))
i tried adding the piece of code that the developer recommended which converts numbers float to string and then prints it out, but when i do that on the ssd1306 library it just gives me a question mark and on the lcdgfx i get blank space.
code for ssd1306:
ssd1306_128x64_i2c_init(); //initializer for display (ssd1306 library)
void display() //loop for controlling the display
{
ssd1306_clearScreen(); //clears the screen
//ssd1306_fillScreen(0x00);
ssd1306_setFixedFont(ssd1306xled_font8x16); //sets font sizessd1306_printFixed(70, 0, "T=", STYLE_BOLD);}
void printFloatNumber() //loop for printing float numbers on oled display
{
char StrT[10];snprintf(StrT, sizeof(StrT), "%f", currentTemperature); //also tried sprintf( str, "%.2f", temp ); ssd1306_printFixed(85, 0, StrT, STYLE_NORMAL);}
void setup()
{
Serial.begin(115200); //starts serial communication at 115200 baud rateattachInterrupt(INTERRUPT, isr, CHANGE); ssd1306_clearScreen(); //clears the screen //ssd1306_fillScreen(0x00); ssd1306_setFixedFont(ssd1306xled_font8x16); //sets font size}
void loop()
{
currentMillis = millis();if (currentMillis - previousMillis >= interval) { previousMillis = currentMillis; warningLED(); display(); printFloatNumber(); //ssd1306_clearScreen(); //clears the screen }}
code for lcdgfx:
DisplaySSD1306_128x64_I2C display(-1); //initializer for display (lcdgfx library)
void printFloatNumber() //loop for printing float numbers on oled display
{
sprintf(StrT, "%.2f", currentTemperature);
display.write(85, 0, StrT, STYLE_NORMAL);
}void setup()
{
Serial.begin(115200); //starts serial communication at 115200 baud rate
display.begin();attachInterrupt(INTERRUPT, isr, CHANGE); // interrupt 0 is pin 2, interrupt 1 is pin 3 display.setFixedFont(ssd1306xled_font8x16); display.clear(); //display.printFixed(0, 0, "U=", STYLE_BOLD); //display.printFixed(0, 16, "I=", STYLE_BOLD); //display.printFixed(0, 32, "P=", STYLE_BOLD); //display.printFixed(70, 0, "T=", STYLE_BOLD);}
void loop()
{
currentMillis = millis();if (currentMillis - previousMillis >= interval) { previousMillis = currentMillis; display(); printFloatNumber(); //ssd1306_clearScreen(); //clears the screen display.clear();
display.printFixed(0, 0, "U=", STYLE_BOLD); display.printFixed(0, 16, "I=", STYLE_BOLD); display.printFixed(0, 32, "P=", STYLE_BOLD); display.printFixed(70, 0, "T=", STYLE_BOLD); }
any idea what's wrong?