Waveshare 1.5inch OLED using int issue

Hi, I am building a cluster display for a car I am building for a car and so far have laid out the information I need, can read and map CAN data but I am stuck on something very silly.

The OLED I am using is a waveshare 1.5 mono OLED driven over SPI and the screen is working and displaying information as I would expect when static.

In the scope I have the following:

int ECT1 = 12;

Then within the void loop I have the following:

  GUI_DisString_EN(0, 4, "ECT:", &Font16, FONT_BACKGROUND, WHITE);
  GUI_DisString_EN(75, 4, ECT1, &Font16, FONT_BACKGROUND, WHITE);
  OLED_DisPage(0, 1);
  OLED_ClearBuf();

On the call up of the int using ECT1 I would expect the screen to display a number however I am receiving a full block of print - if I took out ECT1 and replace with "12" that works no issues

Is there a better way to do this? I am using the waveshare lib and maybe this is where the complications are however this is a screen used a lot and I can find very little information on how I can have numbers mapped to the screen output

I have noticed on here when uploading the ECT1 puts the 1 as green but I have tried other names such as EC and no alteration of the int makes any change

I have also tried GUI_DisNum(75, 4, ECT1, &Font16, FONT_BACKGROUND, WHITE); which kept resetting the Arduino

Thank you for your time

GUI_DisString_EN(75, 4, ECT1, &Font16, FONT_BACKGROUND, WHITE);

I think this function is expecting a string and you are giving it an int. It probably interprets the int as a memory location and tries to print the string at that location, which probably contains random data. So not surprised that does not work.

GUI_DisNum(75, 4, ECT1, &Font16, FONT_BACKGROUND, WHITE); 

That sounds more like the correct function, but clearly something still isn't right if it resets the Arduino. But I can't help you figure out what's wrong without knowing the library you are using. Knowing the type of Arduino board would also be helpful.

1 Like

Board is a UNO

#include "OLED_Driver.h"
#include "OLED_GUI.h"
#include "DEV_Config.h"
#include "Debug.h"

This is the script with a lot of the other items removed to keep it simple whilst I ask for help and trial.

#include "OLED_Driver.h"
#include "OLED_GUI.h"
#include "DEV_Config.h"
#include "Debug.h"

#define S1 2
#define S2 3
#define S3 4
#define S4 5
#define S5 6
#define S6 9

int EC = 1;
int AF = 2;
int IA = 3;
int FP = 4;
int OP = 5;
int OT = 6;
int BO = 7;

extern OLED_DIS sOLED_DIS;
void setup()
{
  System_Init();

  Serial.println("OLED Init ");
  OLED_SCAN_DIR OLED_ScanDir = SCAN_DIR_DFT;
  OLED_Init( OLED_ScanDir );

  Serial.println("OLED_Show ");
  //GUI_Show();
  OLED_ClearBuf();
  OLED_ClearScreen(OLED_BACKGROUND);

  GUI_DisString_EN(40, 4, "RKXX", &Font16, FONT_BACKGROUND, WHITE);
  OLED_DisPage(0, 2);
  OLED_ClearBuf();

  GUI_DisString_EN(36, 4, "TURBO", &Font16, FONT_BACKGROUND, WHITE);
  OLED_DisPage(0, 3);
  OLED_ClearBuf();

  GUI_DisString_EN(47, 4, "RXX", &Font16, FONT_BACKGROUND, WHITE);
  OLED_DisPage(0, 4);
  OLED_ClearBuf();

  delay(1000);

  pinMode(S1, OUTPUT);
  pinMode(S2, OUTPUT);
  pinMode(S3, OUTPUT);
  pinMode(S4, OUTPUT);
  pinMode(S5, OUTPUT);
  pinMode(S6, OUTPUT);

  digitalWrite(S1, HIGH);   //
  delay(1000);   
  digitalWrite(S2, HIGH);   //
  delay(1000);   
  digitalWrite(S3, HIGH);   //
  delay(1000);   
  digitalWrite(S4, HIGH);   //
  delay(1000);   
  digitalWrite(S5, HIGH);   //
  delay(1000);   
  digitalWrite(S6, HIGH);   //
  delay(1000);   

}

void loop()
{
  GUI_DisString_EN(0, 4, "ECT:", &Font16, FONT_BACKGROUND, WHITE);
  GUI_DisString_EN(75, 4, EC, &Font16, FONT_BACKGROUND, WHITE);
  OLED_DisPage(0, 1);
  OLED_ClearBuf();


  }

The library item OLED_GUI.h suggests its method for us as below which feels right but with it falling over I have either understood it wrong or entered data wrong

void GUI_DisNum(POINT Xpoint, POINT Ypoint, int Nummber, sFONT* Font, COLOR Color_Background, COLOR Color_Foreground);

I can't see anything wrong with the way you are using it. Perhaps there is a bug in the library. Do you have a link to the library's repository? If the repo is GitHub, there might be an open issue for this problem.

1 Like

Good call - the library came as part of the waveshare download off their website which looks like it has not been touched since 2019

https://www.waveshare.com/wiki/File:1.5inch_OLED_Moudle.7z

Maybe this is where the issues is. I am not new to Ardunio but I am to OLED screens so assumed I was setting something up wrong - I will have a look atx github and see if anything newer has been posted up else I will look for another library item for a 128x128

You could try a workaround like

  GUI_DisString_EN(0, 4, "ECT:", &Font16, FONT_BACKGROUND, WHITE);
  char buffer[6];
  itoa(ECT1,buffer,10); 
  GUI_DisString_EN(75, 4, buffer, &Font16, FONT_BACKGROUND, WHITE);
  OLED_DisPage(0, 1);
  OLED_ClearBuf();
1 Like

Maybe checkout

The author/maintainer is (or was) a member on this forum, so will hopefully be responsive and willing to help, provided that his library supports your oled screen.

EDIT: Ah, no. Your OLED is 16-bit greyscale. U8G2 supports only monochrome displays, I think (meaning 1-bit per pixel).

Paul, Thank you for the workaround, I am so over joyed that worked! Having never used buffer commands I did try and use the same buffer for multiple instances and it didn't work - I will look the rules up or I assume there will be a buffer flush etc to clear the buffer down between read / write

Should be no problem using the same buffer as many times as you need. Just make sure it's long enough to hold the longest number you need to print, plus at least one character extra (for the null-terminator). Each time you use itoa() it will overwrite the buffer, so no need to flush/clear.

1 Like

Thank you. I have spent a few hours trying to work it out as I didn't want to just ask.

When I add a second set the same as the fist with different names as below I receive a 'conflicting declaration 'char buffer [15]'

  GUI_DisString_EN(0, 4, "ECT:", &Font16, FONT_BACKGROUND, WHITE);
  char buffer[6];
  itoa(EC,buffer,10); 
  GUI_DisString_EN(75, 4, buffer, &Font16, FONT_BACKGROUND, WHITE);
  OLED_DisPage(0, 1);
  OLED_ClearBuf();
  delay (100);

  GUI_DisString_EN(0, 4, "AFR:", &Font16, FONT_BACKGROUND, WHITE);
  char buffer[15];
  itoa(AF,buffer,19); 
  GUI_DisString_EN(75, 4, buffer, &Font16, FONT_BACKGROUND, WHITE);
  OLED_DisPage(0, 2);
  OLED_ClearBuf();
  delay (100);

Arduino: 1.8.16 (Windows Store 1.8.51.0) (Windows 10), Board: "Arduino Uno"

C:\Users\AppData\Local\Temp\arduino_modified_sketch_228478\oled_r53.ino: In function 'void loop()':

oled_r53:171:17: error: conflicting declaration 'char buffer [15]'

char buffer[15];

             ^

C:\User\AppData\Local\Temp\arduino_modified_sketch_228478\oled_r53.ino:163:8: note: previous declaration as 'char buffer [6]'

char buffer[6];

    ^~~~~~

exit status 1

conflicting declaration 'char buffer [15]'

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

But they don't have different names. They are both called "buffer". That's what the error message is about.

By the way, thanks for posting the full error message instead of just saying "I got an error". Please post error messages in code tags.

Make one "buffer". It can be a global variable or local to a function as you like. Follow my advice about the length.

itoa(AF,buffer,19); 

You don't want to display a number in base 19. No-one uses base 19 on this planet! Stick to base 10.

1 Like