Multiple ByteArrays for Pico OLED Displays

RP2040 based microcontroller boards running MicroPython.
Target audience: MicroPython users with an RP2040 boards.
This does not include conventional Linux-based Raspberry Pi boards.
User avatar
ChasL001
Posts: 12
Joined: Wed Apr 07, 2021 12:05 pm
Location: Chinnor, UK
Contact:

Multiple ByteArrays for Pico OLED Displays

Post by ChasL001 » Sun May 23, 2021 8:59 am

Hello All,

I'm trying to write code to display large graphics on a Pico OLED Display (128 x 128) Adafruit 1.12" Display.

I can do this by creating a Byte Array of a graphic and have the numbers ZERO to NINE stored in a text file for quick ref.

I can place the byte array into the standard OLED test code like the one shown in the SDK manual which works

What I want to do is store them each in a variable and call them as needed.

I tried adding them into an array as you would with text strings but when called they are gibberish on screen as they are being encoded into text.

Saving them as individual strings is OK and I can change the string name manually in the program to display each.

What I want to do is to access these strings programmatically and for the life of me I can't work out or find how to do this in MicroPython, maybe it's not possible?

As a test in Python I wrote this code.

Code: Select all

Number = ""
Number1 = "One"
Number2 = "Two"

n = 2
Numbers = str("Number" + str(n))
# for n in Numbers:

print(Numbers)
When run this just prints the Name of the variable as "Number1" instead of the variable content "One". I'm probably missing something very obvious but...

Appreciate any help, thanks.

fdufnews
Posts: 76
Joined: Mon Jul 25, 2016 11:31 am

Re: Multiple ByteArrays for Pico OLED Displays

Post by fdufnews » Sun May 23, 2021 11:52 am

Hello,
Maybe you can find interresting things following this link
I convert images to bytearrays and then the imagexx.py and the script animhorse.py are downloaded into the Pico. The animhorse.py script imports the images and creates an array of images that are displayed one after the other.
There is a short video of the result in the repo.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Multiple ByteArrays for Pico OLED Displays

Post by pythoncoder » Sun May 23, 2021 12:31 pm

@ChasL001 I think you want to store the bytearrays in a dict:

Code: Select all

