Adafruit NeoPixel: Difference between revisions

The educational technology and digital learning wiki
Jump to navigation Jump to search
No edit summary
 
(23 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{stub}}
{{syllabus
[[category: e-textile]]
|is_part_of_syllabus=E-textile
|is_part_of_module=Adafruit Wearables
|do_not_show_sub_page=No
|page_previous=Adafruit NeoPixel
|page_next=Adafruit Sensors
|status=draft
|last_modification=2019/09/26
|objective=hook up a NeoPixel to a micro-controller
program the pixel (to do)
|difficulty=beginner
|see_also=Adafruit Circuit Playground Express,
MakeCode,
Adafruit GEMMA,
Adafruit NeoPixel,
Adafruit Sensors
|cat_syllabus=e-textile
}}
== Introduction ==
== Introduction ==


Line 8: Line 24:


* [[Adafruit Circuit Playground Express]]
* [[Adafruit Circuit Playground Express]]
* [[Adafruit FLORA]]
* [[Adafruit Wearables]]
* [[Adafruit GEMMA]]
* [[Adafruit GEMMA]]


Line 21: Line 37:
* 5-9VDC power (can run at 3.5V but color will be dimmed), constant current 18.5mA per LED (~55mA max total per pixel)
* 5-9VDC power (can run at 3.5V but color will be dimmed), constant current 18.5mA per LED (~55mA max total per pixel)


=== Hooking up a NeoPixel ===
== Hooking up a NeoPixel ==


According to [https://learn.adafruit.com/flora-rgb-smart-pixels/hook-up-alligator-clips Hook up alligator clips] (retrieved Aug 2019), a NeoPixel must be connected with three wires to a FLORA-type board. Depending on the board, the wiring is bit different. E.g. on a GEMMA, the signal must be wired from A1.
According to [https://learn.adafruit.com/flora-rgb-smart-pixels/hook-up-alligator-clips Hook up alligator clips] (retrieved Aug 2019), a NeoPixel must be connected with three wires to a FLORA-type board. Depending on the board, wiring opportunities can be different. E.g. on a GEMMA, you got less choice, but the principle is the same:
* Connect the + cable to a VOUT (Volt Out) pad
* Connect the - cable to a GND (Grounding) pad
* Connect the data cable to a general purpose input/output pad, e.g. A1.
We suggest using standard colors for your cables, i.e. red for +, black for -, and yellow or white for the data.
 
=== Wiring from a CPX ===


{| class="wikitable"
{| class="wikitable"
|+ Wiring with a GEMMA
|+ Wiring with a Circuit Playground Express
|-
|-
! Board !! NeoPixel
! Pads on the board !! NeoPixel
!LED Strip with cables
|-
|-
| VOUT  
| VOUT (Power output) || +
Power output
|red
| +
|-
|-
| GND  
| GND (Grounding)  || -
Grounding
|black
| -
|-
|-
| D1 / ~A0
| A1 (or another general Purpose Input Output pad, i.e. A0 to A7)
General Purpose Input Ouput
| ↑ (arrow pointing towards the inside)  
| ↑ (arrow pointing towards the inside)  
|white or yellow
|}
|}


[[image:GEMMA-NeoPixel-wiring.jpg|thumb|600px|none|Gemma - NexPixel wiring (improvised)]]
Note that A0 to A7 are different with respect to other functionality, so you might as well use A1 to A3 since they cannot not be used for anything else than digital input/output and analog input.
 


=== Wiring from a Gemma ===


{| class="wikitable"
{| class="wikitable"
|+ Wiring with a Circuit Playground Express
|+ Wiring with a GEMMA
|-
|-
! Board !! NeoPixel
! Pads on the board !! NeoPixel
!Strip with cables
|-
|-
| VOUT || +
| VOUT (Power output)
| +
|red
|-
|-
| GND || -
| GND (Grounding)
| -
|black
|-
|-
| A1
| D1 / ~A0 or A1, A2 (General Purpose Input Output)
General Purpose Input Ouput
| ↑ (arrow pointing towards the inside)  
| ↑ (arrow pointing towards the inside)  
|white or yellow
|}
|}


== MakeCode example ==
[[image:GEMMA-NeoPixel-wiring.jpg|thumb|600px|none|Gemma - NexPixel wiring (improvised): Read is power, black is grounding and white is the signal]]
 
== MakeCode example for the Circuit Playground Express ==
 
To manipulate a strip of external NeoPixels you will have to:
* Define the strip
* Use strip methods to set colors and other things. Below we use the setPixelColor(index,color) and setAll (...) methods.
 
This also works with a single pixel. Instead of using loops to iterate over each pixel, just work with pixel at index 0.
 
* Inspiration: [https://learn.adafruit.com/flora-rgb-smart-pixels/code-with-makecode Code with Makecode]
 
The following example does the following:
* On start, a short animation of 5 seconds of the strip
* After that all turned to black (off)
* Pressing Button A -> All Pixels will be blue
* Pressing Button B -> All Pixels will be red
* Pressing A3 (or the attached copper) band: Three loops that will light up with different colors. After that: all set to yellow
 
[[image:CPX-neopixel-strip-test.jpg|800px|none|thumb|Connecting a NeoPixelstrip to a playground Express]]




=== Programming a strand of pixels ===
To play with this example, simply copy the code below, then paste it into the {} JavaScript code tab at https://makecode.adafruit.com/#editor. You then can switch to the blocks editor. Make sure to start from a fresh project.


This also works with a single pixel...
<source lang="JavaScript">
// Button A down
input.buttonA.onEvent(ButtonEvent.Down, function () {
    // show blue on all pixels
    strip.setAll(0x0000FF)
})
// Button B down
input.buttonB.onEvent(ButtonEvent.Down, function () {
    // show red on all pixels
    strip.setAll(0xFF0000)
})
// A3 touched (you could add a strip of copper)
input.touchA3.onEvent(ButtonEvent.Down, function () {
    for (let index2 = 0; index2 <= strip.length(); index2++) {
        strip.setPixelColor(index2, 0xff0000)
        pause(100)
    }
    for (let index22 = 0; index22 <= strip.length(); index22++) {
        strip.setPixelColor(index22, 0x00ff00)
        pause(100)
    }
    for (let index3 = 0; index3 <= strip.length(); index3++) {
        strip.setPixelColor(index3, 0x0000ff)
        pause(100)
    }
    for (let index32 = 0; index32 <= strip.length(); index32++) {
        strip.setPixelColor(index32, 0xffff00)
    }
})
let strip: light.NeoPixelStrip = null
// mount an external Neopixel strip on pin A1 with 30
strip = light.createStrip(pins.A1, 30)
// show default animation for 5 seconds
strip.showAnimation(light.rainbowAnimation, 5000)
// Turn it off (make colors black)
for (let index = 0; index <= strip.length(); index++) {
    strip.setPixelColor(index, 0x000000)
}


* [https://learn.adafruit.com/flora-rgb-smart-pixels/code-with-makecode Code with Makecode]
</source>
 
To celebrate, 3D print the little cup from [https://www.blockscad3d.com/community/projects/295023 BlockSCAD] with a food safe plastic, then fill it with an invigorating drink.


== Links ==
== Links ==




'''Official documentation''' (read this)
'''Official general documentation''' (read this)


* [https://learn.adafruit.com/adafruit-neopixel-uberguide/the-magic-of-neopixels Adafruit NeoPixel Überguide]
* [https://learn.adafruit.com/adafruit-neopixel-uberguide/the-magic-of-neopixels Adafruit NeoPixel Überguide]
* [https://learn.adafruit.com/flora-rgb-smart-pixels/overview Sewable NeoPixels]
* [https://learn.adafruit.com/flora-rgb-smart-pixels/overview Sewable NeoPixels]
** [https://learn.adafruit.com/flora-rgb-smart-pixels/code-with-makecode Code with Makecode]
** [https://learn.adafruit.com/flora-rgb-smart-pixels/code-with-makecode Code with Makecode]
'''Tutorials'''
* [https://makecode.adafruit.com/projects/wearable-neopixels/make Wearable neopixels]

Latest revision as of 09:28, 8 October 2019

E-textile
Module: Adafruit Wearables
◀▬▬▶
draft beginner
2019/10/08 ⚒⚒ 2019/09/26
Objectives
  • hook up a NeoPixel to a micro-controller program the pixel (to do)
See also

Objectives

  • hook up a NeoPixel to a micro-controller program the pixel (to do)

See also

  • Quality: draft
  • Difficulty: beginner

Introduction

In this article we describe the Flora RGB Smart NeoPixel version 2

See also:

The pixel

Main characteristics:

  • 12.5mm diameter
  • 2.5mm total thickness
  • 800 KHz speed protocol
  • Chainable design, meaning that you can connect several of these to one pin and chain them
  • 5-9VDC power (can run at 3.5V but color will be dimmed), constant current 18.5mA per LED (~55mA max total per pixel)

Hooking up a NeoPixel

According to Hook up alligator clips (retrieved Aug 2019), a NeoPixel must be connected with three wires to a FLORA-type board. Depending on the board, wiring opportunities can be different. E.g. on a GEMMA, you got less choice, but the principle is the same:

  • Connect the + cable to a VOUT (Volt Out) pad
  • Connect the - cable to a GND (Grounding) pad
  • Connect the data cable to a general purpose input/output pad, e.g. A1.

We suggest using standard colors for your cables, i.e. red for +, black for -, and yellow or white for the data.

Wiring from a CPX

Wiring with a Circuit Playground Express
Pads on the board NeoPixel LED Strip with cables
VOUT (Power output) + red
GND (Grounding) - black
A1 (or another general Purpose Input Output pad, i.e. A0 to A7) ↑ (arrow pointing towards the inside) white or yellow

Note that A0 to A7 are different with respect to other functionality, so you might as well use A1 to A3 since they cannot not be used for anything else than digital input/output and analog input.

Wiring from a Gemma

Wiring with a GEMMA
Pads on the board NeoPixel Strip with cables
VOUT (Power output) + red
GND (Grounding) - black
D1 / ~A0 or A1, A2 (General Purpose Input Output) ↑ (arrow pointing towards the inside) white or yellow
Gemma - NexPixel wiring (improvised): Read is power, black is grounding and white is the signal

MakeCode example for the Circuit Playground Express

To manipulate a strip of external NeoPixels you will have to:

  • Define the strip
  • Use strip methods to set colors and other things. Below we use the setPixelColor(index,color) and setAll (...) methods.

This also works with a single pixel. Instead of using loops to iterate over each pixel, just work with pixel at index 0.

The following example does the following:

  • On start, a short animation of 5 seconds of the strip
  • After that all turned to black (off)
  • Pressing Button A -> All Pixels will be blue
  • Pressing Button B -> All Pixels will be red
  • Pressing A3 (or the attached copper) band: Three loops that will light up with different colors. After that: all set to yellow
Connecting a NeoPixelstrip to a playground Express


To play with this example, simply copy the code below, then paste it into the {} JavaScript code tab at https://makecode.adafruit.com/#editor. You then can switch to the blocks editor. Make sure to start from a fresh project.

// Button A down
input.buttonA.onEvent(ButtonEvent.Down, function () {
    // show blue on all pixels
    strip.setAll(0x0000FF)
})
// Button B down
input.buttonB.onEvent(ButtonEvent.Down, function () {
    // show red on all pixels
    strip.setAll(0xFF0000)
})
// A3 touched (you could add a strip of copper)
input.touchA3.onEvent(ButtonEvent.Down, function () {
    for (let index2 = 0; index2 <= strip.length(); index2++) {
        strip.setPixelColor(index2, 0xff0000)
        pause(100)
    }
    for (let index22 = 0; index22 <= strip.length(); index22++) {
        strip.setPixelColor(index22, 0x00ff00)
        pause(100)
    }
    for (let index3 = 0; index3 <= strip.length(); index3++) {
        strip.setPixelColor(index3, 0x0000ff)
        pause(100)
    }
    for (let index32 = 0; index32 <= strip.length(); index32++) {
        strip.setPixelColor(index32, 0xffff00)
    }
})
let strip: light.NeoPixelStrip = null
// mount an external Neopixel strip on pin A1 with 30
strip = light.createStrip(pins.A1, 30)
// show default animation for 5 seconds
strip.showAnimation(light.rainbowAnimation, 5000)
// Turn it off (make colors black)
for (let index = 0; index <= strip.length(); index++) {
    strip.setPixelColor(index, 0x000000)
}

To celebrate, 3D print the little cup from BlockSCAD with a food safe plastic, then fill it with an invigorating drink.

Links

Official general documentation (read this)

Tutorials