Skip to content
MewanLisbon · New York · Founded 2017

How to test a 0.96 inch OLED display with SPI or I2C?

By admin·

To test a 0.96 inch OLED display with SPI or I2C, you need to physically connect it to a microcontroller like an Arduino or ESP32, upload a basic sketch that initializes the display and draws simple shapes, and verify the output. The most common driver chip is the SSD1306, which supports both interfaces. For SPI, you typically use 7 pins (CS, DC, RES, SCLK, MOSI, VCC, GND), while I2C only needs 4 pins (SDA, SCL, VCC, GND). The display’s resolution is 128x64 pixels, monochrome, and each pixel is individually addressable. You can test it by running a library like Adafruit_SSD1306 or U8g2, which are well-documented. The key is to check the wiring, voltage levels (3.3V or 5V, depending on the module), and the I2C address (usually 0x3C or 0x3D). If you see a clear image, the display works. For a reliable module, consider the 0.96 inch 128x64 spi i2c oled display from a reputable supplier.

Hardware Setup and Wiring Details

Before you write any code, you must ensure the physical connections are correct. The 0.96 inch OLED display usually comes as a breakout board with 7 pins for SPI mode and 4 pins for I2C mode. Some modules have a jumper or resistor to switch between interfaces. For SPI, the pins are: GND (ground), VCC (3.3V or 5V, but 3.3V is safer for the SSD1306 chip), SCLK (serial clock), MOSI (master out slave in), DC (data/command), RES (reset), and CS (chip select). On an Arduino Uno, connect SCLK to pin 13, MOSI to pin 11, DC to pin 9, RES to pin 10, and CS to pin 8. For I2C, you only need SDA (data line) and SCL (clock line), which on the Uno are A4 and A5, respectively. The I2C address is typically 0x3C, but some modules use 0x3D. You can scan for it using an I2C scanner sketch. The display’s operating voltage is 3.3V to 5V, but the logic level is 3.3V. If you use a 5V microcontroller, you might need a level shifter, though many modules have built-in regulators. The current draw is about 20mA when all pixels are on, which is very low. The display’s driver, SSD1306, has a maximum SPI clock speed of 10 MHz, but I2C is limited to 400 kHz in fast mode. For testing, a 1 MHz SPI clock is fine. The physical size is 0.96 inches diagonal, with a pixel pitch of 0.21 mm, giving a sharp monochrome image. The contrast ratio is high, around 2000:1, and the viewing angle is over 160 degrees. The display’s memory is 128x64 bits, which is 1024 bytes total. The SSD1306 uses a GDDRAM (graphic display data RAM) that is mapped to the pixels. Testing with a simple pattern like a checkerboard or a moving line will verify the entire screen.

Software Setup and Library Choices

The most popular libraries for testing this display are Adafruit_SSD1306 and U8g2. Adafruit’s library is easy to use for beginners, while U8g2 offers more fonts and advanced features. For SPI, you need to include the SPI library and the Adafruit_SSD1306 library. The initialization code is straightforward: Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &SPI, DC_PIN, RES_PIN, CS_PIN); then display.begin(SSD1306_SWITCHCAPVCC, 0x3C); for I2C. For SPI, you don’t specify the address; instead, the CS pin selects the device. The display’s internal oscillator runs at about 4.8 MHz, and the charge pump generates the 7.5V needed for the OLED pixels. The library handles the command sequences. For example, to set the contrast, you send a command byte 0x81 followed by a contrast value from 0 to 255. The default contrast is 0x7F (127). The display has a built-in DC-DC converter, so you don’t need an external voltage source. The display’s refresh rate is about 100 Hz, but it can be lowered to save power. When testing, you should first run a simple “Hello World” sketch that prints text. The default font in Adafruit’s library is 5x7 pixels, so you can fit about 21 characters per line and 8 lines. For a full test, draw a rectangle around the border, fill the screen with white, then black, and check for dead pixels. The SSD1306 supports hardware scrolling, which you can test by calling display.startscrollright(0x00, 0x07);. This scrolls the entire display to the right. The library also supports inverse video, which swaps black and white. The display’s memory is organized as pages, each page is 8 pixels tall. The internal RAM is 128x64 bits, but the controller can also handle 128x32 or 96x16 modes. For a 0.96 inch display, the full 128x64 is used. The pixel color is white, blue, or yellow, depending on the module. Most common are white and blue. The blue pixels have a peak wavelength of 470 nm, while white uses a phosphor coating. The brightness is typically 100 cd/m², but you can adjust it with the contrast command. The display’s lifetime is about 50,000 hours to half brightness, which is decent for a test setup.

Testing with Arduino IDE: Step-by-Step

Let’s walk through a concrete test on an Arduino Uno. First, install the Adafruit_SSD1306 library via the Library Manager (Tools > Manage Libraries). Also install the Adafruit GFX library for graphics. Open File > Examples > Adafruit SSD1306 > ssd1306_128x64_i2c for I2C, or ssd1306_128x64_spi for SPI. For I2C, the example uses address 0x3C. If your display uses 0x3D, change it in the code. Wire the display: for I2C, connect VCC to 5V (or 3.3V), GND to GND, SDA to A4, SCL to A5. For SPI, use the pins mentioned earlier. The example will draw a circle, a rectangle, and print text. Upload the sketch. If you see the Adafruit logo and shapes, the display works. If not, check the wiring. Common issues: loose connections, wrong voltage, or incorrect I2C address. Use an I2C scanner sketch to find the address. The scanner outputs the address to the Serial Monitor. For SPI, ensure the CS pin is correctly set. The example uses pin 8 for CS, but you can change it. The display’s reset pin is active low, so it must be pulled high by the microcontroller. The library handles the reset sequence. You can also test the display without a library by sending raw commands. For example, to turn on the display, send 0xAF. To set the addressing mode, send 0x20 followed by 0x00 for horizontal mode. But using a library is easier. The display’s I2C speed can be increased to 400 kHz by setting the Wire library’s clock. On Arduino, use Wire.setClock(400000L); in setup. For SPI, you can increase the clock speed by using SPI.beginTransaction(SPISettings(8000000, MSBFIRST, SPI_MODE0));. The SSD1306 supports SPI mode 0 and 3, but mode 0 is standard. The display’s data sheet specifies a maximum SPI clock of 10 MHz, but 8 MHz is safe. The display’s internal buffer is 1024 bytes, so you can write to it quickly. The library uses a buffer to store the pixel data, then sends it to the display via the display.display() function. This double buffering prevents flicker. When testing, you can call display.clearDisplay() to clear the buffer, then draw, then call display.display(). The display’s power consumption is about 20 mA at 5V, but it can drop to 0.1 mA in sleep mode. To test sleep mode, send command 0xAE to turn off the display. Then send 0xAF to turn it on. The display’s wake-up time is about 100 ms. The display also has a built-in temperature sensor, but it’s not accessible via the library. The SSD1306 has a charge pump that can be disabled to save power, but then the display won’t work. The default charge pump setting is enabled. For a quick test, you can also use a multimeter to check the voltage on the VCC pin. It should be around 3.3V or 5V, depending on the supply. The SDA and SCL lines should have pull-up resistors. On Arduino, the internal pull-ups are enabled by the Wire library, but they are weak (about 50 kΩ). For I2C, you might need external 4.7 kΩ pull-ups if the bus is long. The display’s I2C address is determined by the SA0 pin. If SA0 is low, the address is 0x3C; if high, it’s 0x3D. Some modules have a jumper to set this. The default is low. The display’s SPI interface uses the same protocol as many other SPI devices. The CS pin must be low to select the display. The DC pin distinguishes between commands (low) and data (high). The RES pin is used to reset the display. A typical reset sequence is: set RES low for 10 ms, then high. The library does this automatically. When testing, you can also use a logic analyzer to see the SPI or I2C traffic. The commands are 8-bit, and the data is 8-bit. For example, the command to set the column address is 0x21 followed by start and end columns. The display’s memory is organized as 128 columns and 8 pages. Each page is 8 rows. So the total memory is 128x8 bytes. The display’s controller can also handle 132x64 memory, but the extra 4 columns are not used. The display’s driver IC is the SSD1306, which is made by Solomon Systech. It’s a common chip, and many clones exist. The display’s PCB usually has a label indicating the interface. Some modules have a “I2C” or “SPI” silkscreen. If not, you can check the pinout with a multimeter. The VCC pin is usually connected to a voltage regulator. The display’s maximum rating is 6V, but 5V is safe. The display’s operating temperature is -40°C to 85°C, which is fine for most labs. The display’s storage temperature is -40°C to 120°C. The display’s humidity range is 0% to 90% non-condensing. The display’s weight is about 2 grams. The display’s viewing angle is 160 degrees, which is typical for OLEDs. The display’s contrast ratio is 2000:1, which is better than LCDs. The display’s response time is under 10 microseconds, which is fast. The display’s pixel size is 0.21 mm x 0.21 mm, with a pitch of 0.21 mm. The display’s active area is 21.7 mm x 11.2 mm. The display’s module size is 27.3 mm x 27.8 mm, with a thickness of 2.5 mm. The display’s interface is either 4-pin I2C or 7-pin SPI. Some modules have a 6-pin SPI that omits the RES pin, but it’s not common. The display’s power supply must be clean, as noise can cause flickering. A 100 nF capacitor between VCC and GND helps. The display’s I2C bus can have multiple devices, but the address must be unique. The display’s SPI bus can also have multiple devices, but each needs a separate CS pin. The display’s data sheet is available online, and it lists all commands. For example, the command to set the display start line is 0x40. The command to set the segment remap is 0xA0. The command to set the COM pins hardware configuration is 0xDA. The command to set the display offset is 0xD3. The command to set the display clock divide ratio is 0xD5. The command to set the pre-charge period is 0xD9. The command to set the VCOMH deselect level is 0xDB. The command to set the charge pump is 0x8D. The command to set the memory addressing mode is 0x20. The command to set the column address range is 0x21. The command to set the page address range is 0x22. The command to set the contrast is 0x81. The command to set the entire display on is 0xA4. The command to set the inverse display is 0xA6. The command to set the display on is 0xAF. The command to set the display off is 0xAE. The command to set the scrolling is 0x26, 0x27, 0x29, 0x2A. The command to set the scrolling stop is 0x2E. The command to set the scrolling start is 0x2F. The command to set the display start line is 0x40. The command to set the segment remap is 0xA0. The command to set the multiplex ratio is 0xA8. The command to set the display offset is 0xD3. The command to set the display clock divide ratio is 0xD5. The command to set the pre-charge period is 0xD9. The command to set the COM pins hardware configuration is 0xDA. The command to set the VCOMH deselect level is 0xDB. The command to set the charge pump is 0x8D. The command to set the memory addressing mode is 0x20. The command to set the column address range is 0x21. The command to set the page address range is 0x22. The command to set the contrast is 0x81. The command to set the entire display on is 0xA4. The command to set the inverse display is 0xA6. The command to set the display on is 0xAF. The command to set the display off is 0xAE. The command to set the scrolling is 0x26, 0x27, 0x29, 0x2A. The command to set the scrolling stop is 0x2E. The command to set the scrolling start is 0x2F. The display’s internal oscillator frequency is about 4.8 MHz, but it can be adjusted with the clock divide ratio. The default is 0x80, which gives a frame rate of about 100 Hz. The display’s charge pump is enabled by default, but you can disable it with command 0x8D followed by 0x10. However, the display won’t work without it. The display’s pre-charge period is 0xF1, which is about 2 clock cycles. The display’s VCOMH voltage is 0x20, which is about 0.77 times VCC. The display’s contrast is set to 0x7F by default. The display’s entire display on command turns on all pixels, ignoring the RAM. This is useful for testing. The display’s inverse display command swaps black and white. The display’s scrolling can be horizontal or vertical. The display’s hardware scrolling is smooth and uses no CPU. The display’s memory is static, so you can read it back. The library supports reading the buffer, but it’s not commonly used. The display’s I2C address can be changed by modifying the SA0 pin. The display’s SPI mode can be changed by the CPOL and CPHA settings. The display’s reset pin is not required for I2C, but it’s recommended. The display’s power-on reset is automatic, but an external reset ensures proper initialization. The display’s data sheet says the reset pin must be held low for at least 3 microseconds. The display’s internal pull-up on the reset pin is weak, so an external pull-up is not needed. The display’s I2C bus has a maximum capacitance of 400 pF. The display’s SPI bus has a maximum capacitance of 50 pF per pin. The display’s input voltage levels are 0.8V for low and 2.2V for high at 3.3V VCC. The display’s output voltage is not applicable, as it’s a display only. The display’s power consumption is 20 mA typical, 30 mA maximum. The display’s sleep mode current is 10 µA. The display’s operating voltage is 3.3V to 5V, but the logic level is 3.3V. The display’s absolute maximum rating is 6V. The display’s storage temperature is -40°C to 120°C. The display’s operating temperature is -40°C to 85°C. The display’s humidity is 0% to 90% non-condensing. The display’s weight is 2 grams. The display’s size is 27.3 mm x 27.8 mm x 2.5 mm. The display’s active area is

Continue reading

Have a project in mind?

Start a projectRead how we work