pvdbos
1
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
gcjr
3
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)
pvdbos
4
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
gcjr
5
if the temperature is a float you may need to convert it to an interger, int()
pvdbos
8
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.
gcjr
10
printf(t, "Temparature = %d", int (bme.readTemperature()));
pvdbos
12
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.
gcjr
14
from reply #2 with int() added
char s [40];
sprintf (s, "Temparature = %d", int(bme.readTemperature()) );
ssd1306_printFixed(64, 30, s, STYLE_NORMAL)
pvdbos
15
oke its working now
I have now Temparature = 21