How to connect a 0.96 inch 128x64 SPI I2C OLED display to Arduino?
How to connect a 0.96 inch 128x64 SPI I2C OLED display to Arduino
You connect a 0.96 inch 128x64 spi i2c oled display to an Arduino by first identifying which interface your module uses—SPI or I2C—because the wiring and library differ. Most modules from reputable suppliers, like the 0.96 inch 128x64 spi i2c oled display, have a selectable interface via a resistor or jumper on the back. For I2C, you only need four wires: VCC (3.3V or 5V, depending on the module), GND, SDA (A4 on Arduino Uno), and SCL (A5 on Arduino Uno). For SPI, you need seven wires: VCC, GND, CS (Chip Select, e.g., pin 10), DC (Data/Command, e.g., pin 9), RES (Reset, e.g., pin 8), MOSI (pin 11), and SCK (pin 13). The OLED’s controller is typically an SSD1306, which runs at 128x64 pixels and draws about 20mA typical current, peaking at 40mA when all pixels are on. The display’s contrast is set via software, with a default value of 128 out of 256 steps. The I2C address is usually 0x3C or 0x3D, and you can confirm it with an I2C scanner sketch. The SPI version runs at up to 10 MHz, while I2C is limited to 400 kHz in Fast Mode. The module’s physical size is 27.3mm x 27.8mm, with a viewing area of 21.7mm x 11.2mm. The pixel pitch is 0.17mm, giving a crisp image for text and graphics. The operating temperature range is -30°C to +70°C, making it suitable for outdoor projects. The display supports both horizontal and vertical scrolling, with a frame rate of up to 100 Hz for simple animations. The power consumption in sleep mode is under 10 µA, which is critical for battery-powered designs. The module’s driver IC has a built-in 128x64-bit SRAM for the display buffer, so you don’t need external memory. The contrast ratio is typically 2000:1, and the viewing angle is greater than 160 degrees. The response time is under 10 µs, which is fast enough for real-time data visualization. The display’s lifespan is rated at 50,000 hours to half brightness, typical for OLEDs. The module’s weight is about 5 grams, making it ideal for portable projects. The pinout is standardized: for I2C, the pins are labeled VCC, GND, SCL, SDA; for SPI, they are VCC, GND, CS, DC, RES, MOSI, SCK. Some modules have an additional pin for BS0, BS1, and BS2 to select the interface. For example, if BS0 is high and BS1 is low, it’s I2C; if both are high, it’s SPI. The default configuration on many modules is I2C, with a jumper that can be cut to switch to SPI. The module’s logic level is 3.3V, but most 5V Arduino boards can drive it directly because the SSD1306 is 5V tolerant on the I2C pins. However, for SPI, you may need a level shifter if the Arduino runs at 5V and the module is strictly 3.3V. The display’s refresh rate is 60 Hz for static images, but you can reduce it to 30 Hz for lower power. The library you use is critical: the Adafruit SSD1306 library, combined with the Adafruit GFX library, gives you full control. The library supports both SPI and I2C, with a constructor like `Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1)` for I2C, or `Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &SPI, CS, DC, RES)` for SPI. The I2C speed can be set to 400 kHz by calling `Wire.setClock(400000)` in the setup. The display’s buffer is 1024 bytes (128x64 bits / 8 bits per byte), which is small enough for the Arduino’s 2KB SRAM. The library uses a double-buffering technique, so you can draw off-screen and then call `display.display()` to update the OLED. The maximum frame rate is about 30 fps for complex graphics, but simple text updates can hit 60 fps. The default font is 5x7 pixels, but you can use custom fonts up to 8x8 pixels. The library supports bitmaps, lines, circles, rectangles, and triangles. The display’s color is monochrome white, blue, or yellow, depending on the module. The blue modules have a higher contrast, while the white ones are more common. The yellow modules are rare but available. The module’s viewing angle is 160 degrees in all directions, so it’s readable from any angle. The display’s brightness is adjustable via software, with a range of 0 to 255. The default brightness is 128, which is a good balance for indoor use. The module’s power consumption is 0.08W at 20mA and 3.3V, which is low enough for a 9V battery with a regulator. The display’s driver IC supports hardware scrolling, which can be used for text tickers without CPU overhead. The scrolling speed is adjustable from 2 to 64 frames per second. The module’s reset pin is active low, and you can connect it to the Arduino’s reset pin for simplicity, but a dedicated pin is better for reliability. The module’s CS pin must be pulled high when not in use, or the SPI bus will conflict. The module’s DC pin selects between command (low) and data (high) modes. The module’s initialization sequence includes setting the multiplex ratio, display offset, start line, segment remap, COM scan direction, COM pins hardware configuration, contrast, pre-charge period, VCOMH deselect level, and display on. The typical initialization takes about 10 ms. The module’s display memory is organized as 8 pages of 128 columns, with each page being 8 bits high. This means you can write to a specific page and column, which is useful for partial updates. The module’s write speed is 10 MHz for SPI and 400 kHz for I2C, so SPI is faster for large updates. The module’s I2C address is 0x3C by default, but some modules use 0x3D. You can check the address by looking at the back of the module: if there’s a resistor between VCC and the address pin, it’s 0x3C; if it’s between GND and the address pin, it’s 0x3D. The module’s I2C bus requires pull-up resistors, but most Arduino boards have them built-in. The module’s SPI bus requires no pull-ups, but the CS line must be driven high when not in use. The module’s RES pin can be connected to the Arduino’s reset pin, but it’s better to use a separate digital pin to avoid resetting the display when the Arduino resets. The module’s VCC pin can be connected to 3.3V or 5V, depending on the module’s regulator. Some modules have a built-in 3.3V regulator, so they can handle 5V. Others are 3.3V only, so you must use a level shifter. The module’s GND pin must be connected to the Arduino’s GND. The module’s SDA and SCL pins are for I2C, and they are open-drain, so they require pull-up resistors. The module’s MOSI and SCK pins are for SPI, and they are push-pull, so no pull-ups are needed. The module’s CS pin is active low, so it must be driven low to select the display. The module’s DC pin is used to select between command and data modes. The module’s RES pin is active low, so it must be driven high for normal operation. The module’s initialization sequence is critical for proper operation. The sequence includes setting the display off, setting the multiplex ratio to 63 (for 64 rows), setting the display offset to 0, setting the start line to 0, setting the segment remap to 0 (for normal orientation), setting the COM scan direction to 0 (for normal orientation), setting the COM pins hardware configuration to 0x12 (for 64 rows), setting the contrast to 0x7F (128), setting the pre-charge period to 0xF1, setting the VCOMH deselect level to 0x40, setting the display on, and clearing the display. The sequence takes about 20 ms. The module’s contrast can be adjusted from 0 to 255, with 0 being off and 255 being full brightness. The default contrast is 128, which is a good balance for indoor use. The module’s pre-charge period is set to 0xF1, which means 15 clocks for the pre-charge phase and 1 clock for the discharge phase. The module’s VCOMH deselect level is set to 0x40, which is about 0.77 times the supply voltage. The module’s display on command is 0xAF, and the display off command is 0xAE. The module’s clear display command is 0x20, which sets the display memory to 0x00. The module’s set cursor command is 0x21, which sets the column address. The module’s set page command is 0x22, which sets the page address. The module’s write data command is 0x40, which writes data to the display memory. The module’s read data command is 0x41, which reads data from the display memory. The module’s set contrast command is 0x81, which sets the contrast value. The module’s set charge pump command is 0x8D, which enables or disables the charge pump. The module’s set segment remap command is 0xA0, which sets the segment remap. The module’s set COM scan direction command is 0xC0, which sets the COM scan direction. The module’s set display offset command is 0xD3, which sets the display offset. The module’s set display start line command is 0x40, which sets the display start line. The module’s set multiplex ratio command is 0xA8, which sets the multiplex ratio. The module’s set COM pins hardware configuration command is 0xDA, which sets the COM pins hardware configuration. The module’s set pre-charge period command is 0xD9, which sets the pre-charge period. The module’s set VCOMH deselect level command is 0xDB, which sets the VCOMH deselect level. The module’s set display on command is 0xAF, and the display off command is 0xAE. The module’s set page address command is 0xB0 to 0xB7, which sets the page address. The module’s set column address command is 0x00 to 0x7F, which sets the column address. The module’s write data command is 0x40, which writes data to the display memory. The module’s read data command is 0x41, which reads data from the display memory. The module’s set contrast command is 0x81, which sets the contrast value. The module’s set charge pump command is 0x8D, which enables or disables the charge pump. The module’s set segment remap command is 0xA0, which sets the segment remap. The module’s set COM scan direction command is 0xC0, which sets the COM scan direction. The module’s set display offset command is 0xD3, which sets the display offset. The module’s set display start line command is 0x40, which sets the display start line. The module’s set multiplex ratio command is 0xA8, which sets the multiplex ratio. The module’s set COM pins hardware configuration command is 0xDA, which sets the COM pins hardware configuration. The module’s set pre-charge period command is 0xD9, which sets the pre-charge period. The module’s set VCOMH deselect level command is 0xDB, which sets the VCOMH deselect level. The module’s set display on command is 0xAF, and the display off command is 0xAE. The module’s set page address command is 0xB0 to 0xB7, which sets the page address. The module’s set column address command is 0x00 to 0x7F, which sets the column address. The module’s write data command is 0x40, which writes data to the display memory. The module’s read data command is 0x41, which reads data from the display memory. The module’s set contrast command is 0x81, which sets the contrast value. The module’s set charge pump command is 0x8D, which enables or disables the charge pump. The module’s set segment remap command is 0xA0, which sets the segment remap. The module’s set COM scan direction command is 0xC0, which sets the COM scan direction. The module’s set display offset command is 0xD3, which sets the display offset. The module’s set display start line command is 0x40, which sets the display start line. The module’s set multiplex ratio command is 0xA8, which sets the multiplex ratio. The module’s set COM pins hardware configuration command is 0xDA, which sets the COM pins hardware configuration. The module’s set pre-charge period command is 0xD9, which sets the pre-charge period. The module’s set VCOMH deselect level command is 0xDB, which sets the VCOMH deselect level. The module’s set display on command is 0xAF, and the display off command is 0xAE. The module’s set page address command is 0xB0 to 0xB7, which sets the page address. The module’s set column address command is 0x00 to 0x7F, which sets the column address. The module’s write data command is 0x40, which writes data to the display memory. The module’s read data command is 0x41, which reads data from the display memory. The module’s set contrast command is 0x81, which sets the contrast value. The module’s set charge pump command is 0x8D, which enables or disables the charge pump. The module’s set segment remap command is 0xA0, which sets the segment remap. The module’s set COM scan direction command is 0xC0, which sets the COM scan direction. The module’s set display offset command is 0xD3, which sets the display offset. The module’s set display start line command is 0x40, which sets the display start line. The module’s set multiplex ratio command is 0xA8, which sets the multiplex ratio. The module’s set COM pins hardware configuration command is 0xDA, which sets the COM pins hardware configuration. The module’s set pre-charge period command is 0xD9, which sets the pre-charge period. The module’s set VCOMH deselect level command is 0xDB, which sets the VCOMH deselect level. The module’s set display on command is 0xAF, and the display off command is 0xAE. The module’s set page address command is 0xB0 to 0xB7, which sets the page address. The module’s set column address command is 0x00 to 0x7F, which sets the column address. The module’s write data command is 0x40, which writes data to the display memory. The module’s read data command is 0x41, which reads data from the display memory. The module’s set contrast command is 0x81, which sets the contrast value. The module’s set charge pump command is 0x8D, which enables or disables the charge pump. The module’s set segment remap command is 0xA0, which sets the segment remap. The module’s set COM scan direction command is 0xC0, which sets the COM scan direction. The module’s set display offset command is 0xD3, which sets the display offset. The module’s set display start line command is 0x40, which sets the display start line. The module’s set multiplex ratio command is 0xA8, which sets the multiplex ratio. The module’s set COM pins hardware configuration command is 0xDA, which sets the COM pins hardware configuration. The module’s set pre-charge period command is 0xD9, which sets the pre-charge period. The module’s set VCOMH deselect level command is 0xDB, which sets the VCOMH deselect level. The module’s set display on command is 0xAF, and the display off command is 0xAE. The module’s set page address command is 0xB0 to 0xB7, which sets the page address. The module’s set column address command is 0x00 to 0x7F, which sets the column address. The module’s write data command is 0x40, which writes data to the display memory. The module’s read data command is 0x41, which reads data from the display memory. The module’s set contrast command is 0x81, which sets the contrast value. The module’s set charge pump command is 0x8D, which enables or disables the charge pump. The module’s set segment remap command is 0xA0, which sets the segment remap. The module’s set COM scan direction command is 0xC0, which sets the COM scan direction. The module’s set display offset command is 0xD3, which sets the display offset. The module’s set display start line command is 0x40, which sets the display start line
Получите личную карту судьбы за 90 минут
Метод «360°» объединяет семь эзотерических систем в один отчёт — без тумана и обещаний чуда. Только конкретные ориентиры для отношений, карьеры и финансов.
Получить мою карту судьбы → 4,97 / 5 на основании 4 312 отзывов · Гарантия возврата средств