0

Gemma M0 Test Code for Neopixels
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Gemma M0 Test Code for Neopixels

by jeremyzschau on Tue Jul 09, 2019 7:38 pm

Is there test code available for Gemma M0 to test neopixels?

jeremyzschau
 
Posts: 111
Joined: Fri Feb 27, 2015 11:00 pm

Re: Gemma M0 Test Code for Neopixels

by adafruit_support_carter on Tue Jul 09, 2019 8:36 pm


adafruit_support_carter
 
Posts: 12675
Joined: Tue Nov 29, 2016 2:45 pm

Re: Gemma M0 Test Code for Neopixels

by jeremyzschau on Thu Jul 11, 2019 6:07 pm

Thank you so much. I am trying to test 8 neopixels connected to gemma M0. I use a MacBook Pro version 10.13.6. I use Mu-Editor to copy and save the code. I only get a solid purple LED on the gemma when I tried adding this code. The neopixels are off.

Code: Select all | TOGGLE FULL SIZE
import time
import board
import neopixel


# On CircuitPlayground Express, and boards with built in status NeoPixel -> board.NEOPIXEL
# Otherwise choose an open pin connected to the Data In of the NeoPixel strip, i.e. board.D1
pixel_pin = board.NEOPIXEL

# On a Raspberry pi, use this instead, not all pins are supported
#pixel_pin = board.D18

# The number of NeoPixels
num_pixels = 8

# The order of the pixel colors - RGB or GRB. Some NeoPixels have red and green reversed!
# For RGBW NeoPixels, simply change the ORDER to RGBW or GRBW.
ORDER = neopixel.GRB

pixels = neopixel.NeoPixel(pixel_pin, num_pixels, brightness=0.2, auto_write=False,
                           pixel_order=ORDER)


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:
        r = g = b = 0
    elif pos < 85:
        r = int(pos * 3)
        g = int(255 - pos*3)
        b = 0
    elif pos < 170:
        pos -= 85
        r = int(255 - pos*3)
        g = 0
        b = int(pos*3)
    else:
        pos -= 170
        r = 0
        g = int(pos*3)
        b = int(255 - pos*3)
    return (r, g, b) if ORDER == neopixel.RGB or ORDER == neopixel.GRB else (r, g, b, 0)


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


while True:
    # Comment this line out if you have RGBW/GRBW NeoPixels
    pixels.fill((255, 0, 0))
    # Uncomment this line if you have RGBW/GRBW NeoPixels
    # pixels.fill((255, 0, 0, 0))
    pixels.show()
    time.sleep(1)

    # Comment this line out if you have RGBW/GRBW NeoPixels
    pixels.fill((0, 255, 0))
    # Uncomment this line if you have RGBW/GRBW NeoPixels
    # pixels.fill((0, 255, 0, 0))
    pixels.show()
    time.sleep(1)

    # Comment this line out if you have RGBW/GRBW NeoPixels
    pixels.fill((0, 0, 255))
    # Uncomment this line if you have RGBW/GRBW NeoPixels
    # pixels.fill((0, 0, 255, 0))
    pixels.show()
    time.sleep(1)

    rainbow_cycle(0.001)    # rainbow cycle with 1ms delay per step
Attachments
Screen Shot 2019-07-12 at 6.57.06 AM.png
Screen Shot 2019-07-12 at 6.57.06 AM.png (66.3 KiB) Viewed 229 times

jeremyzschau
 
Posts: 111
Joined: Fri Feb 27, 2015 11:00 pm

Re: Gemma M0 Test Code for Neopixels

by adafruit_support_carter on Thu Jul 11, 2019 6:29 pm

Can you post a photo showing how you have the NeoPixels attached to the Gemma M0.

adafruit_support_carter
 
Posts: 12675
Joined: Tue Nov 29, 2016 2:45 pm

Re: Gemma M0 Test Code for Neopixels

by jeremyzschau on Thu Jul 11, 2019 6:43 pm

All neopixels did light up before but different code I was using before stopped working for whatever reason. I want to at least get code consistently working before I solder some parts and continue sewing the scarf.
Attachments
IMG_7503.jpg
IMG_7503.jpg (309.01 KiB) Viewed 224 times

jeremyzschau
 
Posts: 111
Joined: Fri Feb 27, 2015 11:00 pm

Re: Gemma M0 Test Code for Neopixels

by caitlinsdad on Thu Jul 11, 2019 7:40 pm

I can't tell from the pic but see what pin you have wired for the data to the neopixels.
The code has to be changed to
Code: Select all | TOGGLE FULL SIZE
pixel_pin = board.A1
or board.A2 or board.A0 what you are using. In CircuitPython, I haven't figured out if referencing the pin numbers by just the number or D1... works but the A# name takes.

Look through https://learn.adafruit.com/adafruit-gem ... -next-step for coding the lights on the Gemma M0 board itself. It's actually a DOTSTAR instead of a neopixel there so a slight change in the configuration line. You should be able to set it off if that purple status light is not needed.

Good luck.

caitlinsdad
 
Posts: 573
Joined: Fri Feb 24, 2012 4:23 pm

Re: Gemma M0 Test Code for Neopixels

by adafruit_support_carter on Thu Jul 11, 2019 11:04 pm

Yep, need to change the pin. Was hoping could just check that from the photo so could tell you which one. But I can't quite make it out either.

The other thing you may want to do is change the name of the file you are saving the code to. There are only a few special file names that are checked for to be run automatically:
https://learn.adafruit.com/welcome-to-c ... -file-7-32

adafruit_support_carter
 
Posts: 12675
Joined: Tue Nov 29, 2016 2:45 pm

Re: Gemma M0 Test Code for Neopixels

by jeremyzschau on Sat Jul 13, 2019 10:26 pm

Close.
Attachments
IMG_7513.jpg
IMG_7513.jpg (402.32 KiB) Viewed 173 times

jeremyzschau
 
Posts: 111
Joined: Fri Feb 27, 2015 11:00 pm

Re: Gemma M0 Test Code for Neopixels

by adafruit_support_carter on Mon Jul 15, 2019 12:10 pm

Your on A0, so change this line:
Code: Select all | TOGGLE FULL SIZE
    pixel_pin = board.NEOPIXEL

to this:
Code: Select all | TOGGLE FULL SIZE
    pixel_pin = board.A0

adafruit_support_carter
 
Posts: 12675
Joined: Tue Nov 29, 2016 2:45 pm

Re: Gemma M0 Test Code for Neopixels

by jeremyzschau on Mon Jul 15, 2019 5:38 pm

A few neopixels remain on. I am still trying to get all to light up in a test cycle such as the rainbow cycle.

Code: Select all | TOGGLE FULL SIZE
import time
import board
import neopixel


# On CircuitPlayground Express, and boards with built in status NeoPixel -> board.NEOPIXEL
# Otherwise choose an open pin connected to the Data In of the NeoPixel strip, i.e. board.D1
pixel_pin = board.A0

# On a Raspberry pi, use this instead, not all pins are supported
#pixel_pin = board.D18

# The number of NeoPixels
num_pixels = 8

# The order of the pixel colors - RGB or GRB. Some NeoPixels have red and green reversed!
# For RGBW NeoPixels, simply change the ORDER to RGBW or GRBW.
ORDER = neopixel.GRB

pixels = neopixel.NeoPixel(pixel_pin, num_pixels, brightness=0.2, auto_write=False,
                           pixel_order=ORDER)


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:
        r = g = b = 0
    elif pos < 85:
        r = int(pos * 3)
        g = int(255 - pos*3)
        b = 0
    elif pos < 170:
        pos -= 85
        r = int(255 - pos*3)
        g = 0
        b = int(pos*3)
    else:
        pos -= 170
        r = 0
        g = int(pos*3)
        b = int(255 - pos*3)
    return (r, g, b) if ORDER == neopixel.RGB or ORDER == neopixel.GRB else (r, g, b, 0)


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


while True:
    # Comment this line out if you have RGBW/GRBW NeoPixels
    pixels.fill((255, 0, 0))
    # Uncomment this line if you have RGBW/GRBW NeoPixels
    # pixels.fill((255, 0, 0, 0))
    pixels.show()
    time.sleep(1)

    # Comment this line out if you have RGBW/GRBW NeoPixels
    pixels.fill((0, 255, 0))
    # Uncomment this line if you have RGBW/GRBW NeoPixels
    # pixels.fill((0, 255, 0, 0))
    pixels.show()
    time.sleep(1)

    # Comment this line out if you have RGBW/GRBW NeoPixels
    pixels.fill((0, 0, 255))
    # Uncomment this line if you have RGBW/GRBW NeoPixels
    # pixels.fill((0, 0, 255, 0))
    pixels.show()
    time.sleep(1)

    rainbow_cycle(0.001)    # rainbow cycle with 1ms delay per step

jeremyzschau
 
Posts: 111
Joined: Fri Feb 27, 2015 11:00 pm

Re: Gemma M0 Test Code for Neopixels

by adafruit_support_carter on Mon Jul 15, 2019 5:47 pm

You are looping and writing to the NeoPixels, so they will generally stay on. Not sure I follow what you mean by "A few neopixels remain on". That seems expected.

adafruit_support_carter
 
Posts: 12675
Joined: Tue Nov 29, 2016 2:45 pm

Re: Gemma M0 Test Code for Neopixels

by jeremyzschau on Mon Jul 15, 2019 5:50 pm

I am trying to get all 8 connected neopixels to rainbow cycle. 3 Neopixels randomly turn on and do not cycle. They remain on unchanging color.

jeremyzschau
 
Posts: 111
Joined: Fri Feb 27, 2015 11:00 pm

Re: Gemma M0 Test Code for Neopixels

by adafruit_support_carter on Mon Jul 15, 2019 6:32 pm

Sounds like a possible wiring issue. Try writing a program that just fills the pixels with a solid color. Use that to test wiring - you'll know it's good when you get all NeoPixels to light up the solid color.

adafruit_support_carter
 
Posts: 12675
Joined: Tue Nov 29, 2016 2:45 pm

Re: Gemma M0 Test Code for Neopixels

by jeremyzschau on Mon Jul 15, 2019 7:27 pm

The neopixel is solid white. No cycle. My goal now is to get one neopixel on alligator clips to rainbow cycle.
Attachments
IMG_7524.JPG
IMG_7524.JPG (154.83 KiB) Viewed 126 times

jeremyzschau
 
Posts: 111
Joined: Fri Feb 27, 2015 11:00 pm

Re: Gemma M0 Test Code for Neopixels

by caitlinsdad on Mon Jul 15, 2019 7:57 pm

You might want to try powering the neopixels with the Vout instead of the 3v pad. I would also copy over the test code from the guide (you have some typos pos*3 vs pos * 3 which might be interpreted different in circuitpython for bitwise operations) also, I've haven't needed to use the RGB order declaration, maybe accounted for in the latest version of circuitpython and the corresponding update neopixel library for it which have been updated frequently.

https://learn.adafruit.com/adafruit-gem ... neopixel-2

caitlinsdad
 
Posts: 573
Joined: Fri Feb 24, 2012 4:23 pm

Please be positive and constructive with your questions and comments.