Help using U8g2

Hi forum!

I am working on a project for a friend and ran into some trouble over the weekend which now causes me some serious panic.

What I am trying to do is display a bitmap once an RFID tag is sensed by an MFRC522. Everything except the screen is now working. At first, I could not get the screen to project bitmaps when I used the SSD1306 library along with the Adafruit GFX library.

Hence, I switched to the U8g2 library and again, everything except the screen is working fine but I am getting countless error-messages, primarily “expected ‘)’ before ‘,’ token” in a place where I cannot for the life of me see what is wrong as well as “'function was not declared in this scope” even though the library is included. I get that on every stated U8g2-function… I just don’t know what to do and I would really appreciate some professional guidance so that I can solve this ASAP, at the moment I do not even know where to start…

I have attached the code to this post. All help is greatly appreciated.

Chris

Project_Y.ino (13.6 KB)

I don’t have the libraries to be able to try to compile to see the errors. Please post the complete text of the errors. There is information in the error message that tells you where to look. Please read the “how to use the forum” stickies to see how to post the errors in code tags. It is much better if you post your code that way, as well, so we don’t have to download it.

Hi, thanks for your reply!

Absolutely. The code is as follows:

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

U8G2_SSD1306_128X64_NONAME_1_SW_I2C(U8G2_R0, a5, a4);

#define SS_PIN 10
#define RST_PIN 

MFRC522 mfrc522(SS_PIN, RST_PIN);   // MFRC522 instance.

int frame = 0;

int LED = 8;

const uint8_t frame1 [] PROGMEM = {
BITMAP 1 CODE 
};

const uint8_t frame2[] PROGMEM = {
BITMAP 2 CODE.
};



void setup(void) {
  
  u8g2.begin();
  
  Serial.begin(9600);   // Initiate a serial communication
  
  SPI.begin();      // Initiate  SPI bus  
  
  mfrc522.PCD_Init();   // Initiate MFRC522
  
  Serial.println("Welcome to OMNID");

  pinMode (LED,OUTPUT);

  present();
}

void loop(void) {

if ( ! mfrc522.PICC_IsNewCardPresent()) 
 {
    return;
  }
  // Select one of the cards
  if ( ! mfrc522.PICC_ReadCardSerial()) 
  {
    return;
  }
  //Show UID on serial monitor
  Serial.print("UID tag :");
  String content= "";
  byte letter;
  for (byte i = 0; i < mfrc522.uid.size; i++) 
  {
     Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
     Serial.print(mfrc522.uid.uidByte[i], HEX);
     content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
     content.concat(String(mfrc522.uid.uidByte[i], HEX));
  }
  Serial.println();
  Serial.print("Message : ");
  content.toUpperCase();
  if (content.substring(1) == "D1 34 47 D5")//change here the UID of the card/cards that you want to give access
  {
     digitalWrite(LED, HIGH);
     Serial.println("X");
     u8g2.firstPage();
  do {
     u8g2.clearBuffer();
     drawBitmap(0, 0, 16, 64, const uint8_t frame1);
     u8g2.sendBuffer();
     delay(4000);
  } while ( u8g2.nextPage() );
     digitalWrite(LED, LOW);
//   delay(10000);
     present();
  }
  if (content.substring(1) == "A5 B1 03 6D")//change here the UID of the card/cards that you want to give access
  {   
      digitalWrite(LED, HIGH);
      Serial.println("Y");
      u8g2.firstPage();
  do {
     u8g2.clearBuffer();
     drawBitmap(0, 0, 16, 64, const uint8_t frame2);
     u8g2.sendBuffer();
     delay(4000);
  } while ( u8g2.nextPage() );
     digitalWrite(LED, LOW);
//   delay(10000);
     present();
  }
}

void present(){
  // Clear the buffer.
       u8g2.clearBuffer();
       u8g2.firstPage();
       u8g2.setFont(u8g_font_04b_03b);
       u8g2.setPrintPos(20, 20);
       u8g2.print("PRESENT OMNID"); 

}

The errors are as follows:

Project_Y:6: error: expected ‘)’ before ‘,’ token
U8G2_SSD1306_128X64_NONAME_1_SW_I2C(U8G2_R0, a5, a4);
^
Project_Y:6: error: no matching function for call to ‘U8G2_SSD1306_128X64_NONAME_1_SW_I2C::U8G2_SSD1306_128X64_NONAME_1_SW_I2C()’
U8G2_SSD1306_128X64_NONAME_1_SW_I2C(U8G2_R0, a5, a4);
^
/Users/christofferjensen/Documents/Arduino/Project_Y/Project_Y.ino:6:46: note: candidates are:
In file included from /Users/christofferjensen/Documents/Arduino/Project_Y/Project_Y.ino:1:0:
/Users/christofferjensen/Documents/Arduino/libraries/U8g2-2.8.5/src/U8g2lib.h:400:11: note: U8G2_SSD1306_128X64_NONAME_1_SW_I2C::U8G2_SSD1306_128X64_NONAME_1_SW_I2C(const u8g2_cb_t*, uint8_t, uint8_t, uint8_t)
public: U8G2_SSD1306_128X64_NONAME_1_SW_I2C(const u8g2_cb_t *rotation, uint8_t clock, uint8_t data, uint8_t reset = U8X8_PIN_NONE) : U8G2() {
^
/Users/christofferjensen/Documents/Arduino/libraries/U8g2-2.8.5/src/U8g2lib.h:400:11: note: candidate expects 4 arguments, 0 provided

/Users/christofferjensen/Documents/Arduino/libraries/U8g2-2.8.5/src/U8g2lib.h:399:7: note: constexpr U8G2_SSD1306_128X64_NONAME_1_SW_I2C::U8G2_SSD1306_128X64_NONAME_1_SW_I2C(const U8G2_SSD1306_128X64_NONAME_1_SW_I2C&)
class U8G2_SSD1306_128X64_NONAME_1_SW_I2C : public U8G2 {
^
/Users/christofferjensen/Documents/Arduino/libraries/U8g2-2.8.5/src/U8g2lib.h:399:7: note: candidate expects 1 argument, 0 provided

/Users/christofferjensen/Documents/Arduino/libraries/U8g2-2.8.5/src/U8g2lib.h:399:7: note: constexpr U8G2_SSD1306_128X64_NONAME_1_SW_I2C::U8G2_SSD1306_128X64_NONAME_1_SW_I2C(U8G2_SSD1306_128X64_NONAME_1_SW_I2C&&)

/Users/christofferjensen/Documents/Arduino/libraries/U8g2-2.8.5/src/U8g2lib.h:399:7: note: candidate expects 1 argument, 0 provided

Project_Y:6: error: expected initializer before ‘)’ token
U8G2_SSD1306_128X64_NONAME_1_SW_I2C(U8G2_R0, a5, a4);
^
Project_Y:11: error: expected primary-expression before ‘)’ token
MFRC522 mfrc522(SS_PIN, RST_PIN); // MFRC522 instance.
^
/Users/christofferjensen/Documents/Arduino/Project_Y/Project_Y.ino: In function ‘void setup()’:
Project_Y:149: error: ‘u8g2’ was not declared in this scope
u8g2.begin();
^
/Users/christofferjensen/Documents/Arduino/Project_Y/Project_Y.ino: In function ‘void loop()’:
Project_Y:191: error: ‘u8g2’ was not declared in this scope
u8g2.firstPage();
^
Project_Y:194: error: expected primary-expression before ‘const’
drawBitmap(0, 0, 16, 64, const uint8_t frame1);
^
Project_Y:194: error: ‘drawBitmap’ was not declared in this scope
drawBitmap(0, 0, 16, 64, const uint8_t frame1);
^
Project_Y:206: error: ‘u8g2’ was not declared in this scope
u8g2.firstPage();
^
Project_Y:209: error: expected primary-expression before ‘const’
drawBitmap(0, 0, 16, 64, const uint8_t frame2);
^
Project_Y:209: error: ‘drawBitmap’ was not declared in this scope
drawBitmap(0, 0, 16, 64, const uint8_t frame2);
^
/Users/christofferjensen/Documents/Arduino/Project_Y/Project_Y.ino: In function ‘void present()’:
Project_Y:221: error: ‘u8g2’ was not declared in this scope
u8g2.clearBuffer();
^
Project_Y:223: error: ‘u8g_font_04b_03b’ was not declared in this scope
u8g2.setFont(u8g_font_04b_03b);
^
exit status 1
expected ‘)’ before ‘,’ token

Thanks!

U8G2_SSD1306_128X64_NONAME_1_SW_I2C(U8G2_R0, a5, a4);

There is something about this line that is causing an error that seems to cascade through the sketch. try A5 and A4. C++ is case sensitive.

#define RST_PIN

You might want to fix this missing value, too.

This page has guidelines for the constructors. Make sure that the right number and type of arguments are supplied.

If you are still having trouble, I would suggest that you write a sketch with just the display by itself. Sort that out then add the other stuff.

Hi

I agree, you definitly have to provide some value for RST_PIN.
Currently the second constructore evaluates to this:

MFRC522 mfrc522(SS_PIN, );   // MFRC522 instance.

Just to ensure, but the initial part should be more like this:

#include <U8g2lib.h>
#include <U8x8lib.h>     // not required, remove this line
#include <SPI.h>         
#include <Wire.h>         // included for I2C support.
#include <MFRC522.h>

Oliver