olikraus / u8g2

U8glib library for monochrome displays, version 2
Other
5.05k stars 1.04k forks source link

U8X8_SSD1305_128X32_NONAME_2ND_HW_I2C isn’t a constructor? #943

Closed FGasper closed 4 years ago

FGasper commented 5 years ago

Hello,

Maybe I’m misunderstanding something in the documentation, but when I replace:

U8X8_SSD1306_128X64_NONAME_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);

… with:

U8X8_SSD1305_128X32_NONAME_2ND_HW_I2C u8x8();

… and try to verify the code, Arduino IDE gives me:

request for member 'begin' in 'u8x8', which is of non-class type 'U8X8_SSD1305_128X32_NONAME_2ND_HW_I2C()'

Here’s my full sketch; is there something I’m missing?

#include <Arduino.h>
#include <SPI.h>
#include <U8x8lib.h>

/* Constructor */
//U8X8_SSD1306_128X64_NONAME_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
U8X8_SSD1305_128X32_NONAME_2ND_HW_I2C u8x8(void);

/* u8x8.begin() is required and will sent the setup/init sequence to the display */
void setup(void)
{
  u8x8.begin();
}

void loop(void)
{
  u8x8.setFont(u8x8_font_chroma48medium8_r);
  u8x8.drawString(0,0,"Hello World!");
  delay(1000);
}

Thank you!

FGasper commented 5 years ago

It appears that specifying the reset pin is needed. I’m going to leave this issue open in case an update to the docs seems warranted.

Thank you!

olikraus commented 5 years ago

Hmm.. you skip the reset pin from my perspective, the problem seems to be the "void" argument, which is probably not valid: U8X8_SSD1305_128X32_NONAME_2ND_HW_I2C u8x8(void); This should be U8X8_SSD1305_128X32_NONAME_2ND_HW_I2C u8x8(); instead.

Actually this is not a u8g2 issue more a general C++ topic.

hansmbakker commented 1 year ago

I see this is closed, but I do have the same error when doing

U8X8_SSD1306_128X32_UNIVISION_HW_I2C u8x8();

(without literally specifying void as a parameter). Is this expected behavior?

olikraus commented 1 year ago

Which error exactly you have?

hansmbakker commented 1 year ago

The relevant parts of my code are:

#include <U8x8lib.h>
U8X8_SSD1306_128X32_UNIVISION_HW_I2C display();

void printOnDisplay(std::string text, bool keepOnDisplay)
{
  display.drawString(0, 0, text.c_str());
  if (!keepOnDisplay)
  {
    delay(1000);
    display.clearDisplay();
  }
}

void setup()
{
  display.begin();
  printOnDisplay(std::string("Hello"), true);
  delay(3000);
  display.clearDisplay();
}

void loop()
{
}

The relevant errors I get are: image

olikraus commented 1 year ago

Hm strange. Maybe try:

U8X8_SSD1306_128X32_UNIVISION_HW_I2C display(U8X8_PIN_NONE);
hansmbakker commented 1 year ago

Sorry for my late response!

U8X8_SSD1306_128X32_UNIVISION_HW_I2C display(U8X8_PIN_NONE);

works!

Which is odd though, because the constructor does have a default parameter value: https://github.com/olikraus/u8g2/blob/a543c481319f381e91c0caea664b7be5ade59635/cppsrc/U8x8lib.h#L2143

I don't have the C++ experience to understand why this still happens, so unfortunately I cannot create a PR for this.

Would it be possible to update the docs at https://github.com/olikraus/u8g2/wiki/u8x8setupcpp#ssd1306-128x32_univision-1? There the parameter is marked optional.

olikraus commented 1 year ago

I agree, your constructor should also work. Maybe Arduino IDE changes something here. It runs a preprocessor on the code. :-/