diff --git a/esphome/components/ssd1306_base/ssd1306_base.cpp b/esphome/components/ssd1306_base/ssd1306_base.cpp index b0c39033e3c..e0e7f94ce08 100644 --- a/esphome/components/ssd1306_base/ssd1306_base.cpp +++ b/esphome/components/ssd1306_base/ssd1306_base.cpp @@ -32,6 +32,8 @@ static const uint8_t SSD1306_COMMAND_PAGE_ADDRESS = 0x22; static const uint8_t SSD1306_COMMAND_NORMAL_DISPLAY = 0xA6; static const uint8_t SSD1306_COMMAND_INVERSE_DISPLAY = 0xA7; +static const uint8_t SSD1306B_COMMAND_SELECT_IREF = 0xAD; + static const uint8_t SSD1305_COMMAND_SET_BRIGHTNESS = 0x82; static const uint8_t SSD1305_COMMAND_SET_AREA_COLOR = 0xD8; @@ -95,6 +97,12 @@ void SSD1306::setup() { this->command(0x8B); } } else { + if (this->is_ssd1306b_()) { + // Select external or internal Iref (0xAD) + this->command(SSD1306B_COMMAND_SELECT_IREF); + // Enable internal Iref and change from 19ua (POR) to 30uA + this->command(0x20 | 0x10); + } // Enable charge pump (0x8D) this->command(SSD1306_COMMAND_CHARGE_PUMP); if (this->external_vcc_) { @@ -226,6 +234,8 @@ bool SSD1306::is_sh1107_() const { return this->model_ == SH1107_MODEL_128_64 || bool SSD1306::is_ssd1305_() const { return this->model_ == SSD1305_MODEL_128_64 || this->model_ == SSD1305_MODEL_128_32; } +bool SSD1306::is_ssd1306b_() const { return this->model_ == SSD1306_MODEL_72_40; } + void SSD1306::update() { this->do_update_(); this->display(); diff --git a/esphome/components/ssd1306_base/ssd1306_base.h b/esphome/components/ssd1306_base/ssd1306_base.h index 14ec309ae0d..a5734373861 100644 --- a/esphome/components/ssd1306_base/ssd1306_base.h +++ b/esphome/components/ssd1306_base/ssd1306_base.h @@ -63,6 +63,7 @@ class SSD1306 : public display::DisplayBuffer { bool is_sh1106_() const; bool is_sh1107_() const; bool is_ssd1305_() const; + bool is_ssd1306b_() const; void draw_absolute_pixel_internal(int x, int y, Color color) override; diff --git a/esphome/components/ssd1306_i2c/ssd1306_i2c.cpp b/esphome/components/ssd1306_i2c/ssd1306_i2c.cpp index ab6fee7b02b..47a21a8ff40 100644 --- a/esphome/components/ssd1306_i2c/ssd1306_i2c.cpp +++ b/esphome/components/ssd1306_i2c/ssd1306_i2c.cpp @@ -62,9 +62,9 @@ void HOT I2CSSD1306::write_display_data() { } } else { size_t block_size = 16; - if ((this->get_buffer_length_() & 8) == 8) { - // use smaller block size for e.g. 72x40 displays where buffer size is multiple of 8, not 16 - block_size = 8; + if ((this->get_buffer_length_() % 24) == 0) { + // use 24 byte block size for e.g. 72x40 displays where buffer size is multiple of 24, not 16 + block_size = 24; } for (uint32_t i = 0; i < this->get_buffer_length_();) {