This is the panel: https://www.amazon.com/BTF-LIGHTING-0-2 ... 01DC0IPVU/
Using CircuitPython 3.x files and mu-editor on macOS.
Problem: constant memory errors
I have a bit of programming experience but am completely new to Python and programming LEDs in general. I'm trying to display text characters on an 256 x 8 LED panel. For lack of finding an existing library or code, I'm manually creating the character shapes, which is working to some extent, but I continue to run into memory errors. I can't tell if these are caused by my poor coding, or the limits of the Express board. And I've suddenly started getting recurring errors with the statement "pixels.show()". Every time I save code to the board, even if the code appears to run, I get some variation of the following errors in the serial console, always with the neopixel library:
Code: Select all
Traceback (most recent call last):
File "code.py", line 97, in <module>
File "neopixel.py", line 232, in show
File "neopixel.py", line 232, in <listcomp>
MemoryError: memory allocation failed, allocating 4096 bytes
Code: Select all
MemoryError: memory allocation failed, allocating 4096 bytes
Thanks in advance for for any advice/suggestions/corrections.
- Scott
Code: Select all
import board
import time
import neopixel
import random
import math
pixel_pin = board.A1
num_pixels = 256
how_bright = 0.1
pixels = neopixel.NeoPixel(pixel_pin, num_pixels, brightness=how_bright, auto_write=False)
red = (255, 0, 0)
yellow = (255, 150, 0)
green = (0, 255, 0)
cyan = (0, 255, 255)
blue = (0, 0, 255)
purple = (180, 0, 255)
orange = (240, 80, 0)
white = (255,255,255)
black = (0, 0, 0)
charA = (2,3,4,5,6,7,11,14,16,20,27,30,34,35,36,37,38,39)
charB = (0,1,2,3,4,5,6,7,8,12,15,16,19,23,24,28,31,33,34,36,37,38)
charC = (1,2,3,4,5,6,8,15,16,23,24,31,33,38)
charD = (0,1,2,3,4,5,6,7,8,15,16,23,24,31,33,34,35,36,37,38)
charE = (0,1,2,3,4,5,6,7,8,12,15,16,19,23,24,31,32,39)
charF = (0,1,2,3,4,5,6,7,12,15,16,19,31,32)
charG = (1,2,3,4,5,6,8,15,16,20,23,24,27,31,33,36,37,38)
charH = (0,1,2,3,4,5,6,7,12,19,28,32,33,34,35,36,37,38,39)
charI = (0,7,8,9,10,11,12,13,14,15,16,23)
charJ = (6,8,23,24,32,33,34,35,36,37,38)
charK = (0,1,2,3,4,5,6,7,11,12,18,21,25,30,32,39)
charL = (0,1,2,3,4,5,6,7,8,23,24,39)
charM = (0,1,2,3,4,5,6,7,14,18,30,32,33,34,35,36,37,38,39)
charN = (0,1,2,3,4,5,6,7,13,14,19,20,25,26,32,33,34,35,36,37,38,39)
charO = (1,2,3,4,5,6,8,15,16,23,24,31,33,34,35,36,37,38)
charP = (0,1,2,3,4,5,6,7,11,15,16,20,27,31,33,34,35)
charQ = (1,2,3,4,5,6,8,15,16,21,23,25,31,33,34,35,36,37,39)
charR = (0,1,2,3,4,5,6,7,11,15,16,20,26,27,31,33,34,35,38,39)
charS = (1,2,6,8,12,15,16,19,23,24,28,31,33,36,37,38)
charT = (0,15,16,17,18,19,20,21,22,23,31,32)
charU = (0,1,2,3,4,5,6,8,23,24,32,33,34,35,36,37,38)
charV = (0,1,2,3,4,5,9,23,25,32,33,34,35,36,37)
charW = (0,1,2,3,4,5,6,7,9,21,25,32,33,34,35,36,37,38,39)
charX = (0,1,6,7,10,13,19,20,26,29,32,33,38,39)
charY = (0,1,2,12,20,21,22,23,28,32,33,34)
charZ = (0,5,6,7,8,11,15,16,19,23,24,29,31,32,33,39)
char0 = (1,2,3,4,5,6,8,13,14,15,16,19,20,23,24,25,26,31,33,34,35,36,37,38)
char1 = (1,7,8,15,16,17,18,19,20,21,22,23,24,39)
char2 = (1,6,7,8,10,15,16,20,23,24,28,31,33,34,39)
char3 = (1,6,8,15,16,19,23,24,28,31,33,34,36,37,38)
char4 = (3,4,11,13,17,20,24,25,26,27,28,29,30,31,36)
char5 = (0,1,2,3,6,8,12,15,16,19,23,24,28,31,32,36,37,38)
char6 = (1,2,3,4,5,6,8,12,15,16,19,23,24,28,31,33,36,37,38)
char7 = (0,6,7,10,15,16,20,28,31,32,33,34)
char8 = (1,2,4,5,6,8,12,15,16,19,23,24,28,31,33,34,36,37,38)
char9 = (1,2,3,6,8,11,15,16,20,23,24,27,31,33,34,35,36,37,38)
charSpace = (0,1,2,3,4,5,6,7)
def do_reset():
pixels.fill(black)
pixels.show()
def do_sleep():
time.sleep(0.001)
def get_rand():
return random.randint(0, 255)
def display_word(pWord,pColor):
pixelCharWidth = 0
charOffset = 0
theColor = pColor
wordLength = len(pWord)
for c in range(wordLength):
if pWord[c].isspace():
#SPACE
pixelCharValues = charSpace
theColor = black
else:
#CHARACTER
pixelCharValues = eval("char" + pWord[c])
theColor = pColor
# RENDER CHARACTER
for i in range(len(pixelCharValues)):
pixels[pixelCharValues[i]+charOffset] = theColor
#
# ADD CHARACTER WIDTH TO OVERALL PIXEL STRING WIDTH
charOffset += (int(pixelCharValues[len(pixelCharValues) - 1]/8 + 2) * 8)
while True:
display_word("TEST",black)
pixels.show()
# do_reset()