import neopixel - less of em work now.

Questions and discussion about running MicroPython on a micro:bit board.
Target audience: MicroPython users with a micro:bit.
Post Reply
MarbleMad
Posts: 2
Joined: Sat Sep 10, 2016 12:40 am

import neopixel - less of em work now.

Post by MarbleMad » Sat Sep 10, 2016 12:50 am

Earlier in the year i wrote some code to control about 252 neopixels. This was the maximum i could get to work before things got glitchy.
I've dug the project out again for an event today and after some insiginificant changes, the code no longer works. I've found the unmodified version now displays rubbish on the built in led matrix and the only way to get things going again is to reduce the number of neopixels to about 130 !
Any idea what's happened here? Stupidly i've not kept my original hex file. Is there a way to roll back the compiler to where it stood in march? or can anyone offer some other workaround? Need more LEDs.

Thanks.

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: import neopixel - less of em work now.

Post by deshipu » Sat Sep 10, 2016 2:04 am

Really hard to say anything without seeing the code.

However, did you know that the micro:bit has a library for neopixels built-in?

MarbleMad
Posts: 2
Joined: Sat Sep 10, 2016 12:40 am

Re: import neopixel - less of em work now.

Post by MarbleMad » Sat Sep 10, 2016 8:34 am

"""

Here's the code, note the original commented out "pixamount = 36*7" used to work but now i have to reduce it to 22*7.,
neopixel_random.py

Repeatedly displays random colours onto the LED strip.
This example requires a strip of 8 Neopixels (WS2812) connected to pin0.

"""
from microbit import *
import neopixel
from random import randint

# Setup the Neopixel strip on pin0 with a length of 8 pixels

#pixamount = 36*7
#np1 = neopixel.NeoPixel(pin0, pixamount)
pixamount = 22*7
np1 = neopixel.NeoPixel(pin2, pixamount)

#neopixel array length
lPixels = [1,2,3,4,5,6,7]
#lPixels = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]
#18 columns
lColumn = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,18]
#lColumn = [1,2]
#3 rows
lRow = [1,2,3]
#lRow = [1]

#
iRows=2
iColumns=18
iPixels=7
iDelay=500

#neopixel pattern (colour indexes)
lPattern1 = [0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0]
lPattern2 = [0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2]

#rgb colour tables
#red,orange,yellow
lColours1 = [(16, 0, 0),(14, 1, 0),(12, 3, 0)]

#red,green,blue
lColours2 = [(60, 0, 0),(0, 60, 0),(0, 0, 60)]
#lColours3 = [(60, 0, 0),(0, 60, 0),(0, 0, 60)]

#red,yellow,red columns - slow left
lColoursLS = [(12, 0, 0),(10, 0, 0),(8, 0, 0),(6, 0, 0),(6, 0, 0),(8, 0, 0),(10, 0, 0)]
#red,magenta,red columns - slow rhs
lColoursRS = [(0, 12, 0),(0, 10, 60),(0, 8, 0),(0, 6, 0),(0, 6, 0),(0, 8, 0),(0, 10, 0)]

#green,blue,green- fast left
lColoursRF = [(0, 12, 0),(0, 10, 2),(0, 8, 4),(0, 6, 5),(0, 6, 0),(0, 8, 4),(0, 10, 2)]
#green,red,green- fast right
lColoursLF = [(12, 0, 0),(10, 0, 2),(8, 0, 4),(6, 0, 5),(6, 0, 0),(8, 0, 4),(10, 0, 2)]


#copy colour to neopixel
def CopyCol(iRow,iColumn,cColour):
iIndex=0
#iIndex = (iRow * (len(lColumn) * len(lPixels))) + (iColumn * len(lPixels))
iIndex = (iRow * (iColumns * iPixels)) + (iColumn * iPixels)
for iPixel in range(0, len(lPixels)):
iPix = iIndex + iPixel
if iPix < pixamount:
np1[iPix] = cColour
#else:
#np2[iPix-252] = cColour
return

#copy pattern to neopixel
def CopyPtn(iRow,iColumn,lPtn,lColours):
iIndex=0
iIndex = (iRow * (iColumns * iPixels)) + (iColumn * iPixels)
#for iPixel in range(0, len(lPtn)):
for iPixel in range(0, len(lPixels)):
iPtnC=0
iPtnC = int(lPtn[iPixel])
col = lColours[iPtnC]
iPix = iIndex + iPixel
if iPix < pixamount:
np1[iPix] = col
#else:
#np2[iPix-252] = col
return


def DoAnimLR(iCIndex):

#left to right
for iColumn in range(0, 18):
if (iVari==0):
cCol = lColoursLS[((iCIndex + iColumn) % 7)]
elif(iVari==1):
cCol = lColoursRS[((iCIndex + iColumn) % 7)]
elif(iVari==2):
cCol = lColoursLF[((iCIndex + iColumn) % 7)]
elif(iVari==3):
cCol = lColoursRF[((iCIndex + iColumn) % 7)]

for iRow in range(0, 3):
iIndex=0
iIndex = (iRow * (iColumns * iPixels)) + (iColumn * iPixels)
for iPixel in range(0, len(lPixels)):
iPix = iIndex + iPixel
if iPix < pixamount:
np1[iPix] = cCol
#else:
#np2[iPix-252] = cCol


return


def DoAnimUD(iCIndex):

#up/down
for iRow in range(0, iRows):
cCol = lColours1[((iCIndex + iRow) % 3)]
for iColumn in range(0, iColumns):
iIndex=0
iIndex = (iRow * (iColumns * iPixels)) + (iColumn * iPixels)
for iPixel in range(0, len(lPixels)):
iPix = iIndex + iPixel
if iPix < pixamount:
np1[iPix] = cCol
#else:
#np2[iPix-252] = cCol

return


iIndex=0
iCount =0

display.show(Image.SKULL)

boolMoved = False
iVal = 0
iAX = 0
iCIndex = 0
iAnimCount = 0
iColumn = 0
iRow = 0
iAnimCount = 0
iStepCount = 0
iFrame=0
iMode=0
iMod = 4

iVari=randint(0,1)

display.show(Image.SKULL)

while True:

if (iAnimCount == 0):

iAX = accelerometer.get_x()

iMode = 0
iMod = 4

if iAX > 150:
iVal = iAX
iMode = 1
iMod = 4
iVari=0
if (iAnimCount == 0):
iAnimCount = 30
display.show(Image.DIAMOND)

if iAX < -150:
iVal = iAX
iMode = 1
iMod = 4
iVari=1
if (iAnimCount == 0):
iAnimCount = 30
display.show(Image.DIAMOND)

if iAX > 300:
iMode = 1
iMod = 2
iVari=2

if iAX < -300:
iMode = 1
iMod = 2
iVari=3


else:
iAX = 0


if (iMode == 0):
DoAnimUD(iCIndex)
elif (iMode == 1):
DoAnimLR(iCIndex)


#if iFrame
np1.show()
#np2.show()

if (iVal > 0):
if (iFrame % iMod) == 0:
iCIndex = iCIndex-1

if (iVal < 0):
if (iFrame % iMod) == 0:
iCIndex = iCIndex+1


if (iAnimCount > 0):
iAnimCount = iAnimCount -1

if (iAnimCount == 1):
display.show(Image.SKULL)

#inc frame counter
iFrame = iFrame + 1

Post Reply