1

I am just trying to set up the U8g2 library to use an OLED. I read through the documentation and tried copying and pasting the code block example for the constructor, but switched out their information for my OLED's information. After trying to verify, the IDE returned this error: exit status 1 expected ')' before ',' token

#include <SPI.h>
#include <U8g2lib.h>

//Constructor
U8G2_SSD1306_128X64_NONAME_1_SW_I2C(U8G2_R0,A5,A4);```

I saw a similar post about this problem from four years ago, but the only suggestion on there was to capitalize the "A" in the analog pins. I tried this and nothing changed. Any help would be much appreciated!
3
  • are there the correct number of arguments in the constructor?
    – jsotola
    Sep 20, 2020 at 15:52
  • According to the website, it takes in the rotation, clock, and data. It also has [, reset] listed, but I don't have a pin for that. github.com/olikraus/u8g2/wiki/u8g2setupcpp
    – Kayla
    Sep 20, 2020 at 16:04
  • i think that you are missing the object name U8G2_SSD1306_128X64_NONAME_1_SW_I2C abc123(U8G2_R0,A5,A4);
    – jsotola
    Sep 20, 2020 at 16:29

1 Answer 1

1

I figured out what I was doing wrong. I was copying the name from the Constructor Reference and immediately inputting the arguments in parentheses. I needed to put u8g2 after the constructor name and then put the arguments. Thanks!

The corrected code is as follows:

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

//Constructor
U8G2_SSD1306_128X64_NONAME_1_SW_I2C u8g2(U8G2_R0,A5,A4);
1
  • It doesn't have to be "u8g2". You could name your instance Fred or Jim or Bob for all the compiler cares. But you do have to give it a name.
    – Delta_G
    Sep 20, 2020 at 18:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.