User Tools

Site Tools


tutorials:products:pixel36mm:index.html

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
tutorials:products:pixel36mm:index.html [2012/01/27 18:15]
pburgess [Wiring]
tutorials:products:pixel36mm:index.html [2016/01/28 18:05] (current)
Line 62: Line 62:
  
 The WS2801 chip is the same as in our 12mm pixels, so any software that works with the smaller pixels can also control these larger versions! The WS2801 chip is the same as in our 12mm pixels, so any software that works with the smaller pixels can also control these larger versions!
- 
- 
- 
- 
- 
- 
- 
- 
- 
  
 ==== Wiring ​ ==== ==== Wiring ​ ====
Line 89: Line 80:
  
 Our Arduino library (explained below) can use any two pins, but the examples are written to use pins 2 and 3 as above. Our Arduino library (explained below) can use any two pins, but the examples are written to use pins 2 and 3 as above.
-==== Code!  ==== 
  
-=== LPD6803 pixels ​===+==== Download ====
  
-The code to drive these dots is fairly simpleexcept that the PWM pin and the data clock pin is shared which means that you can't just stick the PWM pin on a hardware timer output because ​then its not possible ​to use it for the data clocking.+To download the Arduino library[[https://​github.com/​adafruit/​Adafruit-WS2801-Library|visit ​the repository on GitHub]]. 
 +Click the DOWNLOAD ZIP button near the upper left, extract the archive and then rename the uncompressed folder ​to ''​Adafruit_WS2801''​. Confirm that this folder contains ​the files ''​Adafruit_WS2801.cpp''​ and ''​Adafruit_WS2801.h''​ and the ''​examples''​ folder.
  
