peterhinch / micropython-samples

Assorted code ideas, unofficial MP FAQ, plus index to my other repositories.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Flip Screen of SSD1306

ppontre opened this issue · comments

Hi Peter,
I can't sort out how to flip screen on Micropython ESP32 using the library.
I've got a TTGO board with ESP, Battery, SSD1306.
I need to flip the screen upside down
Any suggestion ?
Thanx in advance
Paolo

Hi Paolo,
it can be done but it would be a substantial rewrite. I can't see a simple way to fix _printchar() but a rewritten _printchar_bitwise() function could invert each character. The _newline() method would need adapting so that text flow was reversed.
Pete

commented

@paolo

I succeeded in flipping a display arranged with a 8x8 font, no auto-cr, all-manual…. 1. This evening i’ll have another trial

Hi Paolo, would you be so kind to publish your fix?
Besides an SSD1306 I'm also using an SH1106 for which the driver has a rotate method builtin, which serves my needs. I would like a similar solution for a SSD1306 display just as your described here.
Regards, Rob.

@ppontre @robhamerling You may like to look at this update: the CWriter class supports upside down display on any device whose driver is subclassed from frmebuf (e.g. SSD1306).

commented

@peterhinch Thanks for this pointer, looks very nice. However currently I'm satisfied with the fixed 8x8 font and needed only flipping. Maybe useful for a new project.
BTW: In the meantime I found how to perform flipping by modifying a few bits in ssd1306 registers. I opened an issue (#4015) at github.com/micropython and suggested a solution.

My update aims for generality by supporting any display whose driver is subclassed from framebuf.

Alas inverting the display means using the CWriter class. This is over an order of magnitude slower than Writer as it renders glyphs one pixel at a time rather than via bit blitting.

Your SSD1306-specific method evidently won't carry that speed penalty. It also has the advantage that the same coordinates apply to graphics and text, whereas mine only flips text.