0

Gemma M0 Test Code for Neopixels
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Re: Gemma M0 Test Code for Neopixels

by adafruit_support_carter on Mon Jul 15, 2019 8:23 pm


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

Re: Gemma M0 Test Code for Neopixels

by jeremyzschau on Mon Jul 29, 2019 11:13 pm

The neopixel remains solid white plugged into computer and off when the gemma is disconnected and powered by battery. I changed the power connection to Vout.


Code: Select all | TOGGLE FULL SIZE
# CircuitPython demo - NeoPixel
import time
import board
import neopixel

pixel_pin = board.A1
num_pixels = 1

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(2)  # Increase the number to slow down the rainbow
Attachments
Screen Shot 2019-07-30 at 12.04.44 PM.png
Screen Shot 2019-07-30 at 12.04.44 PM.png (37.7 KiB) Viewed 147 times

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

Re: Gemma M0 Test Code for Neopixels

by jeremyzschau on Mon Jul 29, 2019 11:57 pm

When I check it says this line is too long. Is that a problem?
Attachments
Screen Shot 2019-07-30 at 12.51.31 PM.png
Screen Shot 2019-07-30 at 12.51.31 PM.png (185.69 KiB) Viewed 145 times

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

Re: Gemma M0 Test Code for Neopixels

by adafruit_support_carter on Tue Jul 30, 2019 10:58 am

You can generally ignore the long line message. It's just an aesthetic thing. Long lines can be hard to read in some text editors since the end of the line can be off screen.

Your first screen shot of the folder contents shows main.py. Your other screen shot of the mu editor shows neopixel_pixel.py. Which filename are you using?

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

Re: Gemma M0 Test Code for Neopixels

by jeremyzschau on Tue Jul 30, 2019 8:14 pm

Sorry here is the most current screenshot. File is called neopixel_pixel.py

I am using Mu-Editor.

1. double click gemma loading button drag adafruit-circuitpython-gemma_m0-3.0.3.uf2 file into gemma.
2. ?
3. ?
single neopixel rainbow cycle

Code: Select all | TOGGLE FULL SIZE
# CircuitPython demo - NeoPixel
import time
import board
import neopixel

pixel_pin = board.A1
num_pixels = 1

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(2)  # Increase the number to slow down the rainbow
Attachments
Screen Shot 2019-07-31 at 9.07.32 AM.png
Screen Shot 2019-07-31 at 9.07.32 AM.png (86.5 KiB) Viewed 128 times

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

Re: Gemma M0 Test Code for Neopixels

by adafruit_support_carter on Wed Jul 31, 2019 1:17 pm

1. double click gemma loading button drag adafruit-circuitpython-gemma_m0-3.0.3.uf2 file into gemma.

This is how you would do a CircuitPython firmware update. You don't need to do that every time you change or add code on your board. You only need to do that to upgrade the version of CircuitPython you are running on the Gemma. And you would get that firmware (.uf2 file) here:
https://circuitpython.org/board/gemma_m0/

The other thing to watch is the filename. To have the code run automatically, you need to save it to one of these names:
https://learn.adafruit.com/welcome-to-c ... -file-7-32

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

Re: Gemma M0 Test Code for Neopixels

by jeremyzschau on Thu Aug 01, 2019 12:18 am

I am very sorry. Thank you for your help but there is no change. The neopixel is still solid white. Here are my steps.

1. (first time only) double click gemma drag adafruit-circuitpython-gemma_m0-en_US-4.0.2.uf2 file into gemma.
2. Mu Editor on Mac file chosen neopixel_simpletest.py
3. save file as code.py
goal: single neopixel 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.NEOPIXEL

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

# The number of NeoPixels
num_pixels = 1

# 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-08-01 at 1.07.23 PM.png
Screen Shot 2019-08-01 at 1.07.23 PM.png (54.3 KiB) Viewed 109 times
Screen Shot 2019-08-01 at 1.11.24 PM.png
Screen Shot 2019-08-01 at 1.11.24 PM.png (389.71 KiB) Viewed 109 times

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

Re: Gemma M0 Test Code for Neopixels

by adafruit_support_carter on Thu Aug 01, 2019 12:32 pm

Ooooohhhhh. The RGB LED on the Gemma is a DotStar, not a NeoPixel. Sorry, should have spotted that sooner.

Try the code here:
https://learn.adafruit.com/adafruit-gem ... e-em-11-10

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

Re: Gemma M0 Test Code for Neopixels

by jeremyzschau on Thu Aug 01, 2019 6:49 pm

After saving the code to gemma the neopixel does not illuminate.
Attachments
Screen Shot 2019-08-02 at 7.42.50 AM.png
Screen Shot 2019-08-02 at 7.42.50 AM.png (363.92 KiB) Viewed 85 times

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

Re: Gemma M0 Test Code for Neopixels

by adafruit_support_carter on Thu Aug 01, 2019 7:07 pm

Can you clarify what you are trying to control at this point:
(1) The RGB LED that is on the Gemma M0 board (i.e. the built in DotStar)
(2) The RGB LED that you have attached to A1 via conductive thread (i.e, the NeoPixel)

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

Re: Gemma M0 Test Code for Neopixels

by jeremyzschau on Thu Aug 01, 2019 7:19 pm

I am trying to control the neopixel. The image shows it attached to D1 but I tried connecting it to A1 and there was no result.
Attachments
IMG_7583.jpg
IMG_7583.jpg (300.35 KiB) Viewed 82 times

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

Re: Gemma M0 Test Code for Neopixels

by adafruit_support_carter on Thu Aug 01, 2019 8:21 pm

Ah, OK. Sorry, I got confused by the use of board.NEOPIXEL. It looked like you were trying to use the on board LED.

For the pin arrangement you show, using D1, try this:
Code: Select all | TOGGLE FULL SIZE
# CircuitPython demo - NeoPixel
import time
import board
import neopixel

pixel_pin = board.D1
num_pixels = 1

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

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

Re: Gemma M0 Test Code for Neopixels

by jeremyzschau on Fri Aug 02, 2019 2:50 am

Thank you so much Carter for your patience. I noticed with my old working gemma the tiny red L LED light on the gemma, not neopixels, continuously blinks meaning that data is successfully being transmitted to the neopixels. With the gemma M0 the red L LED blinks for a few moments then goes out. In the moments it does blink the connected neopixels illuminate but remain on the color they first illuminate as and do not cycle through rainbow colors. These images are the code you provided. I changed the number of LEDs to 8 for the 8 connected to the gemma.
Attachments
IMG_7590.jpg
IMG_7590.jpg (345.6 KiB) Viewed 64 times
IMG_7589.jpg
IMG_7589.jpg (317.85 KiB) Viewed 64 times
IMG_7588.jpg
IMG_7588.jpg (311.19 KiB) Viewed 64 times

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

Re: Gemma M0 Test Code for Neopixels

by adafruit_support_carter on Fri Aug 02, 2019 10:29 am

The RGB LED (DotStar) on the Gemma M0 also acts as a status indicator:
https://learn.adafruit.com/welcome-to-c ... ight-20-18

In your photos it appears to be purple. Is it steady purple? Or is it blinking?

A steady purple seems odd. I would expect it to be green to indicate that your code.py is running.

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

Re: Gemma M0 Test Code for Neopixels

by jeremyzschau on Fri Aug 02, 2019 9:08 pm

It's steady purple.

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

Please be positive and constructive with your questions and comments.