Giter Club home page Giter Club logo

esp-idf-ssd1306's Introduction

esp-idf-ssd1306

SSD1306/SH1106 driver for esp-idf

I used this repository as a reference.
I used this font file.

Software requirements

ESP-IDF V4.4/V5.x.

Note for ESP32C2.
ESP-IDF V5.0 ESP32C2 i2c driver has a bug.
ESP-IDF V5.1 is required when using i2c of ESP32C2.

Note for ESP32C6 and ESP32H2.
ESP-IDF V5.1 is required when using ESP32C6 and ESP32H2.

Note for ESP-IDF V5.2.
A new i2c driver is now available in ESP-IDF V5.2.
Under ESP-IDF V5.2 this project uses a new i2c driver.

Installation

git clone https://github.com/nopnop2002/esp-idf-ssd1306
cd esp-idf-ssd1306/TextDemo/
idf.py set-target {esp32/esp32s2/esp32s3/esp32c2/esp32c3/esp32c6/esp32h2}
idf.py menuconfig
idf.py flash

Note for ESP32C3
For some reason, there are development boards that cannot use GPIO06, GPIO08, GPIO09, GPIO19 for SPI clock pins.
According to the ESP32C3 specifications, these pins can also be used as SPI clocks.
I used a raw ESP-C3-13 to verify that these pins could be used as SPI clocks.

Configuration

You have to set this config value with menuconfig.

  • CONFIG_INTERFACE
  • CONFIG_PANEL
  • CONFIG_OFFSETX
  • CONFIG_FLIP
  • CONFIG_SDA_GPIO
  • CONFIG_SCL_GPIO
  • CONFIG_RESET_GPIO
  • CONFIG_MOSI_GPIO
  • CONFIG_SCLK_GPIO
  • CONFIG_CS_GPIO
  • CONFIG_DC_GPIO

config-main


Generic SSD1306 128x32 i2c

128x32 config-128x32_i2c

Generic SSD1306 128x64 i2c

128x64 config-128x64_i2c

Generic SH1106 128x64 i2c

Hardware scroll Not support
Left:1.3 inch SH1106
Right:0.96 inch SSD1306

SH1106_i2c config-sh1106_i2c

128x64 TTGO

Unlike other ESP32 development boards, the RTC_CLOCK crystal on this board uses a 26MHz one.
You need to change the RTC CLOCK frequency to 26MHz using menuconfig.

ESP32-TTGO-1 ESP32-TTGO-2 128x64_Reset config-128x64_TTGO

128x64 ESP-WROOM-32

ESP32-OLED-2 config-ESP-WROOM-32


Generic SSD1306 128x32 SPI

128x32_spi config-128x32_spi

Generic SSD1306 128x64 SPI

D0 is SCLK.
D1 is MOSI.

128x64_spi config-128x64_spi

Generic SH1106 128x64 SPI

Hardware scroll Not support
Left:1.3 inch SH1106
Right:0.96 inch SSD1306

SH1106_spi config-sh1106_spi


I2C Clock speed

According to the SSD1306 datasheet, the minimum i2c clock cycle time is 2.5us.
Therefore, the maximum i2c clock frequency is 400KHz.
The i2c clock frequency used by this project is 400KHz.

I2C Port selection

config-i2c-port

The ESP32 XTENSA series has two I2C Ports.
You can use these two ports freely.
If you use this module at the same time as another I2C device using I2C port 0, you must change it to I2C port 1.


SPI Clock speed

According to the SSD1306 datasheet, the minimum SPI clock cycle time is 100ns.
Therefore, the maximum SPI clock frequency is 10MHz.
The SPI clock frequency used by this project is 1MHz.
Higher SPI clock frequencies can be specified using spi_clock_speed().
When using 10MHz, you need to be careful about the length of the wire cable.

    //int speed = 1000000; // 1MHz
    //int speed = 2000000; // 2MHz
    //int speed = 4000000; // 4MHz
    //int speed = 6000000; // 6MHz
    //int speed = 8000000; // 8MHz
    int speed = 10000000; // 10MHz
    spi_clock_speed(speed);
    spi_master_init(&dev, CONFIG_MOSI_GPIO, CONFIG_SCLK_GPIO, CONFIG_CS_GPIO, CONFIG_DC_GPIO, CONFIG_RESET_GPIO);

SPI BUS selection

config-spi-bus

The ESP32 XTENSA series has three SPI BUSs.
SPI1_HOST is used for communication with Flash memory.
You can use SPI2_HOST and SPI3_HOST freely.
When you use SDSPI(SD Card via SPI), SDSPI uses SPI2_HOST BUS.
When using this module at the same time as SDSPI or other SPI device using SPI2_HOST, it needs to be changed to SPI3_HOST.
When you don't use SDSPI, both SPI2_HOST and SPI3_HOST will work.
Previously it was called HSPI_HOST / VSPI_HOST, but now it is called SPI2_HOST / SPI3_HOST.


Flip upside down

config_flip

ssd1306_flip

esp-idf-ssd1306's People

Contributors

nopnop2002 avatar vadkor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

esp-idf-ssd1306's Issues

Request: provide API to draw XBM bitmap from monochrome buffer with given height/width

The API should be a functional equivalent to:

https://github.com/olikraus/u8g2/wiki/u8g2reference#drawxbm=

Description: Draw a XBM Bitmap. Position (x,y) is the upper left corner of the bitmap. XBM contains monochrome, 1-bit bitmaps.
The current color index is used for drawing (see setColorIndex) pixel values 1. Version 2.15.x of U8g2 introduces a solid and a transparent mode for bitmaps. By default, drawXBM will draw solid bitmaps. This differs from the previous versions: Use setBitmapMode(1) to switch to the previous behavior. The XBMP version of this procedure expects the bitmap to be in PROGMEM area (AVR only). Many tools (including GIMP) can save a bitmap as XBM. A nice step by step instruction is here (external link). The result will look like this:

#define u8g_logo_width 38
#define u8g_logo_height 24
static unsigned char u8g_logo_bits[] = {
   0xff, 0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xe0, 0xe0,
...
   0xff, 0x3f, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xff, 0xff, 0x3f };

Hurray for ssd1306_bitmaps()

Thanks for the bitmaps function. I am using it!

Just ran into something that could use some attention.

In the new function

void ssd1306_bitmaps(SSD1306_t * dev, int xpos, int ypos, uint8_t * bitmap, int width, int height, bool invert)

The xpos, ypos and height parameters are in pixels. I suggest either changing the parameter width to mean width in pixels, or renaming it so that it is clear that it is pixels/8.

Also, the ImageDemo example calls

ssd1306_bitmaps(&dev, xpos, ypos, batman, 4, 12, false);

It passes the height as 12, but the image in the array batman[] is 13 pixels heigh.

/Coert

utf-8

how to use iic to show utf-8?

Proposal to Separate SSD1306 Component to a Standalone Repository

Hi @nopnop2002,

I've been using your SSD1306 Driver for esp-idf and find it very useful.
However, I noticed that the SSD1306 driver is bundled together with numerous examples within the same repository.

Although these examples provide valuable context, I suggest separating the SSD1306 driver into its own dedicated repository. This would make it easier for developers to integrate the driver into their projects, possibly as a Git submodule, without the necessity of cloning the entire current repository.

Separating the driver into its own repository could streamline its adoption by other developers and make it more accessible.

Please consider this proposal and let me know your thoughts.

Thanks for your time

Document ssd1306_display_image

I'm trying to figure out how to use ssd1306_display_image() to display a monochrome image stored in a byte buffer.
There is no documentation or samples on how to do this.

Flip Display Orientation

Hi,
On my lilygo Cam the Display is mounted upside down.
Is there any easy solution to flip the image orientation 180°?

Thank you in advance. =)

When I use your example, I have any question

I want to study ssd1306 with your porject. I use I2C with 0.96 oled.
When I2C is init, your code is ssd1306_i2c.c 54 lines:

        i2c_master_start(cmd);
	i2c_master_write_byte(cmd, (dev->_address << 1) | I2C_MASTER_WRITE, true);
	i2c_master_write_byte(cmd, OLED_CONTROL_BYTE_CMD_STREAM, true);
	i2c_master_write_byte(cmd, OLED_CMD_DISPLAY_OFF, true);

I want to know, in ssd1306 manual, it tell me when Co == 0, i2c frame is follow with contain data byte
image
Don't the contain data byte is last send data type (when I want to send command type, I will send command types until I close I2C, when I want to send data type, I will send data types until I close I2C)?

Will it work with DS3231?

Hi,

you also have a DS3231 Library do you know it's working together with the ssd1306 OLED? I also created another issue here but I am sure that the issue belongs to the lib (I used different I2C Ports)

So Could you test this for me or give me a hint how to combine the OLED with an DS3231?

Thank you in advance

Build and Flash are fine, getting 'i2c driver not installed'

Hi,
Thanks for your work!
I could add the files, successfully build and flash into ESP32. The issue is while running, getting this error:

'/components/driver/i2c.c:1111 (i2c_master_cmd_begin):i2c driver not installed'

Any clue, where I am missing?

thanks!

Best regards
Shanmuganathan

Make I2C Port also via Menuconfig configurable

Hey,

just a small Thing the I2C Hardware is not configurable via the Menuconfig but the SPI-Component is configurable. I found it in the Code so its not a big thing just a small improvement for future updates ;)

Best regards

I don't know any Init cmd and I have any CMD_STREAM or DATA_STREAM question

When in your code:

i2c_master_write_byte(cmd, OLED_CONTROL_BYTE_DATA_STREAM, true); // 40

	i2c_master_write_byte(cmd, OLED_CMD_SET_DISPLAY_OFFSET, true);		// D3
	i2c_master_write_byte(cmd, 0x00, true);
	i2c_master_write_byte(cmd, OLED_CONTROL_BYTE_DATA_STREAM, true);	// 40
	//i2c_master_write_byte(cmd, OLED_CMD_SET_SEGMENT_REMAP, true);		// A1
	if (dev->_flip) {
		i2c_master_write_byte(cmd, OLED_CMD_SET_SEGMENT_REMAP_0, true);		// A0
	} else {
		i2c_master_write_byte(cmd, OLED_CMD_SET_SEGMENT_REMAP_1, true);		// A1
	}
	i2c_master_write_byte(cmd, OLED_CMD_SET_COM_SCAN_MODE, true);		// C8
	i2c_master_write_byte(cmd, OLED_CMD_SET_DISPLAY_CLK_DIV, true);		// D5
	i2c_master_write_byte(cmd, 0x80, true);
	i2c_master_write_byte(cmd, OLED_CMD_SET_COM_PIN_MAP, true);			// DA

I think when OLED_CONTROL_BYTE_DATA_STREAM those below code will can not happen, because 0x40 let ssd1306 think those below code is data instead of cmd.

Can you give me any answer about this.

When you use ssd1306, your code let any OLED_CONTROL_BYTE_DATA_STREAM and OLED_CONTROL_BYTE_CMD_STREAM in your i2c function begin and end. Those cmd is necessary?

And I have another question, when I see the ssd1306 manual, the D/C# flag begin with Control Byte, I want to know this cmd is legal?
image

#define OLED_CONTROL_BYTE_CMD_SINGLE    0x80
#define OLED_CONTROL_BYTE_CMD_STREAM    0x00
#define OLED_CONTROL_BYTE_DATA_SINGLE   0xC0
#define OLED_CONTROL_BYTE_DATA_STREAM   0x40

TTGO LORA32 T3_V1.6: I2C reset

Hi!

I've been trying to use your component but unfortunately despite following both your instructions and these:
https://github.com/Xinyuan-LilyGO/TTGO-LoRa-Series

I am getting a reset:

␛[0;32mI (596) main.c: INTERFACE is i2c␛[0m
␛[0;32mI (606) main.c: CONFIG_SDA_GPIO=4␛[0m
␛[0;32mI (606) main.c: CONFIG_SCL_GPIO=15␛[0m
␛[0;32mI (616) main.c: CONFIG_RESET_GPIO=16␛[0m
ets Jun  8 2016 00:22:57

rst:0x7 (TG0WDT_SYS_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)

My GPIO config:

#define OLED_RST    -1
#define OLED_SDA    21
#define OLED_SCL    22

#define CONFIG_SDA_GPIO OLED_SDA
#define CONFIG_SCL_GPIO OLED_SCL
#define CONFIG_RESET_GPIO OLED_RST

Using platformIO, so I have them defined as CFLAGS -D per target board.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.