>>> a = bytearray(20)
>>> b = bytearray(x for x in range(15))
>>> c = bytearray(0xff for _ in range(20))
>>> d = {'a': a, 'b': b, 'c': c}
>>> d['b']
bytearray(b'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e')
>>> d['c']
bytearray(b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff')
>>> 
Peter Hinch
Index to my micropython libraries.

User avatar
ChasL001
Posts: 12
Joined: Wed Apr 07, 2021 12:05 pm
Location: Chinnor, UK
Contact:

Re: Multiple ByteArrays for Pico OLED Displays

Post by ChasL001 » Sun May 23, 2021 4:01 pm

Thanks for this and I can sort of see how it works but don't understand how the image converter works. The text says to "Create a dictionnary with: width, height and image data" but don't know how to do this. Can you give me a bit more info on how it should be used?
fdufnews wrote:
Sun May 23, 2021 11:52 am
Hello,
Maybe you can find interresting things following this link
I convert images to bytearrays and then the imagexx.py and the script animhorse.py are downloaded into the Pico. The animhorse.py script imports the images and creates an array of images that are displayed one after the other.
There is a short video of the result in the repo.

User avatar
ChasL001
Posts: 12
Joined: Wed Apr 07, 2021 12:05 pm
Location: Chinnor, UK
Contact:

Re: Multiple ByteArrays for Pico OLED Displays

Post by ChasL001 » Sun May 23, 2021 5:03 pm

Thanks again Peter,

W3Schools says "Dictionaries are used to store data values in key:value pairs." but I'm not sure how I can make this work for my needs? I need to have 12 variables with names like ONE, TWO THREE... NINE, ZERO, POINT and DEGCEE.

I plan to create a display of the temperature on a display like "9.5 °C" with each character being an image [NINE][POINT][FIVE]" "[DEGCEE]

I modified my code to include what you have suggested

Code: Select all

# Display Image & text on I2C driven sh1106 OLED display 
from machine import Pin, I2C, ADC
from sh1106 import SH1106_I2C
import framebuf

WIDTH  = 128                                            # oled display width
HEIGHT = 128                                            # oled display height
i2c = I2C(0, scl=Pin(9), sda=Pin(8),freq=400000)
oled = SH1106_I2C( WIDTH, HEIGHT, i2c)                   # Init oled display
#  32x32 bytearray
# buffer = bytearray(b'\x00\x00\x00\x01\xff\xf0\x00\x00\x00\x00\x00\x7f\xc0?\xc0\x00\x00\x00\x03\xe0\x00\x01\xf8\x00\x00\x00\x1e\x00\x00\x00\x0f\x80\x00\x00x\x00\x00\x00\x01\xe0\x00\x01\xc0\x00\x00\x00\x00p\x00\x07\x00\x00\x00\x00\x00\x1c\x00\x0c\x00\x00\x00\x00\x00\x06\x008\x00\x00\x00\x00\x00\x18\x00`\x00\x00\x00\x00\x000\x01\xc0\x00\x00\x00\x00\x00\xe0\x01\x80\x00\x00\x00\x00\x01\xc0\x03\x00\x00\x00\x00\x00\x03\x00\x06\x00\x00\x00\x00\x00\x06\x00\x0c\x00\x00\x00\x00\x00\x18\x00\x18\x00\x00\x00\x00\x000\x00\x18\x00\x00\x00\x00\x00`\x000\x00\x00\x00\x00\x01\x80\x00 \x00\x00\x00\x00\x03\x00\x00`\x00\x00\x00\x00\x0e\x00\x00`\x00\x00\x00\x00\x1c\x00\x00@\x00\x00\x00\x000\x00\x00\xc0\x00\x00\x1f\x80`\x00\x00\xc3\xff\xf0q\xc1\x80\x00\x00\x82\x000`c\x00\x00\x00\x82\x000\x80.\x00\x00\x00\x83\x000\x806\x00\x00\x00\x82\x000\xc0#\x00\x00\x00\xc2\x00 `a\xc0\x00\x00\xc2\x00 {\xc0`\x00\x00\xc2\x000\x1f\x008\x00\x00B\x003\xff\xfc\x0c\x00\x00b\x002\xcc\xcc\x07\x00\x00c\x002\x00\x0c\x01\x80\x00"\x00"\x00\x0c\x00\xe0\x002\x00"\x00\x0c\x00p\x00\x1a\x002\x00\x0c\x00\x1c\x00\x1a\x002\x00\x0c\x00\x0e\x00\x0e\x002\x00\x0c\x00\x03\x00\x06\x002\x00\x0c\x00\x01\xc0\x03\x002\x00\x0c\x00\x00`\x02\x00"\x00\x0c\x00\x008\x03\x00"\x00\x0c\x00\x00\x1c\x02\x002\x00\x0c\x00\x00\x07\x02\x002\x00\x0c\x00\x00\x0e\x02\x002\x00\x0c\x00\x008\x02\x003\xff\xfc\x00\x00\xe0\x02\x000\x00\x00\x00\x07\x80\x02\x00>\x00\x00\x00>\x00\x03\x00\'\xc0\x00\x01\xf0\x00\x02\x000\xff\xff\xff\x00\x00\x02\x000\x07\xff\xf0\x00\x00\x02\x008a\x8c\x00\x00\x00\x02\x00?\xff\xfc\x00\x00\x00\x02\x00\x00\x00\x0c\x00\x00\x00\x02\x00\x00\x00\x0c\x00\x00\x00\x02\x00\x00\x00\x0c\x00\x00\x00\x02\x00\x00\x00\x0c\x00\x00\x00\x03\x00\x00\x00\x0c\x00\x00\x00\x02\x00\x00\x00\x0c\x00\x00\x00\x02\x00\x00\x00\x0c\x00\x00\x00\x02\x00\x00\x00\x0c\x00\x00\x00\x02\x00\x00\x00\x0c\x00\x00\x00\x03\xff\xff\xff\xfc\x00\x00\x00')
# Load the array image into the framebuffer (the image is 32x32)

a = bytearray(20)
b = bytearray(x for x in range(15))
c = bytearray(0xff for _ in range(20))
# d = {'a': a, 'b': b, 'c': c, 'd': d, 'e': e, 'f': f, 'g': g, 'h': h, 'i': i, 'j': j, 'k': k, 'l': l, 'm': m}
d = {'a': a, 'b': b, 'c': c}
# Set up list of arrays
d['b']
bytearray(b'\x00\x1f\xfc\x00\x01\xff\xff\x80\x07\xff\xff\xe0\x0f\xff\xff\xf0\x1f\xff\xff\xf8?\xff\xff\xfc?\xff\xff\xfc\x7f\xff\xff\xfe\x7f\xff\xff\xfe\xff\xfc?\xff\xff\xfc?\xff\xff\xfc?\xff\xff\xfc?\xff\xff\xfc?\xff\xff\xfc?\xff\xff\xfc?\xff\xff\xfc?\xff\xff\xfc?\xff\xff\xfc?\xff\xff\xfc?\xff\xff\xfc?\xff\xff\xfc?\xff\x7f\xfc?\xfe\x7f\xff\xff\xfe\x7f\xff\xff\xfe?\xff\xff\xfc?\xff\xff\xfc\x1f\xff\xff\xf8\x0f\xff\xff\xf0\x07\xff\xff\xe0\x01\xff\xff\x80\x00?\xfc\x00')
d['c']
bytearray(b'\x00\x00\xff\xff\x00\x07\xff\xff\x00?\xff\xff\x00\xff\xff\xff\x03\xff\xff\xff\x1f\xff\xff\xff\xff\xff\xff\xff\x7f\xff\xff\xff\x7f\xff\xff\xff?\xff\xff\xff?\xff\xff\xff\x1f\xff\xff\xff\x1f\xf1\xff\xff\x0f\x81\xff\xff\x00\x01\xff\xff\x00\x01\xff\xff\x00\x01\xff\xff\x00\x01\xff\xff\x00\x01\xff\xff\x00\x01\xff\xff\x00\x01\xff\xff\x00\x01\xff\xff\x00\x01\xff\xff\x00\x01\xff\xff\x00\x01\xff\xff\x00\x01\xff\xff\x00\x01\xff\xff\x00\x01\xff\xff\x00\x01\xff\xff\x00\x01\xff\xff\x00\x01\xff\xff\x00\x01\xff\xff')
# d['d']
# bytearray(b'\x01\xff\xf8\x00\x7f\xff\xff\x80\x7f\xff\xff\xf0\xff\xff\xff\xf8\x7f\xff\xff\xfc\x7f\xff\xff\xfe\x7f\xff\xff\xfe\x7f\xff\xff\xff\x7f\xff\xff\xffp\x01\xff\xff\x00\x00\xff\xff\x00\x00\xff\xfe\x00\x00\xff\xfe\x00\x01\xff\xfe\x00\x03\xff\xfe\x00\x0f\xff\xfc\x00\x1f\xff\xf8\x00\x7f\xff\xf0\x00\xff\xff\xc0\x03\xff\xff\x80\x07\xff\xff\x00\x0f\xff\xf8\x00?\xff\xe0\x00\x7f\xff\xff\xfe\xff\xff\xff\xfe\xff\xff\xff\xfe\xff\xff\xff\xfe\xff\xff\xff\xfe\xff\xff\xff\xfe\xff\xff\xff\xfe\xff\xff\xff\xfe\xff\xff\xff\xfe')
# d['e']
# bytearray(b'\x07\xff\xf8\x00\xff\xff\xff\xc0\xff\xff\xff\xf0\xff\xff\xff\xfc\xff\xff\xff\xfe\xff\xff\xff\xfe\xff\xff\xff\xfe\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\xff\xff\x00\x00\xff\xff\x00\x01\xff\xfe\x0f\xff\xff\xfe\x0f\xff\xff\xfc\x0f\xff\xff\xf8\x0f\xff\xff\xf0\x0f\xff\xff\xf8\x0f\xff\xff\xfe\x0f\xff\xff\xff\x0f\xff\xff\xff\x00\x00\xff\xff\x00\x00\x7f\xff\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff\xfe\xff\xff\xff\xfc\xff\xff\xff\xf8\xff\xff\xff\xc0\x0f\xff\xfc\x00')
# d['f']
# bytearray(b'\x07\xff\xf8\x00\x07\xff\xf8\x00\x07\xff\xf0\x00\x07\xff\xf0\x00\x0f\xff\xf0\x00\x0f\xff\xe0\x00\x0f\xff\xe0\x00\x0f\xff\xc0\x00\x1f\xff\xc0\x00\x1f\xff\xc0\x00\x1f\xff\x80\x00?\xff\x80\x00?\xff\x00\x00?\xff?\xfe\x7f\xff?\xfe\x7f\xfe?\xfe\x7f\xfe\x7f\xfe\xff\xfc\x7f\xfe\xff\xfc\x7f\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\x7f\xfe\x00\x00\x7f\xfe\x00\x00\x7f\xfe\x00\x00\x7f\xfe')
# d['g']
# bytearray(b'?\xff\xff\xfc?\xff\xff\xfe?\xff\xff\xfc?\xff\xff\xfc?\xff\xff\xfe?\xff\xff\xfc?\xff\xff\xfe\x7f\xff\xff\xfc?\xff\xff\xfe\x7f\xf8\x00\x00\x7f\xf8\x00\x00\x7f\xff\xff\x00\x7f\xff\xff\xe0\x7f\xff\xff\xf8\x7f\xff\xff\xfc\x7f\xff\xff\xfe\x7f\xff\xff\xfe\x7f\xff\xff\xff\x7f\xff\xff\xff\x7f\xff\xff\xff?\xff\xff\xff\x00\x00?\xff\x00\x00?\xff\x7f\xe0\xff\xff\x7f\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff\xfe\xff\xff\xff\xfc\xff\xff\xff\xf8\xff\xff\xff\xf0\x7f\xff\xff\xc0\x01\xff\xfe\x00')
# d['h']
# bytearray(b'\x00\x1f\xff\x00\x00\xff\xff\xfc\x03\xff\xff\xfe\x07\xff\xff\xfe\x0f\xff\xff\xfc\x1f\xff\xff\xfc?\xff\xff\xfc?\xff\xff\xfc\x7f\xff\xff\xfc\x7f\xfc\x00\x00\xff\xfc\x00\x00\xff\xfb\xff\x00\xff\xff\xff\xe0\xff\xff\xff\xf8\xff\xff\xff\xfc\xff\xff\xff\xfe\xff\xff\xff\xfe\xff\xff\xff\xfe\xff\xff\xff\xff\xff\xfc?\xff\xff\xf8\x1f\xff\xff\xf8\x1f\xff\x7f\xfc\x1f\xff\x7f\xfe?\xff\x7f\xff\xff\xff?\xff\xff\xfe\x1f\xff\xff\xfe\x1f\xff\xff\xfc\x0f\xff\xff\xf8\x03\xff\xff\xe0\x00\xff\xff\xc0\x00?\xfe\x00')
# d['i']
# bytearray(b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\xff\xff\x00\x00\xff\xfe\x00\x01\xff\xfe\x00\x03\xff\xfc\x00\x03\xff\xfc\x00\x07\xff\xf8\x00\x0f\xff\xf8\x00\x0f\xff\xf0\x00\x1f\xff\xf0\x00?\xff\xe0\x00\x7f\xff\xc0\x00\x7f\xff\xc0\x00\xff\xff\x80\x00\xff\xff\x80\x01\xff\xff\x00\x03\xff\xff\x00\x03\xff\xfe\x00\x07\xff\xfe\x00\x07\xff\xfc\x00\x0f\xff\xfc\x00\x00\xff\xf0\x00\x00\x01\xf0\x00')
# d['j']
# bytearray(b'\x00\x7f\xfe\x00\x03\xff\xff\xc0\x0f\xff\xff\xf8\x1f\xff\xff\xf8?\xff\xff\xfc\x7f\xff\xff\xfe\x7f\xff\xff\xfe\x7f\xff\xff\xfe\x7f\xfc?\xfe\x7f\xfc?\xfe\x7f\xfc?\xfe\x7f\xfe\x7f\xfe?\xff\xff\xfc?\xff\xff\xfc\x0f\xff\xff\xf8\x07\xff\xff\xe0\x0f\xff\xff\xf8?\xff\xff\xfc\x7f\xff\xff\xfe\x7f\xfe\x7f\xfe\xff\xfc?\xfe\xff\xfc?\xff\xff\xfc?\xff\xff\xfc?\xff\xff\xff\xff\xff\xff\xff\xff\xfe\x7f\xff\xff\xfe\x7f\xff\xff\xfe\x1f\xff\xff\xfc\x0f\xff\xff\xf8\x03\xff\xff\xc0\x00\x7f\xfe\x00')
# d['k']
# bytearray(b'\x00\x7f\xf8\x00\x03\xff\xff\x00\x0f\xff\xff\xe0\x1f\xff\xff\xf0?\xff\xff\xf8\x7f\xff\xff\xf8\x7f\xff\xff\xfc\x7f\xff\xff\xfc\xff\xff\xff\xfe\xff\xf8?\xfe\xff\xf8\x1f\xfe\xff\xf8\x1f\xfe\xff\xf8\x1f\xff\xff\xff\xff\xff\x7f\xff\xff\xff\x7f\xff\xff\xff?\xff\xff\xff?\xff\xff\xff\x1f\xff\xff\xff\x07\xff\xff\xff\x01\xff\xff\xfe\x00\x00\x1f\xfe\x00\x00?\xfe?\xff\xff\xfe?\xff\xff\xfc?\xff\xff\xfc?\xff\xff\xf8?\xff\xff\xf8?\xff\xff\xf0\x7f\xff\xff\xc0\x7f\xff\xff\x00\x03\xff\xfc\x00')
# d['l']
# bytearray(b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff')
# d['m']
# bytearray(b'\x1e\x00\x03\xf0?\x80\x0f\xfe\x7f\x80?\xff\x7f\xc0\x7f\xff\xff\xc0\x7f\xff\xf3\xc0\xff\xff\xf3\xc0\xff\xff\xf3\xc0\xff\xff\xff\xc0\xff\xff\xff\xc1\xff\x80\x7f\xc1\xff\x00\x7f\x81\xfe\x00?\x01\xfe\x00\x00\x01\xfe\x00\x00\x01\xfe\x00\x00\x01\xfe\x00\x00\x01\xfe\x00\x00\x01\xfe\x00\x00\x01\xfe\x00\x00\x01\xfe\x00\x00\x01\xfe\x00\x00\x01\xff\x00\x00\x01\xff\x00\x00\x00\xff\xff\x00\x00\xff\xff\x00\x00\xff\xff\x00\x00\xff\xff\x00\x00\x7f\xff\x00\x00\x7f\xff\x00\x00?\xff\x00\x00\x1f\xff\x00\x00\x07\xf8')

# myNumber0 = (b'\x00\x1f\xfc\x00\x01\xff\xff\x80\x07\xff\xff\xe0\x0f\xff\xff\xf0\x1f\xff\xff\xf8?\xff\xff\xfc?\xff\xff\xfc\x7f\xff\xff\xfe\x7f\xff\xff\xfe\xff\xfc?\xff\xff\xfc?\xff\xff\xfc?\xff\xff\xfc?\xff\xff\xfc?\xff\xff\xfc?\xff\xff\xfc?\xff\xff\xfc?\xff\xff\xfc?\xff\xff\xfc?\xff\xff\xfc?\xff\xff\xfc?\xff\xff\xfc?\xff\x7f\xfc?\xfe\x7f\xff\xff\xfe\x7f\xff\xff\xfe?\xff\xff\xfc?\xff\xff\xfc\x1f\xff\xff\xf8\x0f\xff\xff\xf0\x07\xff\xff\xe0\x01\xff\xff\x80\x00?\xfc\x00')
# myNumber1 = (b'\x00\x00\xff\xff\x00\x07\xff\xff\x00?\xff\xff\x00\xff\xff\xff\x03\xff\xff\xff\x1f\xff\xff\xff\xff\xff\xff\xff\x7f\xff\xff\xff\x7f\xff\xff\xff?\xff\xff\xff?\xff\xff\xff\x1f\xff\xff\xff\x1f\xf1\xff\xff\x0f\x81\xff\xff\x00\x01\xff\xff\x00\x01\xff\xff\x00\x01\xff\xff\x00\x01\xff\xff\x00\x01\xff\xff\x00\x01\xff\xff\x00\x01\xff\xff\x00\x01\xff\xff\x00\x01\xff\xff\x00\x01\xff\xff\x00\x01\xff\xff\x00\x01\xff\xff\x00\x01\xff\xff\x00\x01\xff\xff\x00\x01\xff\xff\x00\x01\xff\xff\x00\x01\xff\xff\x00\x01\xff\xff')
# myNumber2 = (b'\x01\xff\xf8\x00\x7f\xff\xff\x80\x7f\xff\xff\xf0\xff\xff\xff\xf8\x7f\xff\xff\xfc\x7f\xff\xff\xfe\x7f\xff\xff\xfe\x7f\xff\xff\xff\x7f\xff\xff\xffp\x01\xff\xff\x00\x00\xff\xff\x00\x00\xff\xfe\x00\x00\xff\xfe\x00\x01\xff\xfe\x00\x03\xff\xfe\x00\x0f\xff\xfc\x00\x1f\xff\xf8\x00\x7f\xff\xf0\x00\xff\xff\xc0\x03\xff\xff\x80\x07\xff\xff\x00\x0f\xff\xf8\x00?\xff\xe0\x00\x7f\xff\xff\xfe\xff\xff\xff\xfe\xff\xff\xff\xfe\xff\xff\xff\xfe\xff\xff\xff\xfe\xff\xff\xff\xfe\xff\xff\xff\xfe\xff\xff\xff\xfe\xff\xff\xff\xfe')
# myNumber3 = (b'\x07\xff\xf8\x00\xff\xff\xff\xc0\xff\xff\xff\xf0\xff\xff\xff\xfc\xff\xff\xff\xfe\xff\xff\xff\xfe\xff\xff\xff\xfe\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\xff\xff\x00\x00\xff\xff\x00\x01\xff\xfe\x0f\xff\xff\xfe\x0f\xff\xff\xfc\x0f\xff\xff\xf8\x0f\xff\xff\xf0\x0f\xff\xff\xf8\x0f\xff\xff\xfe\x0f\xff\xff\xff\x0f\xff\xff\xff\x00\x00\xff\xff\x00\x00\x7f\xff\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff\xfe\xff\xff\xff\xfc\xff\xff\xff\xf8\xff\xff\xff\xc0\x0f\xff\xfc\x00')
# myNumber4 = (b'\x07\xff\xf8\x00\x07\xff\xf8\x00\x07\xff\xf0\x00\x07\xff\xf0\x00\x0f\xff\xf0\x00\x0f\xff\xe0\x00\x0f\xff\xe0\x00\x0f\xff\xc0\x00\x1f\xff\xc0\x00\x1f\xff\xc0\x00\x1f\xff\x80\x00?\xff\x80\x00?\xff\x00\x00?\xff?\xfe\x7f\xff?\xfe\x7f\xfe?\xfe\x7f\xfe\x7f\xfe\xff\xfc\x7f\xfe\xff\xfc\x7f\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\x7f\xfe\x00\x00\x7f\xfe\x00\x00\x7f\xfe\x00\x00\x7f\xfe')
# myNumber5 = (b'?\xff\xff\xfc?\xff\xff\xfe?\xff\xff\xfc?\xff\xff\xfc?\xff\xff\xfe?\xff\xff\xfc?\xff\xff\xfe\x7f\xff\xff\xfc?\xff\xff\xfe\x7f\xf8\x00\x00\x7f\xf8\x00\x00\x7f\xff\xff\x00\x7f\xff\xff\xe0\x7f\xff\xff\xf8\x7f\xff\xff\xfc\x7f\xff\xff\xfe\x7f\xff\xff\xfe\x7f\xff\xff\xff\x7f\xff\xff\xff\x7f\xff\xff\xff?\xff\xff\xff\x00\x00?\xff\x00\x00?\xff\x7f\xe0\xff\xff\x7f\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff\xfe\xff\xff\xff\xfc\xff\xff\xff\xf8\xff\xff\xff\xf0\x7f\xff\xff\xc0\x01\xff\xfe\x00')
# myNumber6 = (b'\x00\x1f\xff\x00\x00\xff\xff\xfc\x03\xff\xff\xfe\x07\xff\xff\xfe\x0f\xff\xff\xfc\x1f\xff\xff\xfc?\xff\xff\xfc?\xff\xff\xfc\x7f\xff\xff\xfc\x7f\xfc\x00\x00\xff\xfc\x00\x00\xff\xfb\xff\x00\xff\xff\xff\xe0\xff\xff\xff\xf8\xff\xff\xff\xfc\xff\xff\xff\xfe\xff\xff\xff\xfe\xff\xff\xff\xfe\xff\xff\xff\xff\xff\xfc?\xff\xff\xf8\x1f\xff\xff\xf8\x1f\xff\x7f\xfc\x1f\xff\x7f\xfe?\xff\x7f\xff\xff\xff?\xff\xff\xfe\x1f\xff\xff\xfe\x1f\xff\xff\xfc\x0f\xff\xff\xf8\x03\xff\xff\xe0\x00\xff\xff\xc0\x00?\xfe\x00')
# myNumber7 = (b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\xff\xff\x00\x00\xff\xfe\x00\x01\xff\xfe\x00\x03\xff\xfc\x00\x03\xff\xfc\x00\x07\xff\xf8\x00\x0f\xff\xf8\x00\x0f\xff\xf0\x00\x1f\xff\xf0\x00?\xff\xe0\x00\x7f\xff\xc0\x00\x7f\xff\xc0\x00\xff\xff\x80\x00\xff\xff\x80\x01\xff\xff\x00\x03\xff\xff\x00\x03\xff\xfe\x00\x07\xff\xfe\x00\x07\xff\xfc\x00\x0f\xff\xfc\x00\x00\xff\xf0\x00\x00\x01\xf0\x00')
# myNumber8 = (b'\x00\x7f\xfe\x00\x03\xff\xff\xc0\x0f\xff\xff\xf8\x1f\xff\xff\xf8?\xff\xff\xfc\x7f\xff\xff\xfe\x7f\xff\xff\xfe\x7f\xff\xff\xfe\x7f\xfc?\xfe\x7f\xfc?\xfe\x7f\xfc?\xfe\x7f\xfe\x7f\xfe?\xff\xff\xfc?\xff\xff\xfc\x0f\xff\xff\xf8\x07\xff\xff\xe0\x0f\xff\xff\xf8?\xff\xff\xfc\x7f\xff\xff\xfe\x7f\xfe\x7f\xfe\xff\xfc?\xfe\xff\xfc?\xff\xff\xfc?\xff\xff\xfc?\xff\xff\xff\xff\xff\xff\xff\xff\xfe\x7f\xff\xff\xfe\x7f\xff\xff\xfe\x1f\xff\xff\xfc\x0f\xff\xff\xf8\x03\xff\xff\xc0\x00\x7f\xfe\x00')
# myNumber9 = (b'\x00\x7f\xf8\x00\x03\xff\xff\x00\x0f\xff\xff\xe0\x1f\xff\xff\xf0?\xff\xff\xf8\x7f\xff\xff\xf8\x7f\xff\xff\xfc\x7f\xff\xff\xfc\xff\xff\xff\xfe\xff\xf8?\xfe\xff\xf8\x1f\xfe\xff\xf8\x1f\xfe\xff\xf8\x1f\xff\xff\xff\xff\xff\x7f\xff\xff\xff\x7f\xff\xff\xff?\xff\xff\xff?\xff\xff\xff\x1f\xff\xff\xff\x07\xff\xff\xff\x01\xff\xff\xfe\x00\x00\x1f\xfe\x00\x00?\xfe?\xff\xff\xfe?\xff\xff\xfc?\xff\xff\xfc?\xff\xff\xf8?\xff\xff\xf8?\xff\xff\xf0\x7f\xff\xff\xc0\x7f\xff\xff\x00\x03\xff\xfc\x00')
# Point = (b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff')
# DegCee = (b'\x1e\x00\x03\xf0?\x80\x0f\xfe\x7f\x80?\xff\x7f\xc0\x7f\xff\xff\xc0\x7f\xff\xf3\xc0\xff\xff\xf3\xc0\xff\xff\xf3\xc0\xff\xff\xff\xc0\xff\xff\xff\xc1\xff\x80\x7f\xc1\xff\x00\x7f\x81\xfe\x00?\x01\xfe\x00\x00\x01\xfe\x00\x00\x01\xfe\x00\x00\x01\xfe\x00\x00\x01\xfe\x00\x00\x01\xfe\x00\x00\x01\xfe\x00\x00\x01\xfe\x00\x00\x01\xfe\x00\x00\x01\xff\x00\x00\x01\xff\x00\x00\x00\xff\xff\x00\x00\xff\xff\x00\x00\xff\xff\x00\x00\xff\xff\x00\x00\x7f\xff\x00\x00\x7f\xff\x00\x00?\xff\x00\x00\x1f\xff\x00\x00\x07\xf8')

buffer = bytearray(c)
fb = framebuf.FrameBuffer(buffer, 32, 32, framebuf.MONO_HLSB)
# Clear the oled display in case it has junk on it.
oled.fill(0)
# Blit the image from the framebuffer to the oled display x = across, y = down
oled.blit(fb, 0, 0)
# Finally update the oled display so the image & text is displayed
oled.show()

This sort of works but the display is in the wrong place with corruption at the top,
bad_zero.jpg
bad_zero.jpg (25.43 KiB) Viewed 5042 times
compared to using a ByteArray like "myNumber0"

Code: Select all

buffer = bytearray(myNumber0)
good_zero.jpg
good_zero.jpg (28.09 KiB) Viewed 5042 times
I have commented out my original set of byte arrays, added a set and tried adding more to the dict code but when I add

Code: Select all

# d = {'a': a, 'b': b, 'c': c, 'd': d, 'e': e, 'f': f, 'g': g, 'h': h, 'i': i, 'j': j, 'k': k, 'l': l, 'm': m}
I get an error saying "d is not defined".

I obviously don't understand how these dictionaries work and can't find a guide to explain it to me better.

Sorry to be such a dunce.
pythoncoder wrote:
Sun May 23, 2021 12:31 pm
@ChasL001 I think you want to store the bytearrays in a dict:

Code: Select all

>>> a = bytearray(20)
>>> b = bytearray(x for x in range(15))
>>> c = bytearray(0xff for _ in range(20))
>>> d = {'a': a, 'b': b, 'c': c}
>>> d['b']
bytearray(b'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e')
>>> d['c']
bytearray(b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff')
>>> 

hippy
Posts: 130
Joined: Sat Feb 20, 2021 2:46 pm
Location: UK

Re: Multiple ByteArrays for Pico OLED Displays

Post by hippy » Sun May 23, 2021 5:26 pm

ChasL001 wrote:
Sun May 23, 2021 5:03 pm
I obviously don't understand how these dictionaries work and can't find a guide to explain it to me better.
This would be my simple example ...

Code: Select all

friend = {}
friend["best"] = "Sir Lancelot"
friend["nice"] = "Lady Guinevere"
friend["evil"] = "Mordred"

print("My best friend is " + friend["best"])
print("My nice friend is " + friend["nice"])
print("My evil friend is " + friend["evil"])
You are pairing 'what's within the brackets' - in this case strings, "best", "nice" and "evil", with what's being assigned. So if you did a print(friend) you would see that pairing ...

Code: Select all

{'nice': 'Lady Guinevere', 'best': 'Sir Lancelot', 'evil': 'Mordred'}

fdufnews
Posts: 76
Joined: Mon Jul 25, 2016 11:31 am

Re: Multiple ByteArrays for Pico OLED Displays

Post by fdufnews » Sun May 23, 2021 5:45 pm

Considering your need, I think it will be easier to use a tuple

Code: Select all

myCar = (myNumber0, myNumber1, myNumber2, myNumber3, myNumber4, ..... , myNumber9, , Point, DecCee)
You can then access the shape of the number using its value as an index in myCar.

Code: Select all

buffer = bytearray(myCar[0]) # will display 0
fb = framebuf.FrameBuffer(buffer, 32, 32, framebuf.MONO_HLSB)
This is an example, you can extract each digit of the temp and use it as an index in myCar

Edit: corrected an error (tuple instead of set)
Last edited by fdufnews on Tue May 25, 2021 6:38 am, edited 1 time in total.

User avatar
ChasL001
Posts: 12
Joined: Wed Apr 07, 2021 12:05 pm
Location: Chinnor, UK
Contact:

Re: Multiple ByteArrays for Pico OLED Displays

Post by ChasL001 » Sun May 23, 2021 8:36 pm

hippy wrote:
Sun May 23, 2021 5:26 pm
ChasL001 wrote:
Sun May 23, 2021 5:03 pm
I obviously don't understand how these dictionaries work and can't find a guide to explain it to me better.
This would be my simple example ...

Code: Select all

friend = {}
friend["best"] = "Sir Lancelot"
friend["nice"] = "Lady Guinevere"
friend["evil"] = "Mordred"

print("My best friend is " + friend["best"])
print("My nice friend is " + friend["nice"])
print("My evil friend is " + friend["evil"])
You are pairing 'what's within the brackets' - in this case strings, "best", "nice" and "evil", with what's being assigned. So if you did a print(friend) you would see that pairing ...

Code: Select all

{'nice': 'Lady Guinevere', 'best': 'Sir Lancelot', 'evil': 'Mordred'}
Thank you, that helped a lot :)

BUT THIS SOLVED IT! Brilliant, thank you :D
fdufnews wrote:
Sun May 23, 2021 5:45 pm
Considering your need, I think it will be easier to use a set

Code: Select all

myCar = (myNumber0, myNumber1, myNumber2, myNumber3, myNumber4, ..... , myNumber9, , Point, DecCee)
You can then access the shape of the number using its value as an index in myCar.

Code: Select all

buffer = bytearray(myCar[0]) # will display 0
fb = framebuf.FrameBuffer(buffer, 32, 32, framebuf.MONO_HLSB)
This is an example, you can extract each digit of the temp and use it as an index in myCar

hippy
Posts: 130
Joined: Sat Feb 20, 2021 2:46 pm
Location: UK

Re: Multiple ByteArrays for Pico OLED Displays

Post by hippy » Mon May 24, 2021 12:04 pm

Glad to help.

If you have your friends defined -

Code: Select all

bestF = "Sir Lancelot"
niceF = "Lady Guinevere"
evilF = "Mordred"
You can rank them, 0 being best, by using a dictioanry -

Code: Select all

friend = {}
friend[0] = bestF
friend[1] = niceF
friend[2] = evilF
or you could replace that with -

Code: Select all

friend = {0: bestF, 1: niceF, 2: evilF}
Using either you can list them in order, best (0) first, with -

Code: Select all

print("My friends are, best first ...")
for n in range(len(friend)):
  print("{} : {}".format(n, friend[n]))
Because your dictionary is ordered, from 0 upwards -

Code: Select all

friend = {0: bestF, 1: niceF, 2: evilF}
you can replace that dictionary with a tuple -

Code: Select all

friend = (bestF, niceF, evilF)
or a list ( 'array' ) -

Code: Select all

friend = [bestF, niceF, evilF]
These are all functionally equivalent, and the same 'listing them' code above works as is. The tuple and list should however be faster to access and use less memory than the dictionary.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Multiple ByteArrays for Pico OLED Displays

Post by pythoncoder » Mon May 24, 2021 12:50 pm

fdufnews wrote:
Sun May 23, 2021 5:45 pm
Considering your need, I think it will be easier to use a set

Code: Select all

myCar = (myNumber0, myNumber1, myNumber2, myNumber3, myNumber4, ..... , myNumber9, , Point, DecCee)
That is a tuple, not a set.
Peter Hinch
Index to my micropython libraries.

Post Reply