0

NeoPixel example code no longer working under 6.3
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

NeoPixel example code no longer working under 6.3

by Ahate on Sat Sep 18, 2021 9:54 am

Hi all! I‘m new to CircuitPython but not to coding in general. I tried the NeoPixel example code (https://learn.adafruit.com/adafruit-trinket-m0-circuitpython-arduino/circuitpython-neopixel) on my new Trinket M0 to power up an LED strip and it worked fine right out of the box. After that I realized that the CircuitPython version is probably not up to date since I didn‘t update it after unboxing the Trinket M0. I updated the version as described by the website and my code was no longer working afterwards.

When I connect the board the LED is lighting up green and yellow (or might be orange), turns off for half a second and flashes cyan four times. Line 4 in the code is import neopixel. When I enter a blank line before that line, the LED flashes 5 times. So I guess, the problem has something to do with the neopixel library?

Things I already tried:
- updating CircuitPython to 6.3 again
- updating the UF2 Bootloader from 2.0 to 3.13.0
- re-downloading neopixel.mpy in lib and deleting it altogether (no difference if present or not)
- putting an older version of neopixel.mpy in lib (resulted in green/purple error indicator)

I ran out of things to try and hope that you guys might have an idea what I could do here.

Here is the code for reference:
Code: Select all | TOGGLE FULL SIZE
 """CircuitPython Essentials NeoPixel example"""
import time
import board

import neopixel

pixel_pin = board.A1
num_pixels = 8

pixels = neopixel.NeoPixel(pixel_pin, num_pixels, brightness=0.3, auto_write=False)


def wheel(pos):
    # Input a value 0 to 255 to get a color value.
    # The colours are a transition r - g - b - back to r.
    if pos < 0 or pos > 255:
        return (0, 0, 0)
    if pos < 85:
        return (255 - pos * 3, pos * 3, 0)
    if pos < 170:
        pos -= 85
        return (0, 255 - pos * 3, pos * 3)
    pos -= 170
    return (pos * 3, 0, 255 - pos * 3)


def color_chase(color, wait):
    for i in range(num_pixels):
        pixels[i] = color
        time.sleep(wait)
        pixels.show()
    time.sleep(0.5)


def rainbow_cycle(wait):
    for j in range(255):
        for i in range(num_pixels):
            rc_index = (i * 256 // num_pixels) + j
            pixels[i] = wheel(rc_index & 255)
        pixels.show()
        time.sleep(wait)


RED = (255, 0, 0)
YELLOW = (255, 150, 0)
GREEN = (0, 255, 0)
CYAN = (0, 255, 255)
BLUE = (0, 0, 255)
PURPLE = (180, 0, 255)

while True:
    pixels.fill(RED)
    pixels.show()
    # Increase or decrease to change the speed of the solid color change.
    time.sleep(1)
    pixels.fill(GREEN)
    pixels.show()
    time.sleep(1)
    pixels.fill(BLUE)
    pixels.show()
    time.sleep(1)

    color_chase(RED, 0.1)  # Increase the number to slow down the color chase
    color_chase(YELLOW, 0.1)
    color_chase(GREEN, 0.1)
    color_chase(CYAN, 0.1)
    color_chase(BLUE, 0.1)
    color_chase(PURPLE, 0.1)

    rainbow_cycle(0)  # Increase the number to slow down the rainbow


Thanks alot!!

Ahate
 
Posts: 2
Joined: Sat Sep 18, 2021 9:23 am

Re: NeoPixel example code no longer working under 6.3

by dastels on Sat Sep 18, 2021 11:53 am

The first thing to do when you get the flashing multicolored status (which indicates an error) is to get into the REPL and run the code. You'll get some useful information. Copy it and post it here.

If you aren't familiar with using the REPL (or even just the serial connection), see
https://learn.adafruit.com/welcome-to-circuitpython/kattni-connecting-to-the-serial-console
https://learn.adafruit.com/welcome-to-circuitpython/interacting-with-the-serial-console
https://learn.adafruit.com/welcome-to-circuitpython/the-repl

Make sure you have neopixel.mpy from the version of the bundle that matches the version of CircuitPython you are using. So if you're still using CP6.3, then use the 6.x library from https://circuitpython.org/libraries.

When you delete libraries, I find it useful to empty trash as well to get rid on anything that might be lingering.

Dave

dastels
 
Posts: 7493
Joined: Tue Oct 20, 2015 3:22 pm

Re: NeoPixel example code no longer working under 6.3

by Ahate on Sat Sep 18, 2021 2:01 pm

The REPL is a great tip! Wasn‘t aware of that. It seems there was another library missing (adafruit_pypixelbuf), that I didn‘t knew existed. Added it and everything is working properly now.

Thanks for the help!

Ahate
 
Posts: 2
Joined: Sat Sep 18, 2021 9:23 am

Re: NeoPixel example code no longer working under 6.3

by dastels on Sat Sep 18, 2021 2:43 pm

Oh yes, that's right. It's required on some boards. The smaller ones (or maybe M0 ones).

Dave

dastels
 
Posts: 7493
Joined: Tue Oct 20, 2015 3:22 pm

Please be positive and constructive with your questions and comments.


cron