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 Thu Aug 22, 2019 9:41 pm

Please check.
Attachments
IMG_7583.jpg
IMG_7583.jpg (300.35 KiB) Viewed 176 times

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

Re: Gemma M0 Test Code for Neopixels

by adafruit_support_carter on Fri Aug 23, 2019 12:50 pm

OK, try running these commands in Mu as shown here:
Screenshot from 2019-08-23 09-44-19.png
Screenshot from 2019-08-23 09-44-19.png (91.88 KiB) Viewed 168 times

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

Re: Gemma M0 Test Code for Neopixels

by jeremyzschau on Fri Aug 23, 2019 11:46 pm

Please check.
Attachments
Screen Shot 2019-08-24 at 12.40.08 PM.png
Screen Shot 2019-08-24 at 12.40.08 PM.png (519.07 KiB) Viewed 159 times

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

Re: Gemma M0 Test Code for Neopixels

by adafruit_support_carter on Sat Aug 24, 2019 7:08 am

The 'p' needs to be capitalized:
neo.jpg
neo.jpg (14.14 KiB) Viewed 151 times

so NeoPixel, not Neopixel.

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

Re: Gemma M0 Test Code for Neopixels

by jeremyzschau on Sat Aug 24, 2019 7:22 am

I'm very sorry. I made the correction. The neopixel attached to the gemma illuminated red.

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

Re: Gemma M0 Test Code for Neopixels

by adafruit_support_carter on Tue Aug 27, 2019 12:16 pm

Cool. Yah, CircuitPython is case sensitive. So upper and lower case letters are seen as totally different.

Sounds like you're working now. You can use the onboard DotStar if you want, which doesn't require any external wiring. That's good for quick prototyping of code - like making rainbow effects, etc. Or just as a fallback to sanity check things if the external NeoPixels are acting up and you don't know if it's a code issue or a wiring issue.

But you got the NeoPixel to be red, so it's working. I'd say try going back to your original sewn project and see if you get that to work. Use the same NeoPixel example as above and just try to get the first one to light.

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

Re: Gemma M0 Test Code for Neopixels

by jeremyzschau on Tue Aug 27, 2019 9:23 pm

I'm sorry how do I get the neopixel attached to cycle rainbow colors?

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

Re: Gemma M0 Test Code for Neopixels

by adafruit_support_carter on Wed Aug 28, 2019 11:21 am

Well at this point your hardware is all working and you have the general idea of how to copy library files over as needed. Now it's just a matter of writing the program for what you want. You'll have to do that part.

There's general info on using NeoPixels with CircuitPython here:
https://github.com/adafruit/Adafruit_Ci ... n_NeoPixel
https://learn.adafruit.com/circuitpytho ... n-neopixel

And you can also look at coding examples from related projects in the Learn system, like this one:
https://learn.adafruit.com/animated-neo ... ython-code

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

Re: Gemma M0 Test Code for Neopixels

by jeremyzschau on Wed Aug 28, 2019 9:38 pm

Please check. The neopixel is either white or not illuminated.
https://github.com/adafruit/Adafruit_CircuitPython_NeoPixel/blob/master/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.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-29 at 10.32.34 AM.png
Screen Shot 2019-08-29 at 10.32.34 AM.png (177.86 KiB) Viewed 97 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 Aug 29, 2019 12:07 pm

What pin is the NeoPixel attached to? Then, look back at the code that worked and compare to the code above.

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

Re: Gemma M0 Test Code for Neopixels

by jeremyzschau on Thu Aug 29, 2019 6:39 pm

D1.
Attachments
Screen Shot 2019-08-30 at 7.31.11 AM.png
Screen Shot 2019-08-30 at 7.31.11 AM.png (188.28 KiB) Viewed 80 times
IMG_7583.jpg
IMG_7583.jpg (300.35 KiB) Viewed 80 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 Aug 29, 2019 7:26 pm

And what is the pin set to in your current code?

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

Re: Gemma M0 Test Code for Neopixels

by Tsaro on Thu Aug 29, 2019 7:35 pm

@jeremyzschau I took the last version of the code you uploaded and was able to make 2 changes to make it work, here is the code in its entirety but the noteworthy fixes were to change the pixel pin:

Code: Select all | TOGGLE FULL SIZE
pixel_pin = board.D1


and to fix a missing indent at your first return:

Code: Select all | TOGGLE FULL SIZE
    return (r, g, b) if ORDER == neopixel.RGB or ORDER == neopixel.GRB else (r, g, b, 0)

^^ Missing indent here

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

Tsaro
 
Posts: 1
Joined: Sat Jun 28, 2014 1:24 pm

Re: Gemma M0 Test Code for Neopixels

by jeremyzschau on Sat Aug 31, 2019 2:03 am

I changed the neopixel because it seems to be a problem. Solid white. No rainbow cycle.

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

Re: Gemma M0 Test Code for Neopixels

by adafruit_support_carter on Sat Aug 31, 2019 10:52 am

Can you repeat previous success? You were able to make it be red above.

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

Please be positive and constructive with your questions and comments.