value error when creating an instance of framebuf.FrameBuffer in MicroPython

72 views Asked by At

This is a problem with the width argument, and the program will only work correctly if it has a specified value between one and eight, otherwise it will display a ValueError: error with no explanation.

My code is like this:

from machine import Pin, I2C
from ssd1306 import SSD1306_I2C
import framebuf

i2c = I2C(1 , scl = Pin(15), sda = Pin(14), freq = 400000)
oled = SSD1306_I2C(128, 64, i2c)

image = bytearray([
                        0b00000010000001000000,
                        0b00000100000000100000,
                        0b00001000000000010000,
                        0b00010000000000001000,
                        0b00100000000000000100,
                        0b01000000000000000010,
                        0b10000000000000000001,
                        0b00000000000000000000,
                        0b00000000000000000000,
                        0b00000000000000000000,
                        0b00000000000000000000,
                        0b00000000000000000000,
                        0b00000000000000000000,
                        0b10000000000000000001,
                        0b01000000000000000010,
                        0b00100000000000000100,
                        0b00010000000000001000,
                        0b00001000000000010000,
                        0b00000100000000100000,
                        0b00000010000001000000
                        ])
fb = framebuf.FrameBuffer(image, 20, 20, framebuf.MONO_HLSB)
oled.blit(fb, 15, 15)
oled.show()

And it shows this error :(My idle is Thonny)

Traceback (most recent call last):
  File "<stdin>", line 30, in <module>
ValueError:

And note that nothing is written in front of ValueError:!!! And in my opinion, this error is from the width argument when creating fb Because as long as I write a number between 1 and 8 in this argument, I don't get an error

0

There are 0 answers