'SSD1306' does not name a type; did you mean 'SSD1306_RECT', why?

Hi everyone,
the ESP32CAM + OLED, compiling got error, I've installed Library Manage of latest, why?

I know it is problem of library, wonder if some one met this situation and may know specific library fit here?

There are two set of SSD/ssd which I changed and tested it.

Thanks
Adam

#include "esp_camera.h"
// #include "SSD1306.h"  // O
 #include "ssd1306.h" // M

// clk:14; sda:15
// SSD1306 display(0x3c, 15, 14); // O
SSD1306 display(0x3c, 15, 14);  // M 

#define SCREEN_WIDTH 128 // OLED显示宽度,以像素为单位
#define SCREEN_HEIGHT 64 

#define SCREEN_WIDTH 128 // OLED显示宽度,以像素为单位
#define SCREEN_HEIGHT 64 


#define PWDN_GPIO_NUM     32
#define RESET_GPIO_NUM    -1
#define XCLK_GPIO_NUM      0
#define SIOD_GPIO_NUM     26
#define SIOC_GPIO_NUM     27

#define Y9_GPIO_NUM       35
#define Y8_GPIO_NUM       34
#define Y7_GPIO_NUM       39
#define Y6_GPIO_NUM       36
#define Y5_GPIO_NUM       21
#define Y4_GPIO_NUM       19
#define Y3_GPIO_NUM       18
#define Y2_GPIO_NUM        5
#define VSYNC_GPIO_NUM    25
#define HREF_GPIO_NUM     23
#define PCLK_GPIO_NUM     22

static camera_config_t camera_config = {
  .pin_pwdn = PWDN_GPIO_NUM,
  .pin_reset = RESET_GPIO_NUM,
  .pin_xclk = XCLK_GPIO_NUM, 
  .pin_sscb_sda = SIOD_GPIO_NUM,  
  .pin_sscb_scl = SIOC_GPIO_NUM,
     
  .pin_d7 = Y9_GPIO_NUM,
  .pin_d6 = Y8_GPIO_NUM,
  .pin_d5 = Y7_GPIO_NUM, 
  .pin_d4 = Y6_GPIO_NUM,
  .pin_d3 = Y5_GPIO_NUM,
  .pin_d2 = Y4_GPIO_NUM,  
  .pin_d1 = Y3_GPIO_NUM,
  .pin_d0 = Y2_GPIO_NUM,
  .pin_vsync = VSYNC_GPIO_NUM,
  .pin_href = HREF_GPIO_NUM,
  .pin_pclk = PCLK_GPIO_NUM,

  .xclk_freq_hz = 20000000,
  .ledc_timer = LEDC_TIMER_0,
  .ledc_channel = LEDC_CHANNEL_0,
  
  .pixel_format = PIXFORMAT_GRAYSCALE,
  .frame_size = FRAMESIZE_QVGA,
  .jpeg_quality = 12,
  .fb_count = 1,
};

byte x,y;
uint8_t oldpixel, newpixel;
int quanterror;

esp_err_t camera_init(){
    //initialize the camera
    esp_err_t err = esp_camera_init(&camera_config);
    if (err != ESP_OK) {
        Serial.print("Camera Init Failed");
        return err;
    }
    sensor_t * s = esp_camera_sensor_get();
    //initial sensors are flipped vertically and colors are a bit saturated
    if (s->id.PID == OV2640_PID) {
        s->set_vflip(s, 1);//flip it back
        s->set_brightness(s, 1);//up the blightness just a bit
        s->set_contrast(s, 1);
    }
  
    Serial.print("Camera Init OK");
    return ESP_OK;
}

void my_camera_show(void)
{
    camera_fb_t *fb = esp_camera_fb_get();
    int i=0;
    for(y = 0; y <SCREEN_HEIGHT; y ++)
    {
      for(x = 0; x <SCREEN_WIDTH; x ++)
      {
        oldpixel = fb-> buf [i]; //保持原始的灰度值
        newpixel =(255 *(oldpixel >> 7)); //门槛值128
        fb-> buf [i] = newpixel; //凸轮缓冲区现在是单声道,0或255
    
        // floyd-steignburg抖动:
        quanterror = oldpixel  -  newpixel; //像素之间的误差
    
        //将此错误分发给相邻像素:
    
       //右
          if(x <SCREEN_WIDTH-1)//边界检查...
          {
    
            fb-> buf [(x + 1)+(y * SCREEN_WIDTH)] +=((quanterror * 7)>> 4);
          }
    
          // 左下
          if((x> 1)&&(y <SCREEN_HEIGHT-1))//边界检查...
          {
            fb-> buf [(x-1)+((y + 1)* SCREEN_WIDTH)] ==((quanterror * 3)>> 4); 
          }
    
          //下
          if(y <63)//边界检查...
          {
             fb-> buf [(x)+((y + 1)* SCREEN_WIDTH)] ==((quanterror * 5)>> 4);
          }
    
          // 右下
          if((x <SCREEN_WIDTH-1)&&(y <SCREEN_HEIGHT-1))//边界检查...
          {
             fb-> buf [(x + 1)+((y + 1)* SCREEN_WIDTH)] ==(quanterror >> 4);
          }

        // 画这个像素

        switch(fb->buf[i]%2)
        {
          case 0:
            display.setColor(BLACK);
            break;
          case 1:
            display.setColor(WHITE);
            break;
          case 2:
           display.setColor(INVERSE);
            break;
        }
        display.setPixel(x, y);
        i++;
      }
    }
    display.display();
    esp_camera_fb_return(fb);
}


void setup() {
  Serial.begin(115200);
  display.init();
  camera_init();
  
  Serial.setDebugOutput(true);
  Serial.println();
  Serial.print("sys is 1...");
  Serial.print("sys is running!");
}

void loop() {
   my_camera_show();
}

ERROR:

Arduino: 1.8.16 (Windows 7), Board: "ESP32 Dev Module, Disabled, Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS), 240MHz (WiFi/BT), QIO, 80MHz, 4MB (32Mb), 921600, Core 1, Core 1, None"

ESP32CAM_OLED_D:13:1: error: 'SSD1306' does not name a type; did you mean 'SSD1306_RECT'?

 SSD1306 display(0x3c, 15, 14);  // M

 ^~~~~~~

 SSD1306_RECT

C:\Users\HUA.DELLV-PC\Documents\Arduino\ESP32CAM_OLED_D\ESP32CAM_OLED_D.ino: In function 'void my_camera_show()':

ESP32CAM_OLED_D:139:13: error: 'display' was not declared in this scope

             display.setColor(BLACK);

             ^~~~~~~

C:\Users\HUA.DELLV-PC\Documents\Arduino\ESP32CAM_OLED_D\ESP32CAM_OLED_D.ino:139:13: note: suggested alternative: 'delay'

             display.setColor(BLACK);

             ^~~~~~~

             delay

ESP32CAM_OLED_D:139:30: error: 'BLACK' was not declared in this scope

             display.setColor(BLACK);

                              ^~~~~

ESP32CAM_OLED_D:142:30: error: 'WHITE' was not declared in this scope

             display.setColor(WHITE);

                              ^~~~~

C:\Users\HUA.DELLV-PC\Documents\Arduino\ESP32CAM_OLED_D\ESP32CAM_OLED_D.ino:142:30: note: suggested alternative: 'SPRITE'

             display.setColor(WHITE);

                              ^~~~~

                              SPRITE

ESP32CAM_OLED_D:145:29: error: 'INVERSE' was not declared in this scope

            display.setColor(INVERSE);

                             ^~~~~~~

ESP32CAM_OLED_D:148:9: error: 'display' was not declared in this scope

         display.setPixel(x, y);

         ^~~~~~~

C:\Users\HUA.DELLV-PC\Documents\Arduino\ESP32CAM_OLED_D\ESP32CAM_OLED_D.ino:148:9: note: suggested alternative: 'delay'

         display.setPixel(x, y);

         ^~~~~~~

         delay

ESP32CAM_OLED_D:152:5: error: 'display' was not declared in this scope

     display.display();

     ^~~~~~~

C:\Users\HUA.DELLV-PC\Documents\Arduino\ESP32CAM_OLED_D\ESP32CAM_OLED_D.ino:152:5: note: suggested alternative: 'delay'

     display.display();

     ^~~~~~~

     delay

C:\Users\HUA.DELLV-PC\Documents\Arduino\ESP32CAM_OLED_D\ESP32CAM_OLED_D.ino: In function 'void setup()':

ESP32CAM_OLED_D:159:3: error: 'display' was not declared in this scope

   display.init();

   ^~~~~~~

C:\Users\HUA.DELLV-PC\Documents\Arduino\ESP32CAM_OLED_D\ESP32CAM_OLED_D.ino:159:3: note: suggested alternative: 'delay'

   display.init();

   ^~~~~~~

   delay

exit status 1

'SSD1306' does not name a type; did you mean 'SSD1306_RECT'?



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

Seems you are using lexus2k's library, but with the initialization from another library

1 Like

thanks.
I'm not sure, changed quite few of libraries for testing.

1 Like

not an expert on this environment
Such an error is not related to a "library" as a LIB file (with code). It is already an issue that a header file is missing.

The type is unknown (or it is not a type):

  • it means: the type name is wrong (see below)
  • or a header file #include is missing (to resolve this type)

When I see this (as source code, without any clue):

SSD1306 display(0x3c, 15, 14);  // M

this "SSD1306" does not look like a type name to me. It looks more like: it is already an instance and an object (of a type), e.g. for a device on the board, already a variable.

Often, type names have something like *t _t, t in name (but just a convention). What should this "SSD1306" be? It looks more like an existing driver, an object (which cannot be used as a type name).

Some of the following errors come just because of the first error. Fix the first error first.
But when 'BLACK' is not defined - it sounds more like an #include of a header file needed is missing.

If you mean by "library" also all the header files - maybe, when you just copy a new version, the Include Path variable ("-I path") is wrong, the header files now in a different (sub-)directory - a H file not found (even included), still pointing with all the "-I path" to a different repository. Even updating a project library does not exclude to update also your project settings (esp. "-I path", if all library were not overwritten, instead placed in a new directory).

I think:
You had to fix an issue with header files first (what and from where to include, all files found, do they contain all the declarations you need ...).
And check if SSD1306 is really a type (find declaration, is it a class, a type, or already a variable/object? "references" I guess, it is already a variable/object, not a type)

1 Like

Great!
Thank you tjaekel.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.