SSD1306/README.md

194 lines
7.9 KiB
Markdown
Raw Permalink Normal View History

2020-10-27 09:03:43 -04:00
# C Library for SSD1306 0.96" OLED display
2020-10-13 05:01:17 -04:00
## SSD1306 Description
Detailed information are described in [Datasheet SSD1306](https://cdn-shop.adafruit.com/datasheets/SSD1306.pdf).
## Library
2022-12-15 16:05:41 -05:00
C library is aimed for driving [0.96" OLED display with SSD1306 driver](#demonstration) 128x64 or 128x32 version through TWI's (I2C). Settings for particular versions:
- 128x64 version
- command argument **SSD1306_SET_MUX_RATIO** set to *0x3F* (ssd1306.c)
- command argument **SSD1306_COM_PIN_CONF** set to *0x12* (ssd1306.c)
- **END_PAGE_ADDR** set to 7 (ssd1306.h)
- 128x32 version
- command argument **SSD1306_SET_MUX_RATIO** set to *0x1F* (ssd1306.c)
- command argument **SSD1306_COM_PIN_CONF** set to *0x02* (ssd1306.c)
- **END_PAGE_ADDR** set to 3 (ssd1306.h)
2020-10-13 05:01:17 -04:00
2021-07-20 05:11:44 -04:00
### Versions
2023-11-27 14:30:49 -05:00
- 1.0 - basic functions. The first publication.
- [2.0](https://github.com/Matiasus/SSD1306/tree/v2.0.0) - more changes:
2022-12-15 16:05:41 -05:00
- rebuild to 'cacheMemLcd' array approach. It means that every request is stored in 'cacheMemLcd' array (RAM) and by the [SSD1306_UpdateScreen (uint8_t)](#ssd1306_updatescreen) function is printed on the display.
- added new function -> [SSD1306_DrawLine (uint8_t, uint8_t, uint8_t, uint8_t)](#ssd1306_drawline). Possible depicted any line (horizontal, vertical, with slope).
- possible to use for more than 1 display (not tested).
- **!!!** ~1kB RAM memory consumption.
2024-09-05 08:24:10 -04:00
- [3.0](https://github.com/Matiasus/SSD1306/tree/v3.0.1) - simplified alphanumeric version
2022-12-15 15:50:49 -05:00
- displaying alphanumeric characters
- for **one display** applicable
2022-12-11 08:19:26 -05:00
- **only few RAM bytes** consumption
2022-12-15 15:50:49 -05:00
- **!!!** no graphic functions like drawLine
2024-09-05 08:24:10 -04:00
- [3.1](https://github.com/Matiasus/SSD1306/tree/v3.1.0) - simplified version with draw lines
- displaying alphanumeric characters with graphic functions like drawLine vertical & horizontal
- for **one display** applicable
- **only few RAM bytes** consumption
- horizontal scroll function added
2021-07-20 05:11:44 -04:00
2020-10-13 07:04:33 -04:00
## Dependencies
2022-12-15 16:34:08 -05:00
- [font.h](https://github.com/Matiasus/SSD1306/blob/master/lib/font.h)
- [twi.c](https://github.com/Matiasus/SSD1306/blob/master/lib/twi.c)
- [twi.h](https://github.com/Matiasus/SSD1306/blob/master/lib/twi.h)
2020-10-13 07:04:33 -04:00
2020-10-27 08:46:37 -04:00
Font.c can be modified according to application requirements with form defined in font.c. Maximal permissible horizontal dimension is 8 bits.
2020-10-27 08:20:54 -04:00
2020-10-13 05:01:17 -04:00
### Usage
2021-07-20 05:15:08 -04:00
Prior defined for MCU Atmega328p / Atmega8 / Atmega16. Need to be carefull with TWI ports definition.
2020-10-13 05:01:17 -04:00
2021-07-20 05:15:08 -04:00
| PORT | [Atmega16](http://ww1.microchip.com/downloads/en/devicedoc/doc2466.pdf) | [Atmega8](https://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-2486-8-bit-AVR-microcontroller-ATmega8_L_datasheet.pdf) / [Atmega328](https://ww1.microchip.com/downloads/en/DeviceDoc/ATmega48A-PA-88A-PA-168A-PA-328-P-DS-DS40002061B.pdf) |
2020-10-13 05:01:17 -04:00
| :---: | :---: | :---: |
| SCL | PC0 | PC5 |
| SDA | PC1 | PC4 |
2023-12-20 05:25:03 -05:00
### Picture of hardware connection
<img src="img/connection.png" alt="Hardware connection" width="600">
2020-10-13 05:01:17 -04:00
### Tested
2023-12-20 05:25:03 -05:00
Library was tested and proved with **_0.96″ 128x64 and 0.91" 128x32 OLED Display (SSD1306 driver)_** and **Arduino UNO R3**. The Arduino was without a bootloader installed, it was only raw Atmega328P microcontroller. Communication was done through I2C (TWI) interface of Arduino UNO R3. This hardware configuration was chosen for simplicity.
2020-10-13 07:00:31 -04:00
## Init OLED Sequence
2023-12-20 05:25:03 -05:00
Init sequence OLED display was defined mainly according to page 64 (next to last page) of [Datasheet SSD1306](https://cdn-shop.adafruit.com/datasheets/SSD1306.pdf).
2020-10-13 07:00:31 -04:00
2023-12-20 05:25:03 -05:00
### Flowchart
2020-10-13 07:00:31 -04:00
```
// +---------------------------+
2023-12-20 05:25:03 -05:00
// | Software Reset | // not tested yet, @source https://github.com/SmingHub/Sming/issues/501
2020-10-13 07:00:31 -04:00
// +---------------------------+
2023-12-20 05:25:03 -05:00
// | 0xE4 |
2020-10-13 07:00:31 -04:00
// +---------------------------+
2023-12-20 05:25:03 -05:00
// ||
2020-10-13 07:00:31 -04:00
// +---------------------------+
2023-12-20 05:25:03 -05:00
// | DISPLAY OFF |
// +---------------------------+
// | 0xAE |
// +---------------------------+
// ||
// +---------------------------+
// | Set MUX Ratio |
// +---------------------------+
// | 0xA8 |
// | 0x3F |
// +---------------------------+
// ||
// +---------------------------+
// | Set Memory Addr Mode |
2020-10-13 07:00:31 -04:00
// +---------------------------+
2023-12-20 05:25:03 -05:00
// | 0x20 |
// | 0x00 |
2020-10-13 07:00:31 -04:00
// +---------------------------+
2023-12-20 05:25:03 -05:00
// ||
2020-10-13 07:00:31 -04:00
// +---------------------------+
2023-12-20 05:25:03 -05:00
// | Set Start Line |
2020-10-13 07:00:31 -04:00
// +---------------------------+
2023-12-20 05:25:03 -05:00
// | 0x40 |
2020-10-13 07:00:31 -04:00
// +---------------------------+
2023-12-20 05:25:03 -05:00
// ||
// +---------------------------+
// | Set Display Offset |
// +---------------------------+
// | 0xD3 |
// | 0x00 |
// +---------------------------+
// ||
2020-10-13 07:00:31 -04:00
// +---------------------------+
// | Set Segment Remap |
// +---------------------------+
2023-12-20 05:25:03 -05:00
// | 0xA0 or 0xA1 |
2020-10-13 07:00:31 -04:00
// +---------------------------+
2023-12-20 05:25:03 -05:00
// ||
2020-10-13 07:00:31 -04:00
// +---------------------------+
// | Set COM Output Scan |
// | Direction |
// +---------------------------+
2023-12-20 05:25:03 -05:00
// | 0xC0 or 0xC8 |
2020-10-13 07:00:31 -04:00
// +---------------------------+
2023-12-20 05:25:03 -05:00
// ||
2020-10-13 07:00:31 -04:00
// +---------------------------+
// | Set COM Pins hardware |
// | configuration |
// +---------------------------+
2023-12-20 05:25:03 -05:00
// | 0xDA |
2024-01-07 14:09:36 -05:00
// | 0x12 for 128x64 |
2023-12-20 05:25:03 -05:00
// | 0x02 for 128x32 |
2020-10-13 07:00:31 -04:00
// +---------------------------+
2023-12-20 05:25:03 -05:00
// ||
2020-10-13 07:00:31 -04:00
// +---------------------------+
// | Set Contrast Control |
// +---------------------------+
2023-12-20 05:25:03 -05:00
// | 0x81 |
// | 0x7F |
2020-10-13 07:00:31 -04:00
// +---------------------------+
2023-12-20 05:25:03 -05:00
// ||
2020-10-13 07:00:31 -04:00
// +---------------------------+
// | Disable Entire Display On |
// +---------------------------+
2023-12-20 05:25:03 -05:00
// | 0xA4 |
2020-10-13 07:00:31 -04:00
// +---------------------------+
2023-12-20 05:25:03 -05:00
// ||
2020-10-13 07:00:31 -04:00
// +---------------------------+
// | Set Normal Display |
// +---------------------------+
2023-12-20 05:25:03 -05:00
// | 0xA6 |
2020-10-13 07:00:31 -04:00
// +---------------------------+
2023-12-20 05:25:03 -05:00
// ||
2020-10-13 07:00:31 -04:00
// +---------------------------+
2023-12-20 05:25:03 -05:00
// | Set OSC Frequency Fosc |
2020-10-13 07:00:31 -04:00
// +---------------------------+
2023-12-20 05:25:03 -05:00
// | 0xD5 |
// | 0x80 |
2020-10-13 07:00:31 -04:00
// +---------------------------+
2023-12-20 05:25:03 -05:00
// ||
2020-10-13 07:00:31 -04:00
// +---------------------------+
2023-12-20 05:25:03 -05:00
// | Enable charge pump |
// | regulator |
2020-10-13 07:00:31 -04:00
// +---------------------------+
2023-12-20 05:25:03 -05:00
// | 0x8D |
// | 0x14 |
2020-10-13 07:00:31 -04:00
// +---------------------------+
2023-12-20 05:25:03 -05:00
// ||
// +---------------------------+
// | Deactivate Scroll |
// +---------------------------+
// | 0x2E |
// +---------------------------+
// ||
2020-10-13 07:00:31 -04:00
// +---------------------------+
// | Display On |
// +---------------------------+
2023-12-20 05:25:03 -05:00
// | 0xAF |
2020-10-13 07:00:31 -04:00
// +---------------------------+
```
2020-10-27 08:10:12 -04:00
## Functions
2021-07-20 05:11:44 -04:00
- [SSD1306_Init (uint8_t)](#ssd1306_init) - Init display
- [SSD1306_ClearScreen (void)](#ssd1306_clearscreen) - Clear screen
- [SSD1306_NormalScreen (uint8_t)](#ssd1306_normalscreen) - Normal screen
- [SSD1306_InverseScreen (uint8_t)](#ssd1306_inversescreen) - Inverse screen
- [SSD1306_SetPosition (uint8_t, uint8_t)](#ssd1306_setposition) - Set position
2020-10-27 08:17:28 -04:00
- [SSD1306_DrawChar (char)](#ssd1306_drawchar) - Draw specific character
- [SSD1306_DrawString (char*)](#ssd1306_drawstring) - Draw specific string
2021-07-20 05:11:44 -04:00
- [SSD1306_UpdateScreen (uint8_t)](#ssd1306_updatescreen) - Update content on display
- [SSD1306_DrawLine (uint8_t, uint8_t, uint8_t, uint8_t)](#ssd1306_drawline) - Draw line
2020-10-27 08:57:25 -04:00
2022-12-15 15:50:49 -05:00
## Demonstration version v1.0.0
<img src="img/ssd1306_v100.jpg" />
2020-10-27 08:57:25 -04:00
2022-12-15 15:50:49 -05:00
## Demonstration version v2.0.0
2022-12-15 16:05:41 -05:00
<img src="img/ssd1306_v200.png" />
2022-12-15 15:50:49 -05:00
## Demonstration version v3.0.0
2022-12-11 08:19:26 -05:00
<img src="img/ssd1306_v300.jpg" />
2022-12-15 16:05:41 -05:00
## Acknowledgement
- [Adafruit SSD1306 Library](https://github.com/adafruit/Adafruit_SSD1306)
2020-10-27 08:57:25 -04:00
2020-10-13 05:01:17 -04:00
## Links
- [Datasheet SSD1306](https://cdn-shop.adafruit.com/datasheets/SSD1306.pdf)
2021-07-21 01:34:08 -04:00
- [Atmega328](https://ww1.microchip.com/downloads/en/DeviceDoc/ATmega48A-PA-88A-PA-168A-PA-328-P-DS-DS40002061B.pdf)