Difference between revisions of "WorkshopNeoPixels"

From SkullSpace Wiki
Jump to navigation Jump to search
(Write out most of the guide)
 
Line 23: Line 23:
 
Because we're using only three NeoPixels, the Arduino and your computer's USB port can give us all the power we need. The only physical part of this workshop is hooking the outputs of the Arduino to the inputs of the NeoPixels. You'll see that the LEDs in the kits come with wires attached, and that the ribbon is labelled GND, DI, and +5v. Those need to be wired to the 5v, Gnd and "Analog In 0" of the Arduino. That should give us the power and data we need to get onto the software part.
 
Because we're using only three NeoPixels, the Arduino and your computer's USB port can give us all the power we need. The only physical part of this workshop is hooking the outputs of the Arduino to the inputs of the NeoPixels. You'll see that the LEDs in the kits come with wires attached, and that the ribbon is labelled GND, DI, and +5v. Those need to be wired to the 5v, Gnd and "Analog In 0" of the Arduino. That should give us the power and data we need to get onto the software part.
  
I'm going to take a break writing for now, but more will be available by Tuesday, January 5th, 2016.
+
For the software, we've made something very simple. Start a new sketch in the Arduino IDE (see 'new' under 'file') and save it (see 'save' under 'file'). Then just paste this text block in there and press the upload button (round button with a right arrow):
 +
 
 +
<nowiki>
 +
  <code>
 +
// Adapted from NeoPixel Ring simple sketch (c) 2013 Shae Erisson
 +
// released under the GPLv3 license to match the rest of the AdaFruit NeoPixel library
 +
 
 +
#include <Adafruit_NeoPixel.h>
 +
 
 +
#define PIN      A0 // Which pin on the Arduino is connected to the NeoPixels?
 +
#define LED_COUNT 3  // How many pixels
 +
 
 +
Adafruit_NeoPixel pixels(LED_COUNT, PIN, NEO_GRB + NEO_KHZ800);
 +
 
 +
void setup() {
 +
  pixels.begin(); // This starts the NeoPixel library.
 +
}
 +
 
 +
void loop() {
 +
  // Do something creative in here!
 +
 
 +
  pixels.setPixelColor(0, pixels.Color(10,0,0));  // Low Red colour
 +
  pixels.setPixelColor(1, pixels.Color(0,20,0));  // Medium green
 +
  pixels.setPixelColor(2, pixels.Color(0,0,10));  // Low Blue
 +
  pixels.show(); // This sends the updated pixel color to the hardware.
 +
}
 +
  </code>
 +
<nowiki>

Revision as of 04:22, 6 January 2016

Here we're going to be playing with WS2812 red+green+blue digital LEDs which AdaFruit calls NeoPixels by controlling them with an Arduino. They can be strung together into long chains so you can use them for signs, fancy Christmas lights, or anything else fun that might need changing lights or precise colours. Most of the hard stuff is handled in software for us, so this will be more of an Arduino and programming workshop that interfaces with the physical world.

Required Supplies

  • Arduino-compatible microcontroller
  • Laptop with the Arduino IDE installed (see this page for details)
  • USB cable to connect the Laptop to the Arduino
  • A good attitude :D

Kit Contents

  • Three NeoPixels soldered to female headers
  • Male to male jumper wires to connect them to the Arduino

Pre-class Preparation

These lights need very precise timing to talk to them making it tricky to program. Because of that, we're going to use an Arduino library from AdaFruit to do all the hard work for us. That way we can just spend time doing awesome things with them. Instructions on installing and using that library are found here, so get that installed and if you like to be prepared give the rest of that page a read. It'll give you a huge leg up and an in-depth look at what we'll be doing in this workshop.

If you're not familiar with basic circuits, that's okay. There is magic here, but it's not needed for the class. There is a great article over at SparkFun that you can read if you're curious.

In-class work

Because we're using only three NeoPixels, the Arduino and your computer's USB port can give us all the power we need. The only physical part of this workshop is hooking the outputs of the Arduino to the inputs of the NeoPixels. You'll see that the LEDs in the kits come with wires attached, and that the ribbon is labelled GND, DI, and +5v. Those need to be wired to the 5v, Gnd and "Analog In 0" of the Arduino. That should give us the power and data we need to get onto the software part.

For the software, we've made something very simple. Start a new sketch in the Arduino IDE (see 'new' under 'file') and save it (see 'save' under 'file'). Then just paste this text block in there and press the upload button (round button with a right arrow):

<nowiki>

 

// Adapted from NeoPixel Ring simple sketch (c) 2013 Shae Erisson // released under the GPLv3 license to match the rest of the AdaFruit NeoPixel library

  1. include <Adafruit_NeoPixel.h>
  1. define PIN A0 // Which pin on the Arduino is connected to the NeoPixels?
  2. define LED_COUNT 3 // How many pixels

Adafruit_NeoPixel pixels(LED_COUNT, PIN, NEO_GRB + NEO_KHZ800);

void setup() {

 pixels.begin(); // This starts the NeoPixel library.

}

void loop() {

 // Do something creative in here!
 pixels.setPixelColor(0, pixels.Color(10,0,0));   // Low Red colour
 pixels.setPixelColor(1, pixels.Color(0,20,0));   // Medium green
 pixels.setPixelColor(2, pixels.Color(0,0,10));   // Low Blue
 pixels.show(); // This sends the updated pixel color to the hardware.

}

 

<nowiki>