Adafruit SSD1306
|
Class that stores state and functions for interacting with SSD1306 OLED displays. More...
#include <Adafruit_SSD1306.h>
Public Member Functions | |
Adafruit_SSD1306 (uint8_t w, uint8_t h, TwoWire *twi=&Wire, int8_t rst_pin=-1, uint32_t clkDuring=400000UL, uint32_t clkAfter=100000UL) | |
Constructor for I2C-interfaced SSD1306 displays. More... | |
Adafruit_SSD1306 (uint8_t w, uint8_t h, int8_t mosi_pin, int8_t sclk_pin, int8_t dc_pin, int8_t rst_pin, int8_t cs_pin) | |
Constructor for SPI SSD1306 displays, using software (bitbang) SPI. More... | |
Adafruit_SSD1306 (uint8_t w, uint8_t h, SPIClass *spi, int8_t dc_pin, int8_t rst_pin, int8_t cs_pin, uint32_t bitrate=8000000UL) | |
Constructor for SPI SSD1306 displays, using native hardware SPI. More... | |
Adafruit_SSD1306 (int8_t mosi_pin, int8_t sclk_pin, int8_t dc_pin, int8_t rst_pin, int8_t cs_pin) | |
DEPRECATED constructor for SPI SSD1306 displays, using software (bitbang) SPI. Provided for older code to maintain compatibility with the current library. Screen size is determined by enabling one of the SSD1306_* size defines in Adafruit_SSD1306.h. New code should NOT use this. More... | |
Adafruit_SSD1306 (int8_t dc_pin, int8_t rst_pin, int8_t cs_pin) | |
DEPRECATED constructor for SPI SSD1306 displays, using native hardware SPI. Provided for older code to maintain compatibility with the current library. Screen size is determined by enabling one of the SSD1306_* size defines in Adafruit_SSD1306.h. New code should NOT use this. Only the primary SPI bus is supported, and bitrate is fixed at 8 MHz. More... | |
Adafruit_SSD1306 (int8_t rst_pin=-1) | |
DEPRECATED constructor for I2C SSD1306 displays. Provided for older code to maintain compatibility with the current library. Screen size is determined by enabling one of the SSD1306_* size defines in Adafruit_SSD1306.h. New code should NOT use this. Only the primary I2C bus is supported. More... | |
~Adafruit_SSD1306 (void) | |
Destructor for Adafruit_SSD1306 object. | |
bool | begin (uint8_t switchvcc=SSD1306_SWITCHCAPVCC, uint8_t i2caddr=0, bool reset=true, bool periphBegin=true) |
Allocate RAM for image buffer, initialize peripherals and pins. More... | |
void | display (void) |
Push data currently in RAM to SSD1306 display. More... | |
void | clearDisplay (void) |
Clear contents of display buffer (set all pixels to off). More... | |
void | invertDisplay (bool i) |
Enable or disable display invert mode (white-on-black vs black-on-white). More... | |
void | dim (bool dim) |
Dim the display. More... | |
void | drawPixel (int16_t x, int16_t y, uint16_t color) |
Set/clear/invert a single pixel. This is also invoked by the Adafruit_GFX library in generating many higher-level graphics primitives. More... | |
virtual void | drawFastHLine (int16_t x, int16_t y, int16_t w, uint16_t color) |
Draw a horizontal line. This is also invoked by the Adafruit_GFX library in generating many higher-level graphics primitives. More... | |
virtual void | drawFastVLine (int16_t x, int16_t y, int16_t h, uint16_t color) |
Draw a vertical line. This is also invoked by the Adafruit_GFX library in generating many higher-level graphics primitives. More... | |
void | startscrollright (uint8_t start, uint8_t stop) |
Activate a right-handed scroll for all or part of the display. More... | |
void | startscrollleft (uint8_t start, uint8_t stop) |
Activate a left-handed scroll for all or part of the display. More... | |
void | startscrolldiagright (uint8_t start, uint8_t stop) |
Activate a diagonal scroll for all or part of the display. More... | |
void | startscrolldiagleft (uint8_t start, uint8_t stop) |
Activate alternate diagonal scroll for all or part of the display. More... | |
void | stopscroll (void) |
Cease a previously-begun scrolling action. More... | |
void | ssd1306_command (uint8_t c) |
Issue a single low-level command directly to the SSD1306 display, bypassing the library. More... | |
bool | getPixel (int16_t x, int16_t y) |
Return color of a single pixel in display buffer. More... | |
uint8_t * | getBuffer (void) |
Get base address of display buffer for direct reading or writing. More... | |
Protected Member Functions | |
void | SPIwrite (uint8_t d) __attribute__((always_inline)) |
Write a single byte to the SPI port. More... | |
void | drawFastHLineInternal (int16_t x, int16_t y, int16_t w, uint16_t color) |
Draw a horizontal line with a width and color. Used by public methods drawFastHLine,drawFastVLine. More... | |
void | drawFastVLineInternal (int16_t x, int16_t y, int16_t h, uint16_t color) |
Draw a vertical line with a width and color. Used by public method drawFastHLine,drawFastVLine. More... | |
void | ssd1306_command1 (uint8_t c) |
Issue single command to SSD1306, using I2C or hard/soft SPI as needed. Because command calls are often grouped, SPI transaction and selection must be started/ended in calling function for efficiency. This is a protected function, not exposed (see ssd1306_command() instead). More... | |
void | ssd1306_commandList (const uint8_t *c, uint8_t n) |
Issue list of commands to SSD1306, same rules as above re: transactions. This is a protected function, not exposed. More... | |
Protected Attributes | |
SPIClass * | spi |
TwoWire * | wire |
uint8_t * | buffer |
int8_t | i2caddr |
I2C address initialized when begin method is called. | |
int8_t | vccstate |
VCC selection, set by begin method. | |
int8_t | page_end |
not used | |
int8_t | mosiPin |
int8_t | clkPin |
(Clock Pin) set when using SPI set during construction. | |
int8_t | dcPin |
(Data Pin) set when using SPI set during construction. | |
int8_t | csPin |
(Chip Select Pin) set when using SPI set during construction. | |
int8_t | rstPin |
Display reset pin assignment. Set during construction. | |
uint8_t | contrast |
normal contrast setting for this device | |
Class that stores state and functions for interacting with SSD1306 OLED displays.
Adafruit_SSD1306::Adafruit_SSD1306 | ( | uint8_t | w, |
uint8_t | h, | ||
TwoWire * | twi = &Wire , |
||
int8_t | rst_pin = -1 , |
||
uint32_t | clkDuring = 400000UL , |
||
uint32_t | clkAfter = 100000UL |
||
) |
Constructor for I2C-interfaced SSD1306 displays.
w | Display width in pixels |
h | Display height in pixels |
twi | Pointer to an existing TwoWire instance (e.g. &Wire, the microcontroller's primary I2C bus). |
rst_pin | Reset pin (using Arduino pin numbering), or -1 if not used (some displays might be wired to share the microcontroller's reset pin). |
clkDuring | Speed (in Hz) for Wire transmissions in SSD1306 library calls. Defaults to 400000 (400 KHz), a known 'safe' value for most microcontrollers, and meets the SSD1306 datasheet spec. Some systems can operate I2C faster (800 KHz for ESP32, 1 MHz for many other 32-bit MCUs), and some (perhaps not all) SSD1306's can work with this – so it's optionally be specified here and is not a default behavior. (Ignored if using pre-1.5.7 Arduino software, which operates I2C at a fixed 100 KHz.) |
clkAfter | Speed (in Hz) for Wire transmissions following SSD1306 library calls. Defaults to 100000 (100 KHz), the default Arduino Wire speed. This is done rather than leaving it at the 'during' speed because other devices on the I2C bus might not be compatible with the faster rate. (Ignored if using pre-1.5.7 Arduino software, which operates I2C at a fixed 100 KHz.) |
Adafruit_SSD1306::Adafruit_SSD1306 | ( | uint8_t | w, |
uint8_t | h, | ||
int8_t | mosi_pin, | ||
int8_t | sclk_pin, | ||
int8_t | dc_pin, | ||
int8_t | rst_pin, | ||
int8_t | cs_pin | ||
) |
Constructor for SPI SSD1306 displays, using software (bitbang) SPI.
w | Display width in pixels |
h | Display height in pixels |
mosi_pin | MOSI (master out, slave in) pin (using Arduino pin numbering). This transfers serial data from microcontroller to display. |
sclk_pin | SCLK (serial clock) pin (using Arduino pin numbering). This clocks each bit from MOSI. |
dc_pin | Data/command pin (using Arduino pin numbering), selects whether display is receiving commands (low) or data (high). |
rst_pin | Reset pin (using Arduino pin numbering), or -1 if not used (some displays might be wired to share the microcontroller's reset pin). |
cs_pin | Chip-select pin (using Arduino pin numbering) for sharing the bus with other devices. Active low. |
Adafruit_SSD1306::Adafruit_SSD1306 | ( | uint8_t | w, |
uint8_t | h, | ||
SPIClass * | spi_ptr, | ||
int8_t | dc_pin, | ||
int8_t | rst_pin, | ||
int8_t | cs_pin, | ||
uint32_t | bitrate = 8000000UL |
||
) |
Constructor for SPI SSD1306 displays, using native hardware SPI.
w | Display width in pixels |
h | Display height in pixels |
spi_ptr | Pointer to an existing SPIClass instance (e.g. &SPI, the microcontroller's primary SPI bus). |
dc_pin | Data/command pin (using Arduino pin numbering), selects whether display is receiving commands (low) or data (high). |
rst_pin | Reset pin (using Arduino pin numbering), or -1 if not used (some displays might be wired to share the microcontroller's reset pin). |
cs_pin | Chip-select pin (using Arduino pin numbering) for sharing the bus with other devices. Active low. |
bitrate | SPI clock rate for transfers to this display. Default if unspecified is 8000000UL (8 MHz). |
Adafruit_SSD1306::Adafruit_SSD1306 | ( | int8_t | mosi_pin, |
int8_t | sclk_pin, | ||
int8_t | dc_pin, | ||
int8_t | rst_pin, | ||
int8_t | cs_pin | ||
) |
DEPRECATED constructor for SPI SSD1306 displays, using software (bitbang) SPI. Provided for older code to maintain compatibility with the current library. Screen size is determined by enabling one of the SSD1306_* size defines in Adafruit_SSD1306.h. New code should NOT use this.
mosi_pin | MOSI (master out, slave in) pin (using Arduino pin numbering). This transfers serial data from microcontroller to display. |
sclk_pin | SCLK (serial clock) pin (using Arduino pin numbering). This clocks each bit from MOSI. |
dc_pin | Data/command pin (using Arduino pin numbering), selects whether display is receiving commands (low) or data (high). |
rst_pin | Reset pin (using Arduino pin numbering), or -1 if not used (some displays might be wired to share the microcontroller's reset pin). |
cs_pin | Chip-select pin (using Arduino pin numbering) for sharing the bus with other devices. Active low. |
Adafruit_SSD1306::Adafruit_SSD1306 | ( | int8_t | dc_pin, |
int8_t | rst_pin, | ||
int8_t | cs_pin | ||
) |
DEPRECATED constructor for SPI SSD1306 displays, using native hardware SPI. Provided for older code to maintain compatibility with the current library. Screen size is determined by enabling one of the SSD1306_* size defines in Adafruit_SSD1306.h. New code should NOT use this. Only the primary SPI bus is supported, and bitrate is fixed at 8 MHz.
dc_pin | Data/command pin (using Arduino pin numbering), selects whether display is receiving commands (low) or data (high). |
rst_pin | Reset pin (using Arduino pin numbering), or -1 if not used (some displays might be wired to share the microcontroller's reset pin). |
cs_pin | Chip-select pin (using Arduino pin numbering) for sharing the bus with other devices. Active low. |
Adafruit_SSD1306::Adafruit_SSD1306 | ( | int8_t | rst_pin = -1 | ) |
DEPRECATED constructor for I2C SSD1306 displays. Provided for older code to maintain compatibility with the current library. Screen size is determined by enabling one of the SSD1306_* size defines in Adafruit_SSD1306.h. New code should NOT use this. Only the primary I2C bus is supported.
rst_pin | Reset pin (using Arduino pin numbering), or -1 if not used (some displays might be wired to share the microcontroller's reset pin). |
bool Adafruit_SSD1306::begin | ( | uint8_t | vcs = SSD1306_SWITCHCAPVCC , |
uint8_t | addr = 0 , |
||
bool | reset = true , |
||
bool | periphBegin = true |
||
) |
Allocate RAM for image buffer, initialize peripherals and pins.
vcs | VCC selection. Pass SSD1306_SWITCHCAPVCC to generate the display voltage (step up) from the 3.3V source, or SSD1306_EXTERNALVCC otherwise. Most situations with Adafruit SSD1306 breakouts will want SSD1306_SWITCHCAPVCC. |
addr | I2C address of corresponding SSD1306 display (or pass 0 to use default of 0x3C for 128x32 display, 0x3D for all others). SPI displays (hardware or software) do not use addresses, but this argument is still required (pass 0 or any value really, it will simply be ignored). Default if unspecified is 0. |
reset | If true, and if the reset pin passed to the constructor is valid, a hard reset will be performed before initializing the display. If using multiple SSD1306 displays on the same bus, and if they all share the same reset pin, you should only pass true on the first display being initialized, false on all others, else the already-initialized displays would be reset. Default if unspecified is true. |
periphBegin | If true, and if a hardware peripheral is being used (I2C or SPI, but not software SPI), call that peripheral's begin() function, else (false) it has already been done in one's sketch code. Cases where false might be used include multiple displays or other devices sharing a common bus, or situations on some platforms where a nonstandard begin() function is available (e.g. a TwoWire interface on non-default pins, as can be done on the ESP8266 and perhaps others). |
void Adafruit_SSD1306::display | ( | void | ) |
Push data currently in RAM to SSD1306 display.
void Adafruit_SSD1306::clearDisplay | ( | void | ) |
Clear contents of display buffer (set all pixels to off).
void Adafruit_SSD1306::invertDisplay | ( | bool | i | ) |
Enable or disable display invert mode (white-on-black vs black-on-white).
i | If true, switch to invert mode (black-on-white), else normal mode (white-on-black). |
void Adafruit_SSD1306::dim | ( | bool | dim | ) |
Dim the display.
dim | true to enable lower brightness mode, false for full brightness. |
void Adafruit_SSD1306::drawPixel | ( | int16_t | x, |
int16_t | y, | ||
uint16_t | color | ||
) |
Set/clear/invert a single pixel. This is also invoked by the Adafruit_GFX library in generating many higher-level graphics primitives.
x | Column of display – 0 at left to (screen width - 1) at right. |
y | Row of display – 0 at top to (screen height -1) at bottom. |
color | Pixel color, one of: SSD1306_BLACK, SSD1306_WHITE or SSD1306_INVERSE. |
|
virtual |
Draw a horizontal line. This is also invoked by the Adafruit_GFX library in generating many higher-level graphics primitives.
x | Leftmost column – 0 at left to (screen width - 1) at right. |
y | Row of display – 0 at top to (screen height -1) at bottom. |
w | Width of line, in pixels. |
color | Line color, one of: SSD1306_BLACK, SSD1306_WHITE or SSD1306_INVERSE. |
|
virtual |
Draw a vertical line. This is also invoked by the Adafruit_GFX library in generating many higher-level graphics primitives.
x | Column of display – 0 at left to (screen width -1) at right. |
y | Topmost row – 0 at top to (screen height - 1) at bottom. |
h | Height of line, in pixels. |
color | Line color, one of: SSD1306_BLACK, SSD1306_WHITE or SSD1306_INVERSE. |
void Adafruit_SSD1306::startscrollright | ( | uint8_t | start, |
uint8_t | stop | ||
) |
Activate a right-handed scroll for all or part of the display.
start | First row. |
stop | Last row. |
void Adafruit_SSD1306::startscrollleft | ( | uint8_t | start, |
uint8_t | stop | ||
) |
Activate a left-handed scroll for all or part of the display.
start | First row. |
stop | Last row. |
void Adafruit_SSD1306::startscrolldiagright | ( | uint8_t | start, |
uint8_t | stop | ||
) |
Activate a diagonal scroll for all or part of the display.
start | First row. |
stop | Last row. |
void Adafruit_SSD1306::startscrolldiagleft | ( | uint8_t | start, |
uint8_t | stop | ||
) |
Activate alternate diagonal scroll for all or part of the display.
start | First row. |
stop | Last row. |
void Adafruit_SSD1306::stopscroll | ( | void | ) |
Cease a previously-begun scrolling action.
void Adafruit_SSD1306::ssd1306_command | ( | uint8_t | c | ) |
Issue a single low-level command directly to the SSD1306 display, bypassing the library.
c | Command to issue (0x00 to 0xFF, see datasheet). |
bool Adafruit_SSD1306::getPixel | ( | int16_t | x, |
int16_t | y | ||
) |
Return color of a single pixel in display buffer.
x | Column of display – 0 at left to (screen width - 1) at right. |
y | Row of display – 0 at top to (screen height -1) at bottom. |
uint8_t * Adafruit_SSD1306::getBuffer | ( | void | ) |
Get base address of display buffer for direct reading or writing.
|
inlineprotected |
Write a single byte to the SPI port.
d | Data byte to be written. |
|
protected |
Draw a horizontal line with a width and color. Used by public methods drawFastHLine,drawFastVLine.
x | Leftmost column – 0 at left to (screen width - 1) at right. |
y | Row of display – 0 at top to (screen height -1) at bottom. |
w | Width of line, in pixels. |
color | Line color, one of: SSD1306_BLACK, SSD1306_WHITE or SSD1306_INVERSE. |
|
protected |
Draw a vertical line with a width and color. Used by public method drawFastHLine,drawFastVLine.
x | Leftmost column – 0 at left to (screen width - 1) at right. |
__y | Row of display – 0 at top to (screen height -1) at bottom. |
__h | height of the line in pixels |
color | Line color, one of: SSD1306_BLACK, SSD1306_WHITE or SSD1306_INVERSE. |
|
protected |
Issue single command to SSD1306, using I2C or hard/soft SPI as needed. Because command calls are often grouped, SPI transaction and selection must be started/ended in calling function for efficiency. This is a protected function, not exposed (see ssd1306_command() instead).
c | the command character to send to the display. Refer to ssd1306 data sheet for commands |
|
protected |
Issue list of commands to SSD1306, same rules as above re: transactions. This is a protected function, not exposed.
c | pointer to list of commands |
n | number of commands in the list |
|
protected |
Initialized during construction when using SPI. See SPI.cpp, SPI.h
|
protected |
Initialized during construction when using I2C. See Wire.cpp, Wire.h
|
protected |
Buffer data used for display buffer. Allocated when begin method is called.
|
protected |
(Master Out Slave In) set when using SPI set during construction.