Using CircuitPython with GEMMA M0
The Adafruit GEMMA M0 ships with CircuitPython, making this a plug & play experience. When you plug in a microUSB cable, the board shows up as a USB storage device on your computer. In the CIRCUITPY disk drive, you'll see editable files which contain sample code and libraries. It's pretty awesome!
Upload The Code
The Adafruit GEMMA M0 already has all the libraries we need to control NeoPixel LEDs. So there's no need to install the drivers, software IDE, board profiles, or libraries. Any computer that can use a USB drives can modify code.
In the CIRCUITPY root directory, open the main.py file in a text editing program. Copy and paste the code below into that text document. Save the file and close it. The GEMMA M0 will automatically reboot and run the code. No upload button (say whaaat?!).
Using TextEdit on Mac OS
If you're using this text editing app, I suggest you disable the Spelling and Grammar features to avoid "auto-correcting" any code. You'll want to turn this off before modifying any of the code. You can do so by right-clicking in the text document and unchecking the spelling & grammar options. These are normally enabled by default.
import board import neopixel pixpin = board.D2 numpix = 7 pixels = neopixel.NeoPixel(pixpin, numpix, brightness=.3) pixels[0] = (0, 50, 255) pixels[1] = (60, 0, 0) pixels[2] = (60, 0, 0) pixels[3] = (60, 0, 0) pixels[4] = (60, 0, 0) pixels[5] = (60, 0, 0) pixels[6] = (60, 0, 0) pixels.write()
CircuitPython NeoPixel Library
Want some more animation from the NeoPixel LEDs? There's a few demo's available that you may find more suitable for your project. Rainbow cycle pattern and color wipes sample code can be found in the Adafruit GEMMA M0 learning guide. If you're a programmer and want to write your own code, the circuitPython NeoPixel library documentation can be found in the Adafruit Github Repository.
Rainbow Cycle
The infamous rainbow cycle displays the NeoPixel like a vibrant rotating color wheel. The arrangement of the NeoPixels in the NeoPixel Jewel make the animation appear somewhat like the "beachball" loading curser in Mac OS.
# Gemma IO demo - NeoPixel from digitalio import * from board import * import neopixel import time pixpin = D2 numpix = 7 led = DigitalInOut(D13) led.direction = Direction.OUTPUT strip = neopixel.NeoPixel(pixpin, numpix, brightness=0.3) 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): return [0, 0, 0] if (pos > 255): return [0, 0, 0] if (pos < 85): return [int(pos * 3), int(255 - (pos*3)), 0] elif (pos < 170): pos -= 85 return [int(255 - pos*3), 0, int(pos*3)] else: pos -= 170 return [0, int(pos*3), int(255 - pos*3)] def rainbow_cycle(wait): for j in range(255): for i in range(len(strip)): idx = int ((i * 256 / len(strip)) + j) strip[i] = wheel(idx & 255) strip.write() time.sleep(wait) while True: rainbow_cycle(0.001)
Text editor powered by tinymce.