2017-10-18 19:25:48 +00:00
|
|
|
# Driver for SSD1306/SH1106 OLED LCD
|
2016-10-28 12:08:37 +00:00
|
|
|
|
|
|
|
This driver is written for usage with the ESP8266 and FreeRTOS ([esp-open-rtos](https://github.com/SuperHouse/esp-open-rtos)).
|
|
|
|
|
2016-11-28 22:57:22 +00:00
|
|
|
## Supported display sizes
|
2016-10-28 12:08:37 +00:00
|
|
|
|
2016-11-28 22:57:22 +00:00
|
|
|
- 128x64
|
|
|
|
- 128x32
|
|
|
|
- 128x16
|
|
|
|
- 96x16
|
|
|
|
|
|
|
|
## Supported connection interfaces
|
|
|
|
|
2017-10-18 19:25:48 +00:00
|
|
|
I2C, SPI3 and SPI4.
|
2016-11-28 22:57:22 +00:00
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
|
|
|
If Reset pin is accesible in your display module, connect it to the RESET pin of ESP8266.
|
2017-10-18 19:25:48 +00:00
|
|
|
If you don't, display RAM could be glitchy after the power cycle.
|
2016-11-28 22:57:22 +00:00
|
|
|
|
|
|
|
### I2C protocol
|
|
|
|
|
2017-10-18 19:25:48 +00:00
|
|
|
Before using the OLED module you need to call the function `i2c_init(BUS, SCL_PIN, SDA_PIN, I2C_FREQ_400K)`
|
|
|
|
to configure the I2C interface and then you should call `ssd1306_init()`.
|
2016-10-28 12:08:37 +00:00
|
|
|
|
|
|
|
#### Example
|
|
|
|
|
2016-11-28 22:57:22 +00:00
|
|
|
```C
|
|
|
|
#define SCL_PIN 5
|
|
|
|
#define SDA_PIN 4
|
2017-10-18 19:25:48 +00:00
|
|
|
#define I2C_BUS 0
|
2016-11-28 22:57:22 +00:00
|
|
|
...
|
|
|
|
|
|
|
|
static const ssd1306_t device = {
|
2017-10-18 19:25:48 +00:00
|
|
|
.protocol = SSD1306_PROTO_I2C,
|
|
|
|
.screen = SSD1306_SCREEN, // or SH1106_SCREEN
|
|
|
|
.i2c_dev.bus = I2C_BUS,
|
|
|
|
.i2c_dev.addr = SSD1306_I2C_ADDR_0,
|
|
|
|
.width = 128,
|
|
|
|
.height = 64
|
2016-11-28 22:57:22 +00:00
|
|
|
};
|
|
|
|
|
2016-10-28 12:08:37 +00:00
|
|
|
...
|
|
|
|
|
2017-10-18 19:25:48 +00:00
|
|
|
i2c_init(I2C_BUS, SCL_PIN, SDA_PIN, I2C_FREQ_400K);
|
2016-10-28 12:08:37 +00:00
|
|
|
|
2016-11-28 22:57:22 +00:00
|
|
|
if (ssd1306_init(&device)) {
|
|
|
|
// An error occured, while performing SSD1306 init (E.g device not found etc.)
|
2016-10-28 12:08:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// rest of the code
|
|
|
|
```
|
|
|
|
|
2017-10-18 19:25:48 +00:00
|
|
|
### SPI3 and SPI4 protocols
|
2016-11-28 22:57:22 +00:00
|
|
|
|
2017-10-18 19:25:48 +00:00
|
|
|
These protocols are MUCH faster than I2C, but use 2 additional GPIO pins
|
|
|
|
(besides the **HSPI CLK** and **HSPI MOSI**): **Chip Select** and **Data/Command** (in case of SPI4).
|
2016-10-28 12:08:37 +00:00
|
|
|
|
2016-11-28 22:57:22 +00:00
|
|
|
No additional function calls are required before `ssd1306_init()`.
|
2016-10-28 12:08:37 +00:00
|
|
|
|
2017-10-18 19:25:48 +00:00
|
|
|
|
|
|
|
#### SPI4 Example
|
2016-11-28 22:57:22 +00:00
|
|
|
|
|
|
|
```C
|
|
|
|
#define CS_PIN 5
|
|
|
|
#define DC_PIN 4
|
|
|
|
|
|
|
|
...
|
|
|
|
|
|
|
|
static const ssd1306_t device = {
|
|
|
|
.protocol = SSD1306_PROTO_SPI4,
|
2017-10-18 19:25:48 +00:00
|
|
|
.screen = SSD1306_SCREEN,
|
|
|
|
.cs_pin = CS_PIN,
|
|
|
|
.dc_pin = DC_PIN,
|
|
|
|
.width = 128,
|
|
|
|
.height = 64
|
|
|
|
};
|
|
|
|
|
|
|
|
...
|
|
|
|
|
|
|
|
if (ssd1306_init(&device)) {
|
|
|
|
// An error occured, while performing SSD1306 init
|
|
|
|
}
|
|
|
|
|
|
|
|
// rest of the code
|
|
|
|
```
|
|
|
|
|
|
|
|
#### SPI3 example
|
|
|
|
```C
|
|
|
|
|
|
|
|
#define CS_PIN 5
|
|
|
|
|
|
|
|
...
|
|
|
|
|
|
|
|
static const ssd1306_t device = {
|
|
|
|
.protocol = SSD1306_PROTO_SPI3,
|
|
|
|
.screen = SSD1306_SCREEN,
|
|
|
|
.cs_pin = CS_PIN,
|
|
|
|
.width = 128,
|
|
|
|
.height = 64
|
2016-11-28 22:57:22 +00:00
|
|
|
};
|
2016-10-28 12:08:37 +00:00
|
|
|
|
2016-11-28 22:57:22 +00:00
|
|
|
...
|
|
|
|
|
|
|
|
if (ssd1306_init(&device)) {
|
|
|
|
// An error occured, while performing SSD1306 init
|
|
|
|
}
|
|
|
|
|
|
|
|
// rest of the code
|
|
|
|
```
|