Background: I purchased a http://rasp.io/inspiring/ set of leds when the kickstarter was launched a couple of years ago.
They are basically SK9822 leds in various shapes, straight 8, triangle of 24 and circle of 24 leds, like neopixels but these use the SPI interface.
For the PI a python library was created, https://github.com/windy54/raspio-inspi ... ter/apa.py
I ported this across to the microbit https://github.com/windy54/raspio-inspi ... spiring.py
It works on the microbit for up to 64 leds, as soon as I select 65 the software crashes. After some investigation it runs out of memory on the line self.led_values in the original code snippet below.
Code: Select all
class Apa(object):
def __init__(self, numleds):
self.numleds = numleds
self.led_values = [] # initialise a list for LED values
for y in range(numleds):
self.led_values.append([0xE0, 0x00, 0x00, 0x00])
Code: Select all
class Apa:
def __init__(self, num_leds):
self.buffer = bytearray(4)
self.leds = [array.array('b',[0xE0, 0, 0x0, 0]) for i in range(num_leds)]
I tried the same construct on a PI to see how much memory is used for each element and it seems to be
32 + num_leds*4 bytes. Which is what I expected, i.e. 32 bytes as reference for the object and 4 bytes per element.
On the microbit it seems to use 32 bytes per element. I used memfree() to monitor the memory and with 64 leds there is about 20 bytes left, 65 causes the crash when it runs out of memory.
Apologies for the length of the post, I thought it important to show what I have been doing.
I guess my questions are:
- Is there something wrong with the code, a better way to create the self.led_values?
Have I found a bug in the microbit micropython code?
Thanks to another post on the web I have managed to control 136 leds from a microbit. https://github.com/windy54/raspio-inspi ... piring2.py
windy54