-Instead, ​the library uses an interrupt that goes off every few millisecondsIf there is data to be updated on the strip, ​it sends that dataIf notit just pulses pin to keep the PWM going.+Place the WS2801 folder inside your Arduino ''​Libraries''​ folderYou may need to create this folder if it does not yet existIn Windowsthis would be ''​(home folder)\My Documents\Arduino\Libraries''​ and for Mac or Linux is ''​(home folder)/​Documents/​Arduino/​Libraries''​ [[http://​www.ladyada.net/​library/​arduino/​libraries.html|We also have a tutorial on library installation]].
  
-**Note that the interrupt uses timer 1 which means the pin 9 and 10 PWMs will not '​work'​ for servos, please use a '​software servo' ​library!**+After installing ​the Adafruit_WS2801 ​library, restart the Arduino IDE. You should now be able to access the sample code by navigating through menus in this order: File->​Sketchbook->​Libraries->​Adafruit_WS2801->​strandtest
  
-This code is heavily based off of [[http://​www.bliptronics.com|bliptronics'​]] original code except we library-ized it and trimmed it down. [[https://​github.com/​adafruit/​LPD6803-RGB-Pixels|You can download the library from github]], [[http://​www.ladyada.net/​library/​arduino/​libraries.html|then follow our library installtion procedure.]]+==== Code! ====
  
-Once you've rebooted, load up the **strandtest.pde** example ​sketch, we'll go through the most important parts. +Let's look through ​the strandtest ​example codeTo use the library in an Arduino ​sketch, you'​ll ​first need to globally declare a Adafruit_WS2801 ​object to talk to the strip. It is invoked ​with three variablesthe number of pixels and the data and clock pins:
- +
-First up, you'll need to make an library ​object to talk to the strip. It is initialized ​with three variablesthe number of pixels and the data/clock pin. You can change these later.+
  
 <code C> <code C>
-// Set the first variable to the NUMBER of pixels. 20 = 20 pixels in a row +int dataPin  ​= 2
-LPD6803 strip = LPD6803(20, ​dataPin, clockPin);​ +int clockPin ​3;
-</​code>​ +
- +
-Next we will set up the strip in the **setup()** procedure. +
- +
-<code C> +
-void setup() { +
-  // The Arduino needs to clock out the data to the pixels +
-  // this happens in interrupt timer 1, we can change how often +
-  // to call the interrupt. setting CPUmax to 100 will take nearly all all the +
-  // time to do the pixel updates and a nicer/​faster display,  +
-  // especially with strands of over 100 dots. +
-  // (Note that the max is '​pessimistic',​ its probably 10% or 20% less in reality) +
-  strip.setCPUmax(50) // start with 50% CPU usage. up this if the strand flickers or is slow +
-   +
-  // Start up the LED counter +
-  strip.begin();​ +
- +
-  // Update the strip, to start they are all '​off'​ +
-  strip.show();​ +
-}</​code>​ +
- +
-**setCPUmax()** configures the timer 1 interrupt that PWM's the strand. You can change this from 0 to 100, it runs in the background. The '​max'​ is calculated assuming the longest possible timing (when sending data) so its a big pessimistic. 50% should be plenty, you can mess with this to make the strip more or less '​flickery'​ You can change this 'on the fly' so for example set it to 0% just before doing a bunch of Ethernet stuff, then back to 50% later. +
- +
-**begin() **actually starts the interrupt +
- +
-**show()** is what updates the strand display. You'll need to call it after setting any colors to see the updates. This way you can change the entire strip at a time (it takes the same amount of time to change one pixel as it does for an entire strip because the full strip data must be shifted out at once) +
- +
-Last, we'll look at an example function, colorWipe. This creates a '​chase'​ that fills the strip up with a color. It is basically a loop that increments through every pixel (which you can conveniently get by **numPixels()** ) and sets the pixel color of that pixel (incremented with **i**) to the color **c**. In this case the color is stored in a 16 bit variable. The strip output is then updated with **show()**. Finally there is some delay (otherwise this would happen instantly) +
- +
-Below that is a little helper that takes 8 bit red green and blue and bit-mashes them into a 15 bit color. This means that the '​max'​ value for each color is 31. +
- +
-<code C> +
-// fill the dots one after the other with said color +
-// good for testing purposes +
-void colorWipe(uint16_t c, uint8_t wait) { +
-  ​int i; +
-   +
-  for (i=0i < strip.numPixels();​ i++) { +
-      strip.setPixelColor(i,​ c); +
-      strip.show();​ +
-      delay(wait);​ +
-  } +
-+
- +
-/* Helper functions */ +
- +
-// Create a 15 bit color value from R,G,B +
-unsigned int Color(byte r, byte g, byte b) +
-+
-  //Take the lowest 5 bits of each value and append them end to end +
-  return( ((unsigned int)g & 0x1F )<<10 | ((unsigned int)b & 0x1F)<<​5 | (unsigned int)r & 0x1F); +
-}+
  
 +// Set the first variable to the NUMBER of pixels. 25 = 25 pixels in a row
 +Adafruit_WS2801 strip = Adafruit_WS2801(25,​ dataPin, clockPin, WS2801_GRB);​
 </​code>​ </​code>​
  
-For examplein the **loop()** we call colorWipe(Color(31,​ 0, 0), 50) which will fill the strand with only-full-red light, pausing about 50 milliseconds between ​pixels.+The last parameter there''​WS2801_GRB'',​ is required when using these 36mm pixels ​(otherwise red and green will be reversed). You do NOT need this parameter if using our 12mm pixels.
  
-<code C> +Next, we initialize ​the strip in the ''​setup()'' ​procedure:
-  colorWipe(Color(310, 0), 50);  // red fill +
-  colorWipe(Color(0,​ 31, 0), 50);  // green fill +
-  colorWipe(Color(0,​ 0, 31), 50);  // blue fill +
-</​code>​  +
- +
-=== WS2801 pixels === +
- +
-This code is very similar to the LPD6803 but simpler because ​we do not need to use the CPU to update ​the pixel clock constantly. +
- +
-The code to drive these dots is even simpler, you don't need to worry about any timers, use any two pins you'd like! You can use anything that requires timer 1 like the servo libraries. +
- +
-[[https://​github.com/​adafruit/​WS2801-Library|To download, visit the repository on Github.]] Click the DOWNLOADS button in the top right corner, rename the uncompressed folder WS2801. Check that the WS2801 folder contains WS2801.cpp and WS2801.h +
- +
-Place the WS2801 library folder your <​arduinosketchfolder>/​libraries/​ folder. You may need to create the libraries subfolder if its your first library. Restart the IDE. [[http://​www.ladyada.net/​library/​arduino/​libraries.html|We also have a tutorial on library installation]] +
- +
-Once you've rebooted, load up the **WS2801->​strandtest.pde** example sketch, we'll go through the most important parts. +
- +
-First up, you'll need to make an library object to talk to the strip. It is initialized with three variables, the number of pixels and the data/clock pin. You can change these later.+
  
 <code C> <code C>
-// Set the first variable to the NUMBER of pixels. 25 = 25 pixels in a row +void setup() {
-WS2801 strip = WS2801(25, dataPin, clockPin)+
-</​code>​+
  
-Next we will set up the strip in the **setup()** procedure. 
- 
-<code C> 
-void setup() { 
-  // Start up the LED counter 
   strip.begin();​   strip.begin();​
  
-  // Update ​the strip, to start they are all '​off'​+  // Update ​LED contents, to start they are all '​off'​
   strip.show();​   strip.show();​
 }</​code>​ }</​code>​
  
-**begin()** initializes the library ​and sets all the pixel colors to off.+''​begin()'' ​initializes the library, while ''​show()''​ refreshes ​the displayed colors of the LEDs. You'll need to call ''​show()''​ after changing any pixel colors to see this reflected in the LEDs. This way you can change the entire strip at one time (it takes the same amount of time to change one pixel as it does for an entire strip, because the full strip data must be issued regardless).
  
-**show()** is what updates the strand displayYou'll need to call it after setting any colors to see the updatesThis way you can change ​the entire strip at a time (it takes the same amount ​of time to change one pixel as it does for an entire strip because ​the full strip data must be shifted out at once)+Let's look inside an example function, ''​colorWipe()''​This creates a 'chase' sequence that fills the strip up with a colorIt is basically a loop that increments through every pixel (which ​you can query with the ''​numPixels()''​ function) and sets the color of each (incremented with ''​i''​) ​to the value passed (''​c''​ — colors are expressed ​as a 32-bit variable type, though only the bottom 24 bits are used). The strip output is then updated with ''​show()''​. Finally there is some delay (otherwise this would happen instantly).
  
-Last, we'll look at an example function, colorWipe. This creates a '​chase'​ that fills the strip up with a color. It is basically a loop that increments through every pixel (which you can conveniently get by **numPixels()** ) and sets the pixel color of that pixel (incremented with **i**) to the color **c**. In this case the color is stored in a 32 bit variable but uses only the bottom 24 bits. The strip output is then updated with **show()**. Finally there is some delay (otherwise this would happen instantly) +Below that is a helper ​function ​that converts a color from separate ​8-bit redgreen and blue values ​into a combined ​24-bit value (suitable for passing to ''​colorWipe()''​). The brightness range is from 0 (off) to 255 (max brightness).
- +
-Below that is a little ​helper that takes 8 bit red green and blue and bit-mashes them into a 24 bit color. This means that the 'max' ​value for each color is 255.+
  
 <code C> <code C>
Line 234: Line 146:
   return c;   return c;
 } }
- 
 </​code>​ </​code>​
  
-For example, in the **loop()** we call colorWipe(Color(255,​ 0, 0), 50) which will fill the strand with only-full-red light, pausing about 50 milliseconds between pixels.+For example, in the ''​loop()''​ function ​we call colorWipe(Color(255,​ 0, 0), 50) which will fill the strand with full-brightness ​red light, pausing about 50 milliseconds between pixels.
  
 <code C> <code C>
Line 244: Line 155:
   colorWipe(Color(0,​ 0, 255), 50);  // blue fill   colorWipe(Color(0,​ 0, 255), 50);  // blue fill
 </​code> ​ </​code> ​
-==== Download ​ ==== 
-=== LPD8603 library === 
- 
-We have an Arduino lirbary that can be fairly easily ported to any microcontroller with two digital output pins and a interrupt timer. This code is heavily based off of [[http://​www.bliptronics.com|bliptronics'​]] original code except we library-ized it and trimmed it down. 
- 
-[[https://​github.com/​adafruit/​LPD6803-RGB-Pixels|You can download the library from github]], [[http://​www.ladyada.net/​library/​arduino/​libraries.html|then follow our library installation procedure.]] 
- 
-**Dont forget that this library uses an interrupt on timer 1 which means the pin 9 and 10 PWMs will not '​work'​ for servos, please use a '​software servo' library!** 
- 
-=== WS2801 library === 
  
-[[https://​github.com/​adafruit/​WS2801-Library|To download, visit the repository on Github.]] Click the DOWNLOADS button in the top right corner, rename the uncompressed folder WS2801. Check that the WS2801 folder contains WS2801.cpp and WS2801.h 
  
-Place the WS2801 library folder your <​arduinosketchfolder>/​libraries/​ folder. You may need to create the libraries subfolder if its your first library. Restart the IDE. [[http://​www.ladyada.net/​library/​arduino/​libraries.html|We also have a tutorial on library installation]] 
/home/ladyada/public_html/wiki/data/attic/tutorials/products/pixel36mm/index.html.1327688122.txt.gz · Last modified: 2016/01/28 18:05 (external edit)