Page 1 of 1

how to use framebuf on ESP32

Posted: Thu Jun 11, 2020 6:50 pm
by BigStupidBeast
Hello every one!
stupid question
how to use framebuf on ESP32?
i have a manual

and i have a simple code:

Code: Select all

from machine import Pin, I2C
import ssd1306


def display(zuzu, scl_pin=22, sda_pin=21, oled_width = 128, oled_height = 64):
    #the list for "display" must contain data in format like (string, int, int)
    i2c = I2C(-1, scl=Pin(scl_pin), sda=Pin(sda_pin))
       
    oled = ssd1306.SSD1306_I2C(oled_width, oled_height, i2c)

    oled.fill(0)
    for i in zuzu:
        oled.text(*i)
        oled.show()

if __name__ == '__main__':     
    x = 6
        list = [
        ('bad', 0, 0),
            ('good', 10, 10),
                ('ugly', 20, 20),
        ('bullets:', 5, 30), (str(x), 70, 30),
                ('Google', 20, 40)
        ]

    display(list)

how to make it work togethe?

if i try this
ESP told me

Code: Select all

Traceback (most recent call last):
  File "<stdin>", line 51, in <module>
AttributeError: 'SSD1306_I2C' object has no attribute 'framebuf'

Re: how to use framebuf on ESP32

Posted: Fri Jun 12, 2020 9:50 am
by pythoncoder
This code https://github.com/Pi4IoT/Single_Board_ ... graphic.py is out of date and won't work with the current official driver.

I suggest you start simple, with a "hello world" display.

You don't need the

Code: Select all

if __name__ == '__main__':
line on microcontrollers. (Incidentally the indentation is wrong in your code here).

Just define a function, let's say 'test' in module 'mymodule.py'. At the REPL you'd issue

Code: Select all

>>> import mymodule
>>> mymodule.test()

Re: how to use framebuf on ESP32

Posted: Sun Jun 14, 2020 10:39 am
by BigStupidBeast
Hi.
In new day with renewed vigour:)

about code.
That my logic. The screen works every time after "show()" comand. I hide my function in "display.py" file and call it only than i need it. The

Code: Select all

if __name__ == '__main__':
here for quick control check what's wrong: wire or code.
Incidentally the indentation is wrong for visualisation how text will be located on screen

Code: Select all

class SSD1306([b]framebuf.FrameBuffer[/b]): #!!the magic is here!!
    def __init__(self, width, height, external_vcc):
        self.width = width
        self.height = height
        self.external_vcc = external_vcc
        self.pages = self.height // 8
        self.buffer = bytearray(self.pages * self.width)
        [b]super().__init__(self.buffer, self.width, self.height, framebuf.MONO_VLSB)[/b] #!!and here!!
        self.init_display()

Code: Select all

>>> dir(oled)
['__class__', '__init__', '__module__', '__qualname__', '__dict__', 
'addr', 'blit', 'buffer', 'fill', 'fill_rect', 'hline', 
'invert', 'line', 'pixel', 'rect', 'scroll', 'text', 'vline', 'width', 'i2c', 'show',
 'height', 'external_vcc', 'pages', 'init_display', 'write_cmd', 'poweroff',
  'poweron', 'contrast', 'write_data', 'temp', 'write_list']