Black Lives Matter - Action and Equality. ... Adafruit is open and shipping.
0

circuit python + load bmp from flash?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

circuit python + load bmp from flash?

by dattasaurabh82 on Sat Jul 04, 2020 7:33 am

I'm trying to see if I can make loading bmp faster by first loading it from flash to memory:
My system is :
Adafruit M0 Express.
ST7735 Tft display.

the bmp file is stored in the root directory and I can load and display it using:
Code: Select all | TOGGLE FULL SIZE
OnDiskBitmap


Here's my code for that:

Code: Select all | TOGGLE FULL SIZE
import board
import displayio
from adafruit_st7735r import ST7735R
import adafruit_imageload

# Release any resources currently in use for the displays
displayio.release_displays()

spi = board.SPI()

while not spi.try_lock():
    pass

spi.configure(baudrate=24000000)  # Configure SPI for 24MHz
spi.unlock()

tft_cs = board.D5
tft_dc = board.D6
tft_rst = board.D9

display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=tft_rst)
display = ST7735R(display_bus, width=128, height=160, rotation=0, bgr=True)

splash = displayio.Group(max_size=10)
display.show(splash)

with open("/purple.bmp", "rb") as f:
    bmp = displayio.OnDiskBitmap(f)
    background = displayio.TileGrid(bmp, pixel_shader=displayio.ColorConverter(), x=0, y=0)
    splash.append(background)
   

    while True:
        pass

#bitmap, palette = adafruit_imageload.load("/purple.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette)

while True:
    pass


When I try using this function, which I believe would be best suited for my purpose:
Code: Select all | TOGGLE FULL SIZE
bitmap, palette = adafruit_imageload.load("/purple.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette)

It throws a memory allocation failed error and the error happens around line 77 of the image load library

Any idea what is happening here?
Can any one re-create this and tell me what's happening?
I'm guessing it's TFT screen type agnostic!

dattasaurabh82
 
Posts: 7
Joined: Wed Feb 13, 2013 1:46 pm

Re: circuit python + load bmp from flash?

by tannewt on Mon Jul 06, 2020 1:08 am

This will depend on your image. How many pixels is it and how many colors? The memory needed will be `width * height * color_bits`. Generally, the M0 will have trouble loading images into memory because the heap is only ~20k or so.

tannewt
 
Posts: 1716
Joined: Thu Oct 06, 2016 8:48 pm

Please be positive and constructive with your questions and comments.