2

I'm working with a 128x64 Oled display. I have just installed the Adafruit library and I'm running some sample codes. I have not modified the sample code in anyway yet just testing if the oled display is working but I've noticed that the splashscreen logo only shows the top half of the image.

How can I fix this?

Splashscreen

6
  • 1
    What sample code are you running? That looks like the sample code supposes a different display height
    – chrisl
    Commented Feb 9, 2022 at 19:46
  • I'm running the ssd1306_128x64_i2c
    – Emma
    Commented Feb 9, 2022 at 19:50
  • Can you provide a link to it?
    – chrisl
    Commented Feb 9, 2022 at 19:51
  • codebender.cc/example/Adafruit_SSD1306/…
    – Emma
    Commented Feb 9, 2022 at 19:55
  • I added #define SSD1306_LCDHEIGHT 64 before line #53 to remove the compilation error
    – Emma
    Commented Feb 9, 2022 at 19:57

1 Answer 1

3

I'm unable to test this now, but here goes:
Turns out I did have the ability to test it (found an extra display module) and this does indeed explain the problem. The only other change I needed to make to your code in order to replicate the problem was change the display's I2C address to 0x3C. Adafruit GFX Library v1.10.13 and Adafruit SSD1306 version v2.5.1.


From comments on the question:

I added #define SSD1306_LCDHEIGHT 64 before line #53 to remove the compilation error

Yeah, you can't do that. Under the old method of defining the screen dimensions, you are intended to modify the header itself:

// ONE of the following three lines must be #defined:
//#define SSD1306_128_64 ///< DEPRECTAED: old way to specify 128x64 screen
#define SSD1306_128_32 ///< DEPRECATED: old way to specify 128x32 screen
//#define SSD1306_96_16  ///< DEPRECATED: old way to specify 96x16 screen
// This establishes the screen dimensions in old Adafruit_SSD1306 sketches
// (NEW CODE SHOULD IGNORE THIS, USE THE CONSTRUCTORS THAT ACCEPT WIDTH
// AND HEIGHT ARGUMENTS).

You can see by default it is using a screen with dimensions 128x32. Later in the header this is used to set SSD1306_LCDHEIGHT to 32 in the header.

#if defined SSD1306_128_32
#define SSD1306_LCDWIDTH 128 ///< DEPRECATED: width w/SSD1306_128_32 defined
#define SSD1306_LCDHEIGHT 32 ///< DEPRECATED: height w/SSD1306_128_32 defined
#endif

What you have done in your code is redefine SSD1306_LCDHEIGHT to 64 from the point where you issued the #define downward, which only affects the code compiled in your sketch.

Meanwhile, over in Adafruit_SSD1306.cpp, SSD1306_LCDHEIGHT is still 32, because this file is compiled independently of your .ino and is unaware of your own re#define. In other words, part of the code you've put into your Arduino thinks it has 32 lines and part of it thinks it has 64 lines.


So, the solution would be get rid of the #define that you inserted into the sketch and to modify header to read:

#define SSD1306_128_64 ///< DEPRECTAED: old way to specify 128x64 screen
//#define SSD1306_128_32 ///< DEPRECATED: old way to specify 128x32 screen
//#define SSD1306_96_16  ///< DEPRECATED: old way to specify 96x16 screen

Or to use the new method of supplying the dimensions by way of the constructor as is done in newer examples:

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
/// ...
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

The Adafruit SSD1306 version v2.5.1's ssd1306_128x64_i2c.ino example that uses this newer method of passing screen dimensions into the Adafruit_SSD1306 constructor and compiled and ran without modification in testing here.

2
  • I have edited the header file and it fixes the problem, thank you. One question though, do I need to use 0x3D as the address for the oled? I used 0x3C because it does not turn on when I use 0x3D. I just want to know why that happened
    – Emma
    Commented Feb 10, 2022 at 9:30
  • 2
    In short, if it's working you have chosen the correct address. The SSD1306 controller chip has a pile of different pins and transfer modes. In I2C mode one of those pins can be used to configure to chip to respond to either 0x3C or 0x3D, such that two of those displays could coexist on the same I2C bus with no other changes. For your display, the choice of I2C interface and 0x3C address has been made for you by the PCB design. I believe the 0x3C/0x3D hard configuration tends to follow the x32/x64 display type, but that nothing guarantees that.
    – timemage
    Commented Feb 10, 2022 at 12:02

Your Answer

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

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