SSD1306 library of Alexey Dynda

Hello, all

I will use the SSD1306 library of Alexey Dynda lexus2k (Aleksei) · GitHub.

there are a lot nice examples of with you can do with the Oled.

but view an simple variable on the screen is for my difficult.

I only will an value on the screen of an BME280 temperature.

ssd1306_printFixed(0, 30, "Temparature =", STYLE_NORMAL);
ssd1306_printFixed(64, 30, bme.readTemperature(), STYLE_NORMAL);

The "text" on the screen is no problem but an variable is a problem

This will give an error but how must I do to work this.

Doesn't the library have methods for printing variables? :o

you can use sprintf() to format a string which can be displayed

    char s [40];
    sprintf (s,  "Temparature = %d", bme.readTemperature());
    ssd1306_printFixed(64, 30, s, STYLE_NORMAL)

I have now:

in the begin of my code
char[40];

and in a sub program

void BME_sensor() {

printf(t, "Temparature = %d", bme.readTemperature());
ssd1306_printFixed(0, 30, "Temparature =", STYLE_NORMAL);
ssd1306_printFixed(64, 30, t, STYLE_NORMAL);
}

on my screen ar stranges charaters

Temparature = #$#@# but not the temp.
ore something

if the temperature is a float you may need to convert it to an interger, int()

yes.

and how do I that?

int() (click link)

int (t);

void loop() {
BME_sensor();
}

void BME_sensor() {

printf(t, "Temparature = %d", bme.readTemperature());
ssd1306_printFixed(0, 30, "Temparature =", STYLE_NORMAL);
ssd1306_printFixed(64, 40, t, STYLE_NORMAL);

}

Sorry does not work.

void BME_sensor() {

    printf(t, "Temparature = %d", bme.readTemperature());

That should be sprintf.
I'm surprised it compiled, let alone produced a result.

"t" should be a character buffer, not an int.

   printf(t, "Temparature = %d", int (bme.readTemperature()));

**s**printf

no

sprintf(t, "Temparature = %d", int(bme.readTemperature()));

error on t

int is incompatible with the parameter of "char"

t should be a char buffer.
I've already mentioned this.

from reply #2 with int() added

    char s [40];
    sprintf (s,  "Temparature = %d", int(bme.readTemperature()) );
    ssd1306_printFixed(64, 30, s, STYLE_NORMAL)

oke its working now
I have now Temparature = 21