Introduction: NeoPixel Pattern Programmer

In this instructable I will show you how to make my pattern programmer for Adafruit's NeoPixels.
It's a hassle to think up nice patterns in code every time, so I created a little application that you can visually program the patterns in, to get quick results on your leds!

What makes this code different than other pattern writers or programmers, is that this application writes the values to the Arduino EEPROM. The EEPROM of the Arduino will not get erased when you power down, this means you can program your deviced, and the pattern will be on it every time you power them on. EEPROM writing and reading is handled by the Arduino firmware.

Together with the Processing sketch that allows you to easily draw a pattern strip and calculates all the values for you and sends them out nicely formatted this is an almost hassle free way to make your NeoPixels do what you want!


Apologies beforehand for the code, it might get a bit hardcode-y in the end.

Step 1: Step 1: Parts and Schematic

Picture of Step 1: Parts and Schematic

To build this device You'll need a few parts!
-1 Arduino, I prefer Nano's

-A length of Adafruit Neopixels, use a segment of 5 if you don't want to change anything in my code

-A Switch

-A 1K resistor

-Breadboard, wire, pcb, anything to hook it all up.

The wiring is real easy, just hook it up like on the schematic. For short lengths of LED strip like in this project, you don't need to use external power.
The switch is to switch between display and program mode, if you are writing a new pattern to the device, put it in program mode to make sure you don't miss a bit.

This is the code for the Arduino:
You'll need to download the NeoPixel library, the EEPROM library is included with the arduino software.

//Arduino EEPROM neopixel pattern writer by Pieter Pelt 2015
//This sketch takes values from the eeprom to show on neopixels, it can also receive new data and write that to the eeprom
//Receives data from accompanying processing sketch
//Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0)

#include <EEPROM.h>
#include <Adafruit_NeoPixel.h>

#define PIN 3
#define FRAMES 0
#define DELAY 1
#define LEDS 2

/* RGB DEFS */
#define RED 0
#define GREEN 1
#define BLUE 2

int  sw = 2;

Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800);

char eepColor[3];          // Contains R, G, B values
char programData[3];

void writeRGB(int _addr, char _red, char _green, char _blue)
{
  EEPROM.write(_addr + RED, _red);        // Write eeprom with data
  EEPROM.write(_addr + GREEN, _green);        // Write eeprom with data
  EEPROM.write(_addr + BLUE, _blue);        // Write eeprom with data
}

void writeEeprom(char _frames, char _delay, char _leds)
{
  EEPROM.write(FRAMES, _frames);   // Frames in the annimation
  EEPROM.write(DELAY, _delay);     // Delay after frames
  EEPROM.write(LEDS, _leds);       // Leds per strip

  /*
  writeRGB(3, 255, 0, 0);
   writeRGB(6, 0, 255, 0);
   writeRGB(9, 0, 0, 255);
   writeRGB(12, 255, 255, 0);
   writeRGB(15, 0, 255, 255);
   //for(int i=3; i<16; i=i+3)writeRGB(i, 255, 255, 0);  // fill frome 1 with yello
   for(int i=18; i<31; i=i+3)writeRGB(i, 0, 255, 0);   // fill frame 2 with blue
   for(int i=33; i<46; i=i+3)writeRGB(i, 255, 0, 255);   // fill frame 3 with red

   */
}

void readEeprom()
{
  programData[FRAMES] = EEPROM.read(FRAMES);  // Get amount of frames
  programData[DELAY] = EEPROM.read(DELAY);    // Get delay per frame
  programData[LEDS] = EEPROM.read(LEDS);      // Get leds per strip
}

void initStrip()
{
  strip.begin();        // Initialize ledstrip
  strip.show();         // Initialize all pixels to 'off'
}

void getLedData(int _addr)
{
  eepColor[RED] = EEPROM.read(_addr + RED);
  eepColor[GREEN] = EEPROM.read(_addr + GREEN);
  eepColor[BLUE] = EEPROM.read(_addr + BLUE);
}

void setup()
{
  writeEeprom(8, 100, 5);  // Write frames, delay and led to eeprom
  readEeprom();
  initStrip();
  Serial.begin(9600);
}

void loop()

{


  if (Serial.available() > 0) {

    int maxtemp = 16;
    int temp[maxtemp];
    for (int i = 0; i < maxtemp; i++) {
      temp[i] = Serial.parseInt();
    }
    if (Serial.read() == '\n') {
      if (temp[15] == 200) { //if the last number was a 200
        EEPROM.write(DELAY, temp[14]);  //set the delay value instead
        readEeprom();
      }
      else {  //else you got rgb data so write that to the EEPROM
        for (int i = 3; i < maxtemp + 1; i = i + 3) {
          writeRGB(temp[15] + i, temp[i - 3], temp[i - 2], temp[i - 1]); //last value in the array is used for the offset in the EEPROM, offset = start of a new fram
        }
      }
    }

  }




  if (digitalRead(sw)) { // if switch
    digitalWrite(13, HIGH);

    for (int i = 0; i < programData[FRAMES]; i++)
    {
      for (int j = 0; j < programData[LEDS]; j++)
      {
        getLedData(3 + (j * 3) + (3 * i * programData[LEDS])); // Get RGB data for one led
        strip.setPixelColor(j, strip.Color(eepColor[RED], eepColor[GREEN], eepColor[BLUE]));  // Set one led with RGB value
      }
      strip.show();    // Display on the strip
      delay(int(programData[DELAY]));
    }
  }
  else {
    digitalWrite(13, LOW);
  }


}

Step 2: Load Up the Software

Picture of Load Up the Software

This is the accompanying Processing sketch.

With this sketch you can draw a pattern like I do in my video, and the software will calculate all the values and positions to sent to the Arduino.


There are a few hotkeys in this program:

s - sent values to arduino (make sure the arduino is in data receive mode, and not in display mode!)
r - reset

b - reset to black

o and p - change delay (the speed of the pattern)

l - load up bitmap

Use the .pde file attached to this page, I couldn't embed the code, as the instructables formatting was always removing essential parts.

Step 3: Have Fun Applying Easy to Program NeoPixels to Your Projects, Clothes and Interior!

Picture of Have Fun Applying Easy to Program NeoPixels to Your Projects, Clothes and Interior!

I used these on my clothes at a MakerFaire, to independently bring more wearable technology to the party! But they of course can be used for anything!

Comments

dunk8888young (author)2017-04-16

Hi i get the image test.bmp could not be found.

TedD8 (author)2016-07-07

also color sequence is off neopixel are grb processing is rgb so getting off colors

TedD8 (author)2016-07-07

what would i need to do to program a strip of 60?????

TedD8 (author)2016-07-07

what would i need to do to program a strip of 60?????

TedD8 (author)2016-05-21

still cant get working im using an uno clone processing keeps saying "array out of bounds

pieterpelt (author)TedD82016-05-22

You need to properly configure your COM port in the setup. It's different for every computer.
Change this line myPort = new Serial(this, Serial.list()[1], 9600);
On my machine my arduino is the 2nd in this list, so I use the Serial.list()[1], maybe on yours its the first on the list, so put a zero there. Check your port selector in the arduino IDE to see whats connected to your PC.

TedD8 (author)2016-05-14

the processing sketch won't compile tons of errors

pieterpelt (author)TedD82016-05-21

Hey I've added the processing sketch as a .pde file because Instructables formatting kept messing with the code, my apologies!

geddyleefan (author)2016-05-02

It looks like the Processing sketch is not complete. Also, I'm new to Arduino, how do you get the IDE to compile and run a Windows program?

pieterpelt (author)geddyleefan2016-05-11

You were right, the formatting cut of part of the processing code! It's all complete now, you just need the libraries specified in the text.

To run an Arduino sketch, just hit the play button in the Arduino IDE!

Adz108 (author)2016-04-27

This is EXACTLY what I need for my next project! Thank you for sharing! :)

HarshS66 (author)2016-04-27

What all things i will recquire in making this project

That Redhead (author)2016-04-25

Awesome!

DIY Hacks and How Tos (author)2016-04-24

Cool neopixel project.

About This Instructable

5,615views

102favorites

License:

More by pieterpelt:NeoPixel Pattern Programmer
Add instructable to: