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 jeremyzschau on Sat Aug 31, 2019 9:00 pm

Typing the commands in the serial window does cause the neopixel to turn red. I just did it again.
Attachments
Screen Shot 2019-09-01 at 9.53.14 AM.png
Screen Shot 2019-09-01 at 9.53.14 AM.png (147.47 KiB) Viewed 100 times

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

Re: Gemma M0 Test Code for Neopixels

by adafruit_support_carter on Tue Sep 03, 2019 12:41 pm

Cool, so the hardware is still functional. In the code you were having issues with, take a close look at what pin you are specifying for the NeoPixel pin.

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

Re: Gemma M0 Test Code for Neopixels

by jeremyzschau on Tue Sep 03, 2019 4:46 pm

The D1 pin.

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

Re: Gemma M0 Test Code for Neopixels

by adafruit_support_carter on Tue Sep 03, 2019 5:38 pm

pin.png
pin.png (38.53 KiB) Viewed 83 times

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

Re: Gemma M0 Test Code for Neopixels

by jeremyzschau on Tue Sep 03, 2019 6:00 pm

This is the code as of now.
Code: Select all | TOGGLE FULL SIZE
# Simple test for NeoPixels on Raspberry Pi
import time
import board
import neopixel


# Choose an open pin connected to the Data In of the NeoPixel strip, i.e. board.D18
# NeoPixels must be connected to D10, D12, D18 or D21 to work.
pixel_pin = board.D1

# 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 ste

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

Re: Gemma M0 Test Code for Neopixels

by adafruit_support_carter on Tue Sep 03, 2019 6:04 pm

What filename are you saving that as?

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

Re: Gemma M0 Test Code for Neopixels

by jeremyzschau on Wed Sep 04, 2019 3:30 am

The file is saved as backup_code.py.
Attachments
Screen%20Shot%202019-08-29%20at%2010.32.34%20AM.png
Screen%20Shot%202019-08-29%20at%2010.32.34%20AM.png (177.86 KiB) Viewed 55 times

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

Re: Gemma M0 Test Code for Neopixels

by adafruit_support_carter on Wed Sep 04, 2019 10:04 am

Only files with a certain name are run automatically:
https://learn.adafruit.com/welcome-to-c ... -file-7-32
Try changing the name to code.py

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

Re: Gemma M0 Test Code for Neopixels

by jeremyzschau on Wed Sep 04, 2019 9:33 pm

Thank you so much for your infinite patience Mr. Carter. It worked with the alligator clip gemma and with the gemmas with 8 neopixels sewn with conductive thread. Hopefully anyone using a Mac can use these steps as a guide. Now that I have code that works I can complete sewing the scarves.

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

Bundle Version py

rm -rf /Volumes/CIRCUITPY/lib
mkdir /Volumes/CIRCUITPY/lib
cp -X ./lib/adafruit_dotstar.mpy /Volumes/CIRCUITPY/lib/
ls /Volumes/CIRCUITPY/lib/*

Mu Editor in Serial Window
import board
import adafruit_dotstar
led = adafruit_dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1)
led.fill(0x0000ff)

Copy file one at a time cp command
cp

Terminal
mdutil -i off /Volumes/CIRCUITPY
cd /Volumes/CIRCUITPY
rm -rf .{,_.}{fseventsd,Spotlight-V*,Trashes}
mkdir .fseventsd
touch .fseventsd/no_log .metadata_never_index .Trashes
cd -

delete extra cd if after jeremy$
cd ~
cd Desktop
cd adafruit-circuitpython-bundle-4.x-mpy-20190819

This means sitting in the library bundle directory.
jeremy-zschaus-computer-2:adafruit-circuitpython-bundle-py-20190807

cp -X ./lib/neopixel.mpy /Volumes/CIRCUITPY/lib/

Mu Editor in Serial Window
import board
import neopixel
pixel = neopixel.NeoPixel(board.D1, 1)
pixel.fill(0xFF0000)

Mu Editor Paste in main code window
examples/neopixel_rpi_simpletest.py

Code: Select all | TOGGLE FULL SIZE
# Simple test for NeoPixels on Raspberry Pi
import time
import board
import neopixel


# Choose an open pin connected to the Data In of the NeoPixel strip, i.e. board.D18
# NeoPixels must be connected to D10, D12, D18 or D21 to work.
pixel_pin = board.D1

# 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-09-05 at 10.23.11 AM.png
Screen Shot 2019-09-05 at 10.23.11 AM.png (209.03 KiB) Viewed 29 times

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

Re: Gemma M0 Test Code for Neopixels

by adafruit_support_carter on Thu Sep 05, 2019 2:25 pm

Yeah! Awesome. Hope the scarves come together OK. Have fun!

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

Please be positive and constructive with your questions and comments.