Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OLED 0,96 - problem with displaying a variable #44

Closed
szymonsmolka opened this issue Feb 11, 2021 · 18 comments
Closed

OLED 0,96 - problem with displaying a variable #44

szymonsmolka opened this issue Feb 11, 2021 · 18 comments
Assignees
Labels
question Further information is requested

Comments

@szymonsmolka
Copy link

Ask any question, you have, regarding the library
Hi. I'm trying to use the lcdgfx library to run a 0.96 64x128 OLED display with the SH1107 driver. I wanted to make a simple thermometer. The temperature is assigned to the float variable, but the display does not show it.
display.printFixed (0, 0, temp, STYLE_BOLD);

How do I enter such a code for example
display.printFixed (0, 0, "TEST", STYLE_BOLD);

The display works and shows TEST

Where is the problem? Please help.

@szymonsmolka szymonsmolka added the question Further information is requested label Feb 11, 2021
@lexus2k
Copy link
Owner

lexus2k commented Feb 11, 2021

Please, try:

    display.setTextCursor(0,0);
    display.print( temp );

The function supports only int variables

@szymonsmolka
Copy link
Author

The temperature is displayed. Thank you. However, there is no decimal value. Is there a way to do this?
Can the font size be changed in this function?

@lexus2k
Copy link
Owner

lexus2k commented Feb 16, 2021

@szymonsmolka

I'm sorry for the delay. Actually you can display any numbers you want like this:

   char str[10];
   sprintf( str, "%.2f", temp );
   display.print( str );

@szymonsmolka
Copy link
Author

No problem :) But it doesn't help. The value of 1266 is displayed all the time. Fortunately, I managed differently with decimal values.
Unfortunately, I can't enlarge the font. Is it possible at all?

@szymonsmolka
Copy link
Author

szymonsmolka commented Feb 19, 2021

char str[10];
   sprintf( str, "%.2f", temp );
   display.print( str );

Have an idea why the value 1266 is displayed?

@lexus2k
Copy link
Owner

lexus2k commented Feb 19, 2021

Hi, I'm sorry, that was the wrong location of f character in format string.
I fixed the format string in the examples above.

Anyway, there is very rich documentation on printf and sprintf functions over internet. Please refer to documentation.

@lexus2k
Copy link
Owner

lexus2k commented Feb 19, 2021

изображение

@lexus2k
Copy link
Owner

lexus2k commented Feb 19, 2021

Can the font size be changed in this function?

No, the only supported feature is for monochrome displays. printFixedN

@szymonsmolka
Copy link
Author

Anyway, there is very rich documentation on printf and sprintf functions over internet. Please refer to documentation.

After your answer, I did so. The code looks fine, and so on it returns 1266. For example, if I change str [10] to str [15], the value is 1249. Can you take a look at what's wrong with the code?

`#include "lcdgfx.h"
#include "lcdgfx_gui.h"
#include <Arduino.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>

OneWire oneWire(A0);
DallasTemperature sensors(&oneWire);

DisplaySH1107_64x128_I2C display(-1);

float temp;

void setup()
{
display.begin();
display.setFixedFont(ssd1306xled_font6x8);
display.clear();
display.fill(0x00);
sensors.begin();
}

void loop()
{

sensors.requestTemperatures();
temp = sensors.getTempCByIndex(0);

display.setTextCursor(0, 64);
char str[10];
sprintf( str, "%.2f", temp );
display.print( str );

delay (5000);

}`

@lexus2k
Copy link
Owner

lexus2k commented Feb 20, 2021

Which version of Arduino IDE are you using? Does it display any warnings / errors?

Try this code:

char str[10];
sprintf( str, "%.2f", temp );
display.write( str );

@szymonsmolka
Copy link
Author

Which version of Arduino IDE are you using?

Arduino IDE 1.8.13

Does it display any warnings / errors?

Summary after upload:

Sketch uses 10044 bytes (70%) of program storage space. Maximum is 14336 bytes.
Global variables use 336 bytes (32%) of dynamic memory, leaving 688 bytes for local variables. Maximum is 1024 bytes.

char str[10];
sprintf( str, "%.2f", temp );
display.write( str );

After this change, the display only shows a question mark :(
Also no warnings.

@lexus2k
Copy link
Owner

lexus2k commented Feb 20, 2021

I don't have all those sensors. so I commented out the code reading the temperature, and replaced it with single assignment. And it works. So the issue somewhere in another library, and not in lcdgfx

#include "lcdgfx.h"
#include "lcdgfx_gui.h"
//#include <Arduino.h>
//#include <OneWire.h>
//#include <DallasTemperature.h>
//#include <Wire.h>

//OneWire oneWire(A0);
//DallasTemperature sensors(&oneWire);

DisplaySH1107_64x128_I2C display(-1);

float temp;

void setup()
{
  display.begin();
  display.setFixedFont(ssd1306xled_font6x8);
  display.clear();
  display.fill(0x00);
  // sensors.begin();
}

void loop()
{

  // sensors.requestTemperatures();
  temp = 23.23; // sensors.getTempCByIndex(0);

  display.setTextCursor(0, 64);
  char str[10];
  sprintf( str, "%.2f", temp );
  display.write( str );

  delay (5000);

}

The result:
изображение

@szymonsmolka
Copy link
Author

An interesting thing. When I do what you did, it still displayed a question mark. Maybe my display is broken.

@lexus2k
Copy link
Owner

lexus2k commented Feb 23, 2021

@szymonsmolka What about direct_draw/draw_text example? Can you capture the result for that example for me?

@szymonsmolka
Copy link
Author

szymonsmolka commented Feb 25, 2021

@szymonsmolka What about direct_draw/draw_text example? Can you capture the result for that example for me?

@lexus2k

https://github.com/lexus2k/lcdgfx/blob/master/examples/direct_draw/draw_text/draw_text.ino

Not working. The same result. Question mark.

@Mephisto68
Copy link

Mephisto68 commented Oct 25, 2023

Can the font size be changed in this function?

No, the only supported feature is for monochrome displays. printFixedN

Hello,
We cannot "send" this to the screen:
Display.printFixedN(10, 52, var, STYLE_NORMAL, FONT_SIZE_2X);
But what a shame not to be able to do that!
I will have to get another library
However, yours is so good!
Would it not be possible in a future version to add this function?
Thanks.

@Mephisto68
Copy link

include "lcdgfx.h"
#include "lcdgfx_gui.h"

/* LCD */
#define PORT_ECRAN_RESET 10
#define PORT_ECRAN_CS 8
#define PORT_ECRAN_DC 9
#define PORT_ECRAN_MOSI_SDA 11
#define PORT_ECRAN_SCK_SCL 13
#define PORT_ECRAN_ECLAIRAGE 7
DisplayST7735_128x128x16_SPI display = DisplayST7735_128x128x16_SPI(PORT_ECRAN_RESET,{-1, PORT_ECRAN_CS, PORT_ECRAN_DC, 0, PORT_ECRAN_MOSI_SDA, PORT_ECRAN_SCK_SCL});

float temp;

void setup()
{
display.begin();
display.setFixedFont(ssd1306xled_font6x8);
display.clear();
display.fill(0x00);
// sensors.begin();
}

void loop()
{

// sensors.requestTemperatures();
temp = 23.23; // sensors.getTempCByIndex(0);

display.setTextCursor(20, 20);
char str[10];
sprintf( str, "%.2f", temp );
display.write( str );

delay (5000);

}

RESULT : the display only shows a question mark :(

@lexus2k
Copy link
Owner

lexus2k commented Oct 29, 2023

Hi,

I apologize for this inconvenience. However the library has some limitations to reduce flash ram usage.
New functionality can be implemented, it requires some time.

Best regards,
Aleksei

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants