Skip to content

drivers/display/ssd1306.py: Add rotate method. #7135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

mcauser
Copy link
Contributor

@mcauser mcauser commented Apr 20, 2021

Adds rotate(bool) to official SSD1306 driver.

The existing init_display() method initialises the screen in the normal orientation.
This PR adds the ability to rotate the display 180 degrees, by remapping the segments and flipping the common output direction. Uses commands SET_COM_OUT_DIR and SET_SEG_REMAP.

Note: changing the common output direction updates the display immediately (mirrored vertically). After remapping the segments, you need to call show() again to repopulate the display memory with the pixel data in the reverse order (mirrored horizontally).

Testing on TinyPICO - ESP32

# MicroPython v1.14 on 2021-02-02; TinyPICO with ESP32-PICO-D4
from machine import Pin, I2C
import ssd1306
i2c = I2C(1, sda=Pin(21), scl=Pin(22))
display = ssd1306.SSD1306_I2C(128, 64, i2c)

# micropython logo
display.fill(0)
display.fill_rect(0, 0, 32, 32, 1)
display.fill_rect(2, 2, 28, 28, 0)
display.vline(9, 8, 22, 1)
display.vline(16, 2, 22, 1)
display.vline(23, 8, 22, 1)
display.fill_rect(26, 24, 2, 4, 1)

# some text
display.text('MicroPython', 40, 0, 1)
display.text('SSD1306', 40, 12, 1)
display.text('OLED 128x64', 40, 24, 1)
display.show()

# rotate 180 deg
display.rotate(True)
display.show()

# rotate 0 deg
display.rotate(False)
display.show()

ssd1306-rotate

@mcauser
Copy link
Contributor Author

mcauser commented Apr 20, 2021

merge

@UnexpectedMaker
Copy link
Contributor

Hahaha... this is worth merging just for the effort @mcauser put in, don't you think @dpgeorge ?

@mcauser
Copy link
Contributor Author

mcauser commented Apr 22, 2021

Tested on a 64x48 I2C SSD1306 (beta wemos oled shield):
ssd1306-64x48

@dpgeorge
Copy link
Member

dpgeorge commented May 6, 2021

Very nice pics!

And the addition of the method looks good to me.

@dpgeorge
Copy link
Member

dpgeorge commented May 6, 2021

Merged in 9eea51b

@dpgeorge dpgeorge closed this May 6, 2021
@mcauser mcauser deleted the ssd1306 branch May 14, 2021 00:22
mcauser added a commit to mcauser/Adafruit_CircuitPython_SSD1306 that referenced this pull request Jun 17, 2021
mcauser added a commit to mcauser/Adafruit_CircuitPython_SSD1306 that referenced this pull request Jun 17, 2021
@DusKing1
Copy link

Hi there! I was using ESP32 with 1.17 firmware and this SSD1306 lib, however the rotation method can work properly. It just, won't do anything. Can you have a dig into this? Thanks!

tannewt pushed a commit to tannewt/circuitpython that referenced this pull request Nov 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants