# Adafruit DotStar LEDs

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/021/922/medium800/leds_dotstar-banner.jpg?1419375063)

NeoPixel LEDs are the bee's knees, but in a few scenarios they come up short…connecting odd microcontrollers that can’t match&nbsp;their strict timing, or fast-moving persistence-of-vision displays.&nbsp;Adafruit **DotStar LEDs** deliver high speed PWM and an easy-to-drive two-wire interface, bridging the gaps in the spectrum of awesome.

# DotStars vs NeoPixels

The basic idea behind DotStars and NeoPixels is the same: a continuous string of individually-addressable RGB LEDs, driven by a microcontroller. The way each goes about it is a little different. DotStars _aren’t necessarily&nbsp;a better thing in every situation_…there are tradeoffs, each has its pros and cons to consider…

<sup>1</sup> Up to 8 MHz on Arduino, up to 32 MHz on Raspberry Pi.

<sup>2</sup>&nbsp;Varies among component generations; 1.2 KHz, 4.6 KHz, 19.2 KHz reported.

# Adafruit DotStar LEDs

## Form Factors

DotStar products are available in numerous&nbsp;form factors…from individual tiny pixels to huge matrices…plus strips, FeatherWings and a few surprises.

Pick a category from the left column for product links and tips & tricks specific to each type of DotStar offering.

# Adafruit DotStar LEDs

## DotStar Strips

The most popular type&nbsp;of DotStars are these **flexible LED strips** …they can be cut to length and fit into all manner of things. There are many&nbsp;varieties! Two **vital** things to be aware&nbsp;of:

- Though strips are described as “flexible,”&nbsp; **they do not tolerate continuous and repeated bending.** &nbsp;“Formable” might be a better word. A typical application is&nbsp;architecture, where they can be curved around columns and then stay put. Repeated flexing (as on costumes) will soon crack the solder connections. For wearable use, affix shorter segments to a semi-rigid base (e.g. a hat, BMX armor, etc.).
- Watch your power draw. Though each pixel only needs a little current, it **adds up fast** …DotStar strips are so simple to use, one can quickly get carried away! We’ll explain more on the “Power and Connections” page.

# RGB DotStar Strips
 **DotStar Digital RGB LED Weatherproof Strip&nbsp;** is available in three different “densities”: 30, 60 and 144 LEDs per meter, on a white or black backing strip.

- [**30 LEDs per meter, white strip**](https://www.adafruit.com/product/2238)
- [**30 LEDs per meter, black strip**](https://www.adafruit.com/product/2237)
- [**60 LEDs per meter, white strip**](https://www.adafruit.com/product/2240)
- [**60 LEDs per meter, black strip**](https://www.adafruit.com/product/2239)
- [**144 LEDs per meter, white strip**](https://www.adafruit.com/product/2242)
- [**144 LEDs per meter, black strip**](https://www.adafruit.com/product/2241)
- [**144/m white strip, half-meter**](https://www.adafruit.com/product/2329)
- [**144/m black strip, half-meter**](https://www.adafruit.com/product/2328)

The&nbsp;_approximate_&nbsp;peak power use&nbsp;(all LEDs on at maximum brightness)&nbsp;per meter is:

- **30** &nbsp;LEDs: 9 Watts (about 1.8 Amps at 5 Volts).
- **60** &nbsp;LEDs: 18 Watts (about 3.6 Amps at 5 Volts).
- **144** &nbsp;LEDs : 43&nbsp;watts (8.6 Amps at 5 Volts).

Mixed colors and lower brightness settings will use proportionally less power.

![led_strips_30w.jpg](https://cdn-learn.adafruit.com/assets/assets/000/063/248/medium640/led_strips_30w.jpg?1539046355)

![led_strips_30b.jpg](https://cdn-learn.adafruit.com/assets/assets/000/063/249/medium640/led_strips_30b.jpg?1539046360)

![led_strips_60w.jpg](https://cdn-learn.adafruit.com/assets/assets/000/063/250/medium640/led_strips_60w.jpg?1539046365)

![led_strips_60b.jpg](https://cdn-learn.adafruit.com/assets/assets/000/063/251/medium640/led_strips_60b.jpg?1539046372)

![led_strips_144w.jpg](https://cdn-learn.adafruit.com/assets/assets/000/063/252/medium640/led_strips_144w.jpg?1539046378)

![led_strips_144b.jpg](https://cdn-learn.adafruit.com/assets/assets/000/063/253/medium640/led_strips_144b.jpg?1539046382)

# White DotStar Strips
A recent addition is _ **White** _&nbsp;DotStar strips. Rather than red, green and blue, these contain three identical white LED elements — either “cool” or “warm” white. For monochrome applications, white DotStars are more “true” and pleasing to the eye than white mixed from red+green+blue. Like the RGB strips, they’re available in different pixel densities.

- [**30 Cool White LEDs per meter**](https://www.adafruit.com/product/2432)
- [**30 Warm White LEDs per meter**](https://www.adafruit.com/product/2435)
- [**60 Cool White LEDs per meter**](https://www.adafruit.com/product/2433)
- [**60 Warm White LEDs per meter**](https://www.adafruit.com/product/2436)
- [**144 Cool White LEDs per meter**](https://www.adafruit.com/product/2434)
- [**144 Warm White LEDs per meter**](https://www.adafruit.com/product/2437)

Approximate color temperature:

- Cool white: 6000–6500K
- Warm white: 3000K

White DotStars are only available with the white backing strip. Power consumption is comparable to the RGB strips. Half-meter strips not offered.

![led_strips_30cool.jpg](https://cdn-learn.adafruit.com/assets/assets/000/063/257/medium640/led_strips_30cool.jpg?1539046950)

![led_strips_30warm.jpg](https://cdn-learn.adafruit.com/assets/assets/000/063/258/medium640/led_strips_30warm.jpg?1539046954)

![led_strips_60cool.jpg](https://cdn-learn.adafruit.com/assets/assets/000/063/259/medium640/led_strips_60cool.jpg?1539046969)

![led_strips_60warm.jpg](https://cdn-learn.adafruit.com/assets/assets/000/063/260/medium640/led_strips_60warm.jpg?1539046975)

![led_strips_144cool.jpg](https://cdn-learn.adafruit.com/assets/assets/000/063/261/medium640/led_strips_144cool.jpg?1539046981)

![led_strips_144warm.jpg](https://cdn-learn.adafruit.com/assets/assets/000/063/262/medium640/led_strips_144warm.jpg?1539046987)

# Finer&nbsp;Details About Flexible DotStar Strips

- **144** pixel/m DotStar strips are sold in **one meter** &nbsp;(RGB or white) and **half meter** &nbsp;(RGB only) lengths. Each of these is a **separate** strip with end connectors. Longer contiguous lengths are _not_ offered in 144 pixels/m.
- **30** and **60** pixel/m DotStar strips are sold in&nbsp; **one meter** &nbsp;_multiples._ Orders for multiple meters will be a **single contiguous strip, up to a limit:** 4 meters for 60 pixels/m strip, 5 meters for 30 pixels/m.
- For **30** &nbsp;and **60** &nbsp;pixels/meter strips, if purchasing **less than a full reel** (4 or 5 meters, respectively), the strip&nbsp; **may or may not** &nbsp;have 4-pin JST plugs soldered at one or both ends. These plugs are for factory testing and might be at **either end** — the plug does not always indicate the input end!&nbsp; **Arrows printed on the strip show the actual data direction. You may need to solder your own wires or plug.**
- The flex strips are **enclosed** in a weatherproof silicone sleeve, making them immune to rain and splashes, but are not recommended for continuous submersion.
- The silicone sleeve can be **cut and removed** for a slimmer profile, but this compromises the strip's weather&nbsp;resistance.
- **Very few glues will adhere to the weatherproof silicone sleeve.** &nbsp;Using zip ties for a “mechanical” bond is usually faster and easier. The only reliable glues we’ve found are Permatex 66B Clear RTV Silicone (not all silicone glues will work!) and Loctite Plastics Bonding System, a 2-part cyanoacrylate glue. Customers have reported _excellent_&nbsp;results with&nbsp; **Permatex Ultra Grey Silicone Gasket Maker** as well.
- However,&nbsp; **_do not_&nbsp;use Permatex 66B silicone to seal the open end of a cut strip!** &nbsp;Like many RTV&nbsp;silicones, 66B releases acetic acid when curing, which can destroy electronics. It’s fine on the&nbsp;_outside_&nbsp;of the strip, but not the&nbsp;_inside._&nbsp;Use&nbsp; **GE Silicone II** &nbsp;for sealing strip ends, or good ol’&nbsp; **hot melt glue.**
- **2-sided carpet tape** &nbsp;provides a light grip on the silicone sleeve; something&nbsp;like a Post-It Note. Or you can try **clear duct tape** over the top.
- **All LED strips** are manufactured in **1/2 meter** segments that are then **joined** into a longer strip. The pixel spacing across these joins is usually 2-3 millimeters different than the rest. This is not a manufacturing mistake, just physical reality.

# Rigid Ultra High Density DotStar LED PCB Bar
Another linear form factor similar to a strip, but this one is **not flexible**. It features **128** _tiny_ DotStar LEDs packed into a 400 millimeter bar with wires at each end with 4-pin JST connectors.

The aluminum-backed PCB is rigid but requires support so it doesn't droop and crack. It's not intended to be bent or curved at all. Also unlike strips, this bar is **not weatherproof**.

- **[Ultra High Density DotStar LED PCB Bar - 128 LEDs](https://www.adafruit.com/product/3776)**

![led_strips_rigidon.jpg](https://cdn-learn.adafruit.com/assets/assets/000/063/263/medium640/led_strips_rigidon.jpg?1539047945)

![led_strips_rigidoff.jpg](https://cdn-learn.adafruit.com/assets/assets/000/063/264/medium640/led_strips_rigidoff.jpg?1539047954)

# Adafruit DotStar LEDs

## DotStar Matrices

 **DotStar matrices** are two-dimensional _grids_ of DotStar LEDs, all controlled from two microcontroller pins.

# Flexible DotStar Matrices
![](https://cdn-learn.adafruit.com/assets/assets/000/063/270/medium800thumb/led_strips_flexing.jpg?1539055387)

Flexible DotStar matrices are available in three different sizes:

- [**8x8 RGB pixels**](https://www.adafruit.com/product/2734)
- [**16x16 RGB pixels**](https://www.adafruit.com/product/2735)
- [**8x32 RGB pixels**](https://www.adafruit.com/product/2736)

![led_strips_flex8x8.jpg](https://cdn-learn.adafruit.com/assets/assets/000/063/265/medium640/led_strips_flex8x8.jpg?1539054521)

![led_strips_flex16x16.jpg](https://cdn-learn.adafruit.com/assets/assets/000/063/266/medium640/led_strips_flex16x16.jpg?1539054530)

![led_strips_flex32x8.jpg](https://cdn-learn.adafruit.com/assets/assets/000/063/267/medium640/led_strips_flex32x8.jpg?1539054774)

Flex matrices are about 2 millimeters&nbsp;(0.08&nbsp;inches) thick.

Though called&nbsp;“flexible,”&nbsp; **these matrices&nbsp;do not tolerate continuous and repeated bending.** &nbsp;“Formable” might be a better word — they can be bent around a rigid or semi-rigid shape, like a hat. Repeated flexing (as on costumes) will soon crack the solder connections. (The videos on the product pages are to highlight&nbsp;just how flexible these matrices&nbsp;are, but this really is a “don’t try this at home” thing.)

Flex matrices are available with **RGB pixels only;** pure white is not offered.

# Rigid DotStar Matrices

A couple of small, non-flexible variants are available:

[**Adafruit DotStar High Density 8x8 Grid**](https://www.adafruit.com/product/3444)

This is the tiniest little LED grid we could make, with **64** full RGB color pixels in a square that is only **1" by 1" square** (25.4mm x 25.4mm). Best of all, these are little DotStar LEDs, with built in PWM drivers, so you only need two digital I/O pins to get a-glowin'.

![led_strips_matrix-small.jpg](https://cdn-learn.adafruit.com/assets/assets/000/063/272/medium640/led_strips_matrix-small.jpg?1539055919)

[**Adafruit DotStar FeatherWing**](https://www.adafruit.com/product/3449)

Stacks atop any of our **Feather** microcontroller boards. Arranged in a **6x12 matrix** , each 2mm by 2mm sized RGB pixel is individually addressable. Only two pins are required to control all the LEDs.

&nbsp;

![led_strips_matrix-featherwing.jpg](https://cdn-learn.adafruit.com/assets/assets/000/063/273/medium640/led_strips_matrix-featherwing.jpg?1539055935)

# Finer&nbsp;Details About&nbsp;DotStar Matrices

As mentioned on the DotStar Strips page, keep power consumption in mind when working with DotStar matrices. With so many pixels at your disposal, it’s easy to get carried away.

![](https://cdn-learn.adafruit.com/assets/assets/000/063/271/medium800/led_strips_matrix-strips.jpg?1539055890)

If you need a size or shape of DotStar matrix that’s not offered here, it’s possible to **create your own** using sections of **DotStar strip!**

DotStar matrices don’t enforce any particular “topology” — some may have rows of pixels arranged left-to-right, others may alternate left-to-right and right-to-left rows, or they could be installed in vertical columns instead. **This will require some planning in your code.** Our _DotStarMatrix_ library supports most matrix topologies.

# Adafruit DotStar LEDs

## Individual DotStars

For advanced users needing fully customized designs, **discrete DotStar** components are available. You’ll need to provide your own PCB and surface-mount soldering skill.

# SMT DotStars
 **Surface-mount** “5050” (5 millimeter square) DotStars are available in a few varieties:

- [**5050 RGB LED — 10 Pack**](https://www.adafruit.com/product/2343)
- [**5050 Cool White LED — 10 Pack**](https://www.adafruit.com/product/2351)
- [**5050 Warm White LED — 10 Pack**](https://www.adafruit.com/product/2350)

Approximate color temperature:

- Cool white: 6000–6500K
- Warm white: 3000K

![led_strips_5050-rgb.jpg](https://cdn-learn.adafruit.com/assets/assets/000/063/274/medium640/led_strips_5050-rgb.jpg?1539058078)

![led_strips_5050-cool.jpg](https://cdn-learn.adafruit.com/assets/assets/000/063/275/medium640/led_strips_5050-cool.jpg?1539058085)

![led_strips_5050-warm.jpg](https://cdn-learn.adafruit.com/assets/assets/000/063/276/medium640/led_strips_5050-warm.jpg?1539058093)

Tiny surface-mount “ **2020** ” (2.0 millimeters square) DotStars are available in RGB (no pure white option):

- [**DotStar Micro LEDs — 10 Pack**](https://www.adafruit.com/product/3341)

![led_strips_2020-rgb.jpg](https://cdn-learn.adafruit.com/assets/assets/000/063/277/medium640/led_strips_2020-rgb.jpg?1539058320)

# Datasheets

The manufacturer’s product datasheets refer to these as “APA102” LEDs, though in reality the 5mm parts are SK9822 LEDs — “APA102 compatible” both in pinout and protocol.

[5mm “5050” RGB DotStars — SK9822 Datasheet — PDF Download](https://cdn-learn.adafruit.com/assets/assets/000/084/591/original/APA102_LED.pdf?1574117503)
[5mm “5050” White DotStars — SK9822 Datasheet — PDF Download](https://cdn-learn.adafruit.com/assets/assets/000/084/592/original/APA102_White_LED.pdf?1574117639)
[2mm “2020” RGB DotStars — APA102 Datasheet — PDF Download](https://cdn-learn.adafruit.com/assets/assets/000/084/593/original/APA102-2020_SMD_LED.pdf?1574117728)
# Adafruit DotStar LEDs

## Power and Connections

# Powering DotStar LEDs

The power requirements for DotStars are pretty much identical to NeoPixels…in fact, we’ll simply [refer you to the relevant page of the NeoPixel Überguide for pointers on estimating and routing power](../../../adafruit-neopixel-uberguide/power). In summary:

- Estimate up to 60 milliamps peak for each pixel at full brightness white.
- A ground connection is required between the microcontroller and strip, in addition to the signal lines.
- For long strips, try to add a power tap every meter or so. This prevents a brown-out effect toward the end of the strip.
- As with NeoPixels, adding a 1000µF (6.3V or higher) capacitor close to the strip (between 5V and GND wires) is a good idea, do it!

[Another guide, this one about minimizing NeoPixel power draw](https://learn.adafruit.com/sipping-power-with-neopixels), is also **100% applicable to DotStars!**

# Connecting DotStar LEDs

Our LED suppliers sometimes make unannounced production changes to the wiring. Therefore, **the best way to identify connections is a close visual examination of the strip.**

![](https://cdn-learn.adafruit.com/assets/assets/000/063/124/medium800/led_strips_leds_dotstar-silkscreen.jpg?1538880514)

First, look for arrows printed along the strip next to each LED. These show the direction of data moving down the strip…your microcontroller connects at the originating (“in”) end, the arrows point toward the “out” end. (In the photo above, our microcontroller would be located&nbsp;off the left side.)

Second, look for labels on the strip to identify the function and order of the four wires: ground, 5 Volts, data and clock…usually labeled GND, 5V, D or DI (data input) and C or CI (clock input). These will go to corresponding pins&nbsp;on your microcontroller and power supply.

Again, due to production variations, you can’t always count on wire colors or plug genders as a reliable indication of function, even if ordered at the same time. Take a close look to confirm before connecting anything.

The simplest wiring is if you can power the strip off of the microcontroller board itself. This is fine for small projects&nbsp;(one or two dozen DotStars max) because we don't light up a lot of LEDs at once.

- Connect the strip **5V** pin to the board **5V**
- Connect the strip **GND** pin to board **GND**
- Connect the strip **CI** (Clock input) and **DI** (Data input) to the board’s SPI **SCK** and **MOSI** pins (if using an **SPI** bus) or **any two digital pins** (if “bitbanging” the signals). We’ll explain this in more detail in the “ **Software** ” section of this guide.

![led_strips_power-board-direct.png](https://cdn-learn.adafruit.com/assets/assets/000/063/278/medium640/led_strips_power-board-direct.png?1539058942)

For longer strips, when you need more than 1 Amp of current, you should power with an external 5V power adapter like so.

- Connect the strip **5V** pin to the power adapter **5V**
- Connect the strip **GND** pin to board **GND and** power adapter **GND**
- Connect the strip **CI** (Clock input) and **DI** (Data input) to two digital or SPI pins as explained above.

Important: **three** points are connected to **ground** : power supply, microcontroller and DotStar strip. If there’s no common ground between the microcontroller and strip, the LED’s won’t function properly.

![led_strips_power-5v-supply.png](https://cdn-learn.adafruit.com/assets/assets/000/063/279/medium640/led_strips_power-5v-supply.png?1539059202)

DotStars are **5 Volt** devices. They _may_ respond to 3.3V signals, but this is not a guaranteed thing.&nbsp;If using a 3.3V controller (Feather, Raspberry Pi, etc.),&nbsp;add a **logic level shifter** to boost 3V logic to 5V…something like a [74AHCT125](https://www.adafruit.com/product/1787) on the data and clock pins.

![led_strips_image-1.png](https://cdn-learn.adafruit.com/assets/assets/000/063/125/medium640/led_strips_image-1.png?1538880573)

# Adafruit DotStar LEDs

## Software

DotStars got their start on Arduino, but have since branched out to other boards and languages.

Pick a category from the left column for information&nbsp;specific to each coding environment.

# Adafruit DotStar LEDs

## Arduino Library Installation

Controlling DotStars “from scratch” is tedious, so we provide a library letting you focus on the fun and interesting bits. The library works with most mainstream Arduino boards and derivatives: Uno, Mega, Adafruit Feather, etc.

# Install Adafruit\_DotStar via Library Manager

Recent versions of the Arduino IDE (1.6.2 and later) make library installation super easy via the Library Manager interface. From the **Sketch** menu, \> **Include Library** \> **Manage Libraries**...&nbsp;&nbsp;In the text input box type in " **DotStar**". Look for " **Adafruit DotStar by Adafruit**"&nbsp;and select the latest version by clicking on the popup menu next to the **Install** button. Then click on the **Install** button. After installation, you can click the " **close**" button.

![](https://cdn-learn.adafruit.com/assets/assets/000/063/280/medium800/led_strips_library-manager.png?1539060046)

# Manually Install Adafruit\_DotStar Library

If you’re using an older version of the IDE, or just want to set things up manually, “classic” installation of the library is as follows: you can visit the&nbsp;[Adafruit\_DotStar library page](https://github.com/adafruit/Adafruit_DotStar)&nbsp;at Github and download from there, or just click this button:

[Download Adafruit_DotStar for Arduino](https://github.com/adafruit/Adafruit_DotStar/archive/master.zip)
1. Uncompress the ZIP file after it’s finished downloading.
2. The resulting folder should contain the files&nbsp; **Adafruit\_DotStar.cpp** ,&nbsp; **Adafruit\_DotStar.h** &nbsp;and an “ **examples** ” sub-folder. Sometimes in Windows you’ll get an intermediate-level folder and need to move things around.
3. Rename the folder (containing the .cpp and .h files) to&nbsp; **Adafruit\_DotStar** &nbsp;(with the underscore and everything), and place it alongside your other Arduino libraries, typically in your (home folder)/Documents/Arduino/Libraries folder. Libraries should _never_&nbsp;be installed in the “Libraries” folder alongside the Arduino application itself…put them in the subdirectory of your home folder!
4. Re-start the Arduino IDE if it’s currently running.

[Here’s a tutorial](http://learn.adafruit.com/adafruit-all-about-arduino-libraries-install-use)&nbsp;that walks through the process of correctly installing Arduino libraries manually.

[Another option for Arduino is the **FastLED** library](http://fastled.io), featuring cutting-edge code with more color-handling and mathematical support functions. However, it’s a little more tricky to use…so, if connecting DotStars for the first time, we ask that you **start with the Adafruit\_DotStar library.** Once the hardware is confirmed working, you can then graduate to whatever code or library you’d like!

# A Simple Code Example: strandtest

Launch the Arduino IDE. From the&nbsp; **File** &nbsp;menu, select&nbsp; **Sketchbook**** → ****Libraries**** → ****Adafruit\_DotStar**** → ****strandtest**

![](https://cdn-learn.adafruit.com/assets/assets/000/063/282/medium800/led_strips_load-strandtest.png?1539063928)

(If the Adafruit\_DotStar rollover menu is not present, the library has not been correctly installed, or the IDE needs to be restarted after installation. Check the installation steps above to confirm it’s properly named and located.)

The “strandtest” example shows basic library use; declaring a strip object, setting LED colors and pushing this data to the strip via the `show()` method. For more advanced examples, **nearly any NeoPixel code&nbsp;should compile and run with DotStars, just changing the library #include and the strip declaration.**

Select your board type and serial port from the&nbsp; **Tools** &nbsp;menu, and try uploading to the board. If the DotStars are connected and powered as previously described, you should see a little light show.

If using a one-meter strip or less, it’s usually OK to power off the microcontroller’s 5V pin. Here’s how it might look on an Arduino Uno or Adafruit Metro board:

- Connect the strip **5V** pin to the board **5V**
- Connect the strip **GND** pin to board **GND**
- Connect the strip **CI** (Clock input) to **digital pin 5**.
- Connect the strip&nbsp; **DI** (Data input) to **digital pin 4**.

For longer strips, see the “Power and Connections” page for guidance.

Some microcontroller boards won’t have a pin 4 or 5. Not to worry, we’ll show on the next page how to change the software for different connections.

![led_strips_power-board-direct.png](https://cdn-learn.adafruit.com/assets/assets/000/063/281/medium640/led_strips_power-board-direct.png?1539060502)

# Help!
### 

Check your connections. The most common mistake is connecting to the output end of a strip rather than the input.

### 

99% of the time this is due to not having a shared ground wire connected to the Arduino. Make sure the **Ground wire from the DotStars** connects to BOTH your **power supply ground** AND the **Arduino ground**.

Another common mistake is getting the data and clock wires reversed. If you get no response from the LEDs, or they flash in an unexpected way, try swapping those two wires.

# Adafruit DotStar LEDs

## Arduino Library Use

**[Doxygen-generated documentation for the Adafruit\_DotStar library is available here.](https://adafruit.github.io/Adafruit_DotStar/html/index.html)**

 **It’s assumed at this point that you have the Adafruit\_DotStar library for Arduino installed and have run the strandtest example sketch successfully.&nbsp;** If not, return to the prior page for directions to set that up.

To learn about writing your own DotStar sketches, let’s begin by **dissecting the strandtest sketch** …

All DotStar sketches begin by including the header file:

```
#include &lt;Adafruit_DotStar.h&gt;
```

Just below this in the **strandtest** example are some extra lines that are sometimes needed…

Most microcontrollers have some kind of **SPI** bus (a high-speed serial interface to devices). If so, there’s an SPI-related header file that must be included. But a few microcontrollers (such as the diminutive Adafruit Gemma and Trinket) don’t have SPI, in which case that line should be commented out (preceded with a “//”) or simply deleted.

Speaking of Gemma and Trinket…the next line, normally commented out, should be enabled (remove the “//”) if using one of those boards.

```
// Because conditional #includes don't work w/Arduino sketches...
#include &lt;SPI.h&gt;         // COMMENT OUT THIS LINE FOR GEMMA OR TRINKET
//#include &lt;avr/power.h&gt; // ENABLE THIS LINE FOR GEMMA OR TRINKET
```

The next few lines define the **length of the strip** (30 pixels in our example, but you can change this to more or less to match your setup) and **which pins** to use for the **data** and **clock** signals. The wiring diagrams previously shown had these on 4 and 5…but they can usually be any two pins, whatever works best for you and matches your wiring:

```
#define NUMPIXELS 30 // Number of LEDs in strip

// Here's how to control the LEDs from any two pins:
#define DATAPIN    4
#define CLOCKPIN   5
Adafruit_DotStar strip(NUMPIXELS, DATAPIN, CLOCKPIN, DOTSTAR_BRG);
```

This is how we declare a DotStar&nbsp;_object._ We’ll refer to this by name later to control the strip of pixels.

The last parameter is optional — this is the color data order of the&nbsp;DotStar strip, which has changed over time in different production runs.&nbsp;Default is DOTSTAR\_BRG, so change this if you have an earlier strip. If the LEDs are basically working but coming up the wrong colors, this is usually the reason why…swap around the R, G and B until things look right.

If using an **SPI-capable** microcontroller, this usually provides better performance. However, this **must be wired to specific pins** , and it **varies among microcontrollers**. For example, on the Arduino Uno the SPI MOSI and SCK signals are on pins 11 and 13 respectively. You’ll need a pinout diagram for other boards, look for the SPI **MOSI** and **SCK** pins!

The object declaration in this case is a little different…simply leave out the data and clock pin numbers:

```
Adafruit_DotStar strip(NUMPIXELS, DOTSTAR_BRG);
```

The SPI-or-not decision affects the wiring and strip declaration, but after that everything is the same regardless.

Now, in the `setup()` function, call `begin()` to prepare the data and clock pins for DotStar output:

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

The second line, `strip.show()`, isn’t absolutely necessary, it’s just there to be thorough. That function pushes data out to the pixels…since no colors have been set yet, this initializes all the DotStars to an initial “off” state in case some were left lit by a prior program.

To set the color of an individual DotStar LED, use the `setPixelColor()` function, which can work a couple of different ways. Easiest usually involves passing a pixel number and red, green and blue color values:

```
strip.setPixelColor(index, red, green, blue);
```

`index` is the pixel number, starting at 0 (first pixel), then 1 (second pixel), up to the number of pixels in the strip minus one. Pixel indices outside this range will simply be ignored.

`red`, `green`, `blue` specify the color, each in a range from 0 (off) to 255 (maximum brightness).

For example, here’s how we’d set the first pixel (index 0) to an orangey color (100% red, 50% green, 0% blue):

```
strip.setPixelColor(0, 255, 127, 0);
```

An alternate syntax takes just two arguments, a pixel index (same as before) and a single color value as a “packed” 24-bit integer (often in hexadecimal notation…something advanced programers may be more comfortable working in):

```
strip.setPixelColor(index, color);
```

You can “pack” separate red, green and blue values into a single 32-bit type for later use:

```
uint32_t magenta = strip.Color(255, 0, 255);
```

Then later you can just pass “magenta” as an argument to `setPixelColor()` rather than the separate red, green and blue numbers every time.

**`setPixelColor()` does not have an immediate effect on the LEDs. To “push” the color data to the strip, call `show()`**:

```
strip.show();
```

This updates the whole strip at once, and despite the extra step is actually a good thing. If every call to `setPixelColor()` had an immediate effect, animation would appear jumpy rather than buttery smooth.

Multiple pixels can be set to the same color using the fill() function, which accepts one to three arguments. Typically it’s called like this:

```
strip.fill(color, first, count);
```

“color” is a packed 32-bit RGB (or RGBW) color value, as might be returned by strip.Color(). There is no option here for separate red, green and blue, so call the Color() function to pack these into one value.

“first” is the index of the first pixel to fill, where 0 is the first pixel in the strip, and strip.numPixels() - 1 is the last. Must be a positive value or 0.

“count” is the number of pixels to fill. Must be a positive value.

If called without a _count_ argument (only color and first), this will from _first_ to the end of the strip.

If called without _first_ or _count_ arguments (only color), the full strip will be set to the requested color.

If called with _no_ arguments, the strip will be filled with black or “off,” but there’s also a different syntax which might be easier to read:

```
strip.clear();
```

You can query the color of a previously-set pixel using `getPixelColor()`:

```
uint32_t color = strip.getPixelColor(11);
```

This returns a 32-bit merged color value (only the least 24 bits are used).

The number of pixels in a previously-declared strip can be queried using `numPixels()`:

```
uint16_t n = strip.numPixels();
```

The overall brightness of all the LEDs can be adjusted using `setBrightness()`. This takes a single argument, a number in the range 0 (off) to 255 (max brightness). For example, to set a strip to 1/4 brightness:

```
strip.setBrightness(64);
```

Just like `setPixel()`, **this does not have an immediate effect.** You need to follow this with a call to `show()`.

# HSV (Hue-Saturation-Value) Colors…

The DotStar library has some support for colors in the “HSV” (hue-saturation-value) color space. This is a different way of specifying colors than the usual RGB (red-green-blue). Some folks find it easier or more “natural” to think about…or quite often it’s just easier for certain color effects (the popular rainbow cycle and such).

In the DotStar library, **_hue_** is expressed as a **16-bit** number. Starting from 0 for red, this increments first toward yellow (around 65536/6, or 10922 give or take a bit), and on through green, cyan (at the halfway point of 32768), blue, magenta and back to red. In your own code, you can allow any hue-related variables to _overflow_ or _underflow_ and they’ll “wrap around” and do the correct and expected thing, it’s really nice.

_ **Saturation** _ determines the intensity or purity of the color…this is an **8-bit** number ranging from 0 (no saturation, just grayscale) to 255 (maximum saturation, pure hue). In the middle, you’ll start to get sort of pastel tones.

_ **Value** _ determines the brightness of a color…it’s also an **8-bit** number ranging from 0 (black, regardless of hue or saturation) to 255 (maximum brightness).

![led_strips_hsv-diagram.png](https://cdn-learn.adafruit.com/assets/assets/000/074/099/medium640/led_strips_hsv-diagram.png?1554498129)

setPixelColor() and fill() both still want&nbsp; **RGB** values though, so we **convert** to these from HSV by using the ColorHSV() function:

```
uint32_t rgbcolor = strip.ColorHSV(hue, saturation, value);
```

If you just want a “pure color” (fully saturated and full brightness), the latter two arguments can be left off:

```
uint32_t rgbcolor = strip.ColorHSV(hue);
```

In either case, the resulting RGB value can then be passed to a pixel-setting function, e.g.:

```
strip.fill(rgbcolor);
```

 **There is _no_ corresponding function to go the other way** , from RGB to HSV. This is on purpose and by design, because conversion in that direction is often ambiguous — there may be multiple valid possibilities for a given input. If you look at some of the example sketches you’ll see they _keep track of their own hues_…they _don’t_ assign colors to pixels and then try to read them back out again.

# …and Gamma Correction

Something you might observe when working with more nuanced color changes&nbsp;is that things may appear overly bright or washed-out.&nbsp;It’s generally not a problem with simple primary and secondary colors, but becomes more an issue with blends, transitions, and the sorts of pastel colors you might get from the ColorHSV() function. _Numerically_ the color values are correct, but _perceptually_ our eyes make something different of it, [as explained in this guide](https://learn.adafruit.com/led-tricks-gamma-correction).

The gamma32() function takes a packed RGB value (as you might get out of Color() or ColorHSV()) and filters the result to look more perceptually correct.

```
uint32_t rgbcolor = strip.gamma32(strip.ColorHSV(hue, sat, val));
```

You might notice in some sketches that we _never_ use ColorHSV() _without_ passing the result through gamma32() before setting a pixel’s color. It’s that desirable.

However, the gamma32 operation is _not built in_ to ColorHSV() — it must be called as a separate operation — for a few reasons, including that advanced programmers might want to provide a more specific color-correction function of their own design (gamma32() is a “one size fits most” approximation) or may need to keep around the original “numerically but not perceptually correct” numbers.

_There is no corresponding reverse operation._ When you set a pixel to a color filtered through gamma32(), reading back the pixel value yields that filtered color, _not_ the original RGB value. It’s precisely because of this sort of decimation that advanced DotStar programs often treat the pixel buffer as a _write-only_ resource…they generate each full frame of animation based on their own program state, _not_ as a series of read-modify-write operations.

# Help!
### 

There are two main culprits for this:

1. forgetting to call `strip.begin()` in `setup()`.
2. forgetting to call `strip.show()` after setting pixel colors.

Another (less common) possibility is running out of RAM — see the last section below. If the program _sort of_ works but has unpredictable results, consider that.

### 

Certainly! Each requires its own declaration with a unique name:

```
Adafruit_DotStar strip_a(16, 3, 4);
Adafruit_DotStar strip_b(16, 5, 6);
```

The above declares two distinct DotStar objects, one with data and clock on pins 3 and 4, the other on pins 5 and 5. Each contains 16 pixels and is using the default color order.

### 

In many cases, yes. All the strips will then show exactly the same thing. This only works up to a point though…four strips wired to the same two pins is a good and reliable number. More than that starts to get “iffy.”

### 

Different versions of DotStar LEDs expect to receive color data in a different order…and occasionally it may change if it improves production efficiency or yield.

The last argument to the `Adafruit_DotStar()` constructor lets you try different color orders. Default if unspecified is&nbsp;`DOTSTAR_BRG`.

We _don’t_ change this in each release of the library because it’s just an endless game of Whack-a-Mole…it’s only a matter of time before the manufacturers use a different order again. Find what works with the hardware you have.

# Most NeoPixel Code Adapts Easily to DotStars

**Nearly any NeoPixel code&nbsp;should compile and run with DotStars** , just changing the library #include and the strip declaration…the remaining functions are roughly the same. There may be a few exceptions, but this is usually esoteric code that’s doing NeoPixel-specific hardware trickery.

# Pixels Gobble RAM

Each DotStar requires about 3 bytes of RAM. This doesn’t sound like very much, but when you start using dozens or even hundreds of pixels, and consider that the mainstream Arduino Uno only has 2 kilobytes of RAM (often much less after other libraries stake their claim), this can be a real problem!  
  
For using really large numbers of LEDs, you might need to step up to a more potent board like the Arduino Mega or one of our M0- or M4-equipped Metro Express or Feather boards. But if you’re close and need just a little extra space, you can sometimes tweak your code to be more RAM-efficient. [This tutorial has some pointers on memory usage.](http://learn.adafruit.com/memories-of-an-arduino "Link: http://learn.adafruit.com/memories-of-an-arduino")

# Adafruit DotStar LEDs

## DotStarMatrix Library

![](https://cdn-learn.adafruit.com/assets/assets/000/063/283/medium800/led_strips_matrix-strips.jpg?1539064279)

The Adafruit\_DotStarMatrix library builds upon Adafruit\_DotStar to create two-dimensional graphic displays using DotStar LEDs. You can then easily draw shapes, text and animation without having to calculate every X/Y pixel position. Small DotStar matrices are available in the shop. Larger displays can be formed using sections of DotStar strip, as shown above.  
  
In addition to the Adafruit\_DotStar library (which was already downloaded and installed in a prior step), DotStarMatrix requires **two** additional libraries:

1. [Adafruit\_DotStarMatrix](https://github.com/adafruit/Adafruit_DotStarMatrix/archive/master.zip)
2. [Adafruit\_GFX](https://github.com/adafruit/Adafruit-GFX-Library/archive/master.zip)

If you’ve previously used any Adafruit LCD or OLED displays, you might already have the latter library installed.  
  
Installation for both is similar to Adafruit\_DotStar before: using the **Arduino Library Manager** (in recent versions of the Arduino IDE) is recommended. Otherwise, if you manually download: unzip, make sure the folder name matches the .cpp and .h files within, then move to your Arduino libraries folder and restart the IDE.

Arduino sketches need to include <u>all three headers</u> just to use this library:

```
#include &lt;Adafruit_GFX.h&gt;
#include &lt;Adafruit_DotStarMatrix.h&gt;
#include &lt;Adafruit_DotStar.h&gt;
```

If using an older (pre-1.8.10) version of the Arduino IDE, you’ll also need to locate and install [Adafruit\_BusIO](https://github.com/adafruit/Adafruit_BusIO/archive/master.zip). No need to #include a header for this one.

# Layouts

Adafruit\_DotStarMatrix uses exactly the same coordinate system, color functions and graphics commands as the Adafruit\_GFX library. If you’re new to the latter, [a separate tutorial explains its use](http://learn.adafruit.com/adafruit-gfx-graphics-library/overview "Link: http://learn.adafruit.com/adafruit-gfx-graphics-library/overview"). There are also example sketches included with the Adafruit\_DotStarMatrix library.  
  
We’ll just focus on the _constructor_ here — how to declare a two-dimensional display made from DotStars. Powering the beast is another matter, covered on a prior page.

The library handles both _single_ matrices — all DotStars in a single uniform grid — and _tiled_ matrices — multiple grids combined into a larger display:

![](https://cdn-learn.adafruit.com/assets/assets/000/063/284/medium800/led_strips_leds_single-vs-tiled.png?1539064736)

Let’s begin with the declaration for a single matrix, because it’s simpler to explain. We’ll be demonstrating the [**Adafruit DotStar FeatherWing**](https://www.adafruit.com/product/3449) in this case — a 12x6 matrix of tiny DotStars. When looking at this FeatherWing with the text in a readable orientation, the first pixel, #0, is at the bottom left. Each successive pixel is right one position — pixel 1 is directly to the right of pixel 0, and so forth. At the end of each row, the next pixel is at the left side of the next row up. This isn’t something we decide in code…it’s how the DotStars are hard-wired in the circuit board comprising the FeatherWing.

![](https://cdn-learn.adafruit.com/assets/assets/000/063/285/medium800/led_strips_matrix-wide.jpg?1539067537)

We refer to this layout as _row major_ and _progressive._ _Row major&nbsp;_means the pixels are arranged in horizontal lines (the opposite, in vertical lines, is _column major_). _Progressive_ means each row proceeds in the same direction. Some matrices will reverse direction on each row, as it can be easier to wire that way. We call that a _zigzag_ layout.  
  
However…for this example, we want to use the FeatherWing in the “tall” direction, so the Feather board is standing up on the desk with the USB cable at the top. When we turn the board this way, the matrix layout changes…

![](https://cdn-learn.adafruit.com/assets/assets/000/063/286/medium800/led_strips_matrix-tall.jpg?1539067546)

Now the first pixel is at the **top left**. Pixels increment top-to-bottom — it’s now **column major**. The order of the columns is still **progressive** though.  
  
We declare the matrix thusly:

```
Adafruit_DotStarMatrix matrix = Adafruit_DotStarMatrix(
  6, 12,  // Width, height
  11, 13, // Data pin, clock pin
  DS_MATRIX_TOP     + DS_MATRIX_LEFT +
  DS_MATRIX_COLUMNS + DS_MATRIX_PROGRESSIVE,
  DOTSTAR_BGR);
```

The first two arguments — 6 and 12 — are the width and height of the matrix, in pixels. The next two arguments — 11 and 13 — are the pin numbers to which the DotStars are connected (data and clock, respectively). On the FeatherWing this is hard-wired to digital pins 11 and 13, but on some Feather boards these physical pins have different numeric assignments, and standalone (non-FeatherWing) matrices are free to use other pins. See the&nbsp;dotstar\_wing.ino example for pin assignments on other boards.

The next argument is the interesting one. This indicates where the first pixel in the matrix is positioned and the arrangement of rows or columns. The first pixel <u>must</u> be at one of the four corners; _which_ corner is indicated by adding either DS\_MATRIX\_TOP or DS\_MATRIX\_BOTTOM to either DS\_MATRIX\_LEFT or DS\_MATRIX\_RIGHT. The row/column arrangement is indicated by further adding either DS\_MATRIX\_COLUMNS or DS\_MATRIX\_ROWS to either DS\_MATRIX\_PROGRESSIVE or DS\_MATRIX\_ZIGZAG. These values are all added to form a single value as in the above code.

DS\_MATRIX\_TOP + DS\_MATRIX\_LEFT +  
DS\_MATRIX\_COLUMNS + DS\_MATRIX\_PROGRESSIVE

The last argument is exactly the same as with the DotStar library, indicating the type of LED pixels being used. In some cases you can simply leave this argument off.

**The point of this setup is that the rest of the sketch never needs to think about the layout of the matrix. Coordinate (0,0) for drawing graphics will <u>always</u> be at the top-left for you, regardless of the actual position of the first DotStar.**

### 

Adafruit\_GFX only handles rotation. Though it would work with our example above, it doesn’t cover every permutation of rotation _and mirroring_ that may occur with certain matrix layouts, not to mention the zig-zag capability, or this next bit…

# Tiled Matrices

A _tiled_ matrix is comprised of multiple smaller DotStar matrices. This is sometimes easier for assembly or for distributing power. All of the sub-matrices need to be the **same size** , and must be ordered in a predictable manner. The `Adafruit_DotStarMatrix()`&nbsp;constructor then receives some additional arguments:

```
Adafruit_DotStarMatrix matrix = Adafruit_DotStarMatrix(
  matrixWidth, matrixHeight, tilesX, tilesY,
  dataPin, clockPin, matrixType, ledType);
```

The first two arguments are the width and height, in pixels, of <u>each</u> tiled <u>sub-matrix</u>, <u>not</u> the entire display.

The next two arguments are the number of tiles, in the horizontal and vertical direction. The dimensions of the overall display then will always be a multiple of the sub-matrix dimensions.

The fifth and sixth arguments are the data and clock pin numbers, same as before and as with the DotStar library. The last argument also follows prior behaviors, and in many cases can be left off.

The second-to-last argument though…this gets complicated…

With a single matrix, there was a starting corner, a major axis (rows or columns) and a line sequence (progressive or zigzag). This is now doubled — similar information is needed <u>both</u> for the pixel order within the individual tiles, <u>and</u> the overall arrangement of tiles in the display. As before, we add up a list of symbols to produce a single argument describing the display format.

The DS\_MATRIX\_\* symbols work the same as in the prior single-matrix case, and now refer to the individual sub-matrices within the overall display. All tiles must follow the same format. An additional set of symbols work similarly to then describe the tile order.

The first tile must be located at one of the four corners. Add either DS\_TILE\_TOP or DS\_TILE\_BOTTOM and DS\_TILE\_LEFT or DS\_TILE\_RIGHT to indicate the position of the first tile. This is independent of the position of the first pixel within the tiles; they can be different corners.

Tiles can be arranged in horizontal rows or vertical columns. Again this is independent of the pixel order within the tiles. Add either DS\_TILE\_ROWS or DS\_TILE\_COLUMNS.

Finally, rows or columns of tiles may be arranged in progressive or zigzag order; that is, every row or column proceeds in the same order, or alternating rows/columns switch direction. Add either DS\_TILE\_PROGRESSIVE or DS\_TILE\_ZIGZAG to indicate the order. **BUT** …if DS\_TILE\_ZIGZAG order is selected, alternate lines of tiles <u>must</u> be rotated 180 degrees. This is intentional and by design; it keeps the tile-to-tile wiring more consistent and simple. This rotation is <u>not</u> required for DS\_TILE\_PROGRESSIVE.

![](https://cdn-learn.adafruit.com/assets/assets/000/063/296/medium800/led_strips_Matrix-Tile-Diagram.png?1539105684)

Tiles don’t need to be square! The above is just one possible layout. The display shown at the top of this page is three 10x8 tiles assembled from DotStar strip.

Once the matrix is defined, the remainder of the project is similar to Adafruit\_DotStar. Remember to use `matrix.begin()` in the `setup()` function and `matrix.show()` to update the display after drawing. The `setBrightness()` function is also available. The library includes a couple of example sketches for reference.

# Other Layouts

For any other cases that are not uniformly tiled, you can provide your own function to remap X/Y coordinates to DotStar strip indices. This function should accept two unsigned 16-bit arguments (pixel X, Y coordinates) and return an unsigned 16-bit value (corresponding strip index). The simplest row-major progressive function might resemble this:

```
uint16_t myRemapFn(uint16_t x, uint16_t y) {
  return WIDTH * y + x;
}
```

That’s a crude example. Yours might be designed for pixels arranged in a spiral (easy wiring), or a Hilbert curve.  
  
The function is then enabled using setRemapFunction():

```
matrix.setRemapFunction(myRemapFn);
```

# RAM Again

On a per-pixel basis, Adafruit\_DotStarMatrix is no more memory-hungry than Adafruit\_DotStar, requiring 3 bytes of RAM per pixel. But the number of pixels in a two-dimensional display takes off exponentially…a 16x16 display requires _four times_ the memory of an 8x8 display, or about 768 bytes of RAM (nearly half the available space on an Arduino Uno). It can be anywhere from _tricky_ to _impossible_ to combine large displays with memory-hungry libraries such as SD or ffft. Fortunately 32-bit boards (e.g. Metro Express) are fairly mainstream now.

# Gamma Correction

Because the Adafruit\_GFX library was originally designed for LCDs (having limited color fidelity), it handles colors as 16-bit values (rather than the full 24 bits that DotStars are capable of). This is not the big loss it might seem. A quirk of human vision makes bright colors less discernible than dim ones. The Adafruit\_DotStarMatrix library uses _gamma correction_ to select brightness levels that are visually (though not numerically) equidistant. There are 32 levels for red and blue, 64 levels for green.  
  
The `Color()` function performs the necessary conversion; you don’t need to do any math. It accepts 8-bit red, green and blue values, and returns a gamma-corrected 16-bit color that can then be passed to other drawing functions.

# Adafruit DotStar LEDs

## Python & CircuitPython

It's easy to use DotStar LEDs with Python or CircuitPython and the [Adafruit CircuitPython DotStar](https://github.com/adafruit/Adafruit_CircuitPython_DotStar) module.&nbsp; This module allows you to easily write Python code that controls your LEDs.

You can use these LEDs with any CircuitPython microcontroller board or with a computer that has GPIO and Python [thanks to Adafruit\_Blinka, our CircuitPython-for-Python compatibility library](https://learn.adafruit.com/circuitpython-on-raspberrypi-linux).

# CircuitPython Microcontroller Wiring

First wire up some DotStars to your board exactly as shown on the previous pages. When using this library, you pass in the pin names you choose when you create the object. If the LEDs are on hardware SPI pins, they will create a SPI device. If they're not on a hardware SPI pin combination, they will be bit banged. Wiring up to a hardware SPI pin combination means they'll respond screaming fast! However, it also means you can't share SPI with anything else. So if you have the need for another SPI device, you can bit bang but the LEDs will respond more slowly.

Warning: 

Here's an example of wiring a Feather M0 to a DotStar strip to hardware SPI pins:

&nbsp;

- **Board USB** to **LED 5V**
- **Board GND** &nbsp;to **LED GND**
- **Board&nbsp;MO** to **LED DI**
- **Board SCK** &nbsp;to **LED CI**

&nbsp;

![led_strips_FeatherM0_DotStar_SPI_bb.jpg](https://cdn-learn.adafruit.com/assets/assets/000/063/372/medium640/led_strips_FeatherM0_DotStar_SPI_bb.jpg?1539197117)

Here is an example of wiring a Feather M0 to a DotStar strip to bit banged pins:

- **Board USB** to **LED 5V**
- **Board GND** &nbsp;to **LED GND**
- **Board D5** to **LED DI**
- **Board D6** to **LED CI**

![led_strips_FeatherM0_DotStar_BIt_Bang_bb.jpg](https://cdn-learn.adafruit.com/assets/assets/000/063/373/medium640/led_strips_FeatherM0_DotStar_BIt_Bang_bb.jpg?1539197299)

# Python Computer Wiring

Since there's _dozens_ of Linux computers/boards you can use we will show wiring for Raspberry Pi. For other platforms, [please visit the guide for CircuitPython on Linux to see whether your platform is supported](https://learn.adafruit.com/circuitpython-on-raspberrypi-linux).&nbsp;

Here's the Raspberry Pi wired with hardware SPI (faster than bit-bang but you must use a hardware SPI interface and you cannot share the SPI device since there's no chip select)

&nbsp;

- **Pi 5V** to **LED 5V**  
- **Pi GND** &nbsp;to **LED GND**
- **Pi MOSI&nbsp;** to **LED DI**
- **Pi SCLK** to **LED CI**  

&nbsp;

![led_strips_raspi_DotStar_SPI_bb.jpg](https://cdn-learn.adafruit.com/assets/assets/000/063/404/medium640/led_strips_raspi_DotStar_SPI_bb.jpg?1539274090)

Here's the Raspberry PI wired up with bit-bang SPI (you can use _any_ two digital pins, but its not as fast as hardware SPI)

- **Pi 5V** to **LED 5V**  
- **Pi GND** &nbsp;to **LED GND**
- **Pi GPIO5** to **LED DI**
- **Pi GPIO6** to **LED CI**

![led_strips_raspi_DotStar_BIt_Bang_bb.jpg](https://cdn-learn.adafruit.com/assets/assets/000/063/406/medium640/led_strips_raspi_DotStar_BIt_Bang_bb.jpg?1539278589)

# CircuitPython Installation of DotStar Library

You'll need to install the&nbsp;[Adafruit CircuitPython DotStar](https://github.com/adafruit/Adafruit_CircuitPython_DotStar)&nbsp;library on your CircuitPython board.

First make sure you are running the&nbsp;[latest version of Adafruit CircuitPython](https://learn.adafruit.com/welcome-to-circuitpython/installing-circuitpython)&nbsp;for your board.

Next you'll need to install the necessary libraries&nbsp;to use the hardware--carefully follow the steps to find and install these libraries from&nbsp;[Adafruit's CircuitPython library bundle](https://github.com/adafruit/Adafruit_CircuitPython_Bundle/releases).&nbsp; Our CircuitPython starter guide has [a great page on how to install the library bundle](https://learn.adafruit.com/welcome-to-circuitpython/circuitpython-libraries).

For non-express boards like the Trinket M0 or Gemma M0, you'll need to manually install the necessary libraries from the bundle:

- **adafruit\_dotstar.mpy**
- **adafruit\_bus\_device**

Before continuing make sure your board's lib folder or root filesystem has the&nbsp; **adafruit\_dotstar.mpy,** and **adafruit\_bus\_device**** &nbsp; **files and folders** &nbsp;**copied over.

Next[&nbsp;connect to the board's serial REPL](https://learn.adafruit.com/welcome-to-circuitpython/the-repl) so you are at the CircuitPython&nbsp; **\>\>\>** &nbsp;prompt.

# Python Installation of DotStar Library

You'll need to install the Adafruit\_Blinka library that provides the CircuitPython support in Python. This may also require verifying you are running Python 3. [Since each platform is a little different, and Linux changes often, please visit the CircuitPython on Linux guide to get your computer ready](https://learn.adafruit.com/circuitpython-on-raspberrypi-linux)!

Once that's done, from your command line run the following command:

- `sudo pip3 install adafruit-circuitpython-dotstar`

If your default Python is version 3 you may need to run 'pip' instead. Just make sure you aren't trying to use CircuitPython on Python 2.x, it isn't supported!

# CircuitPython & Python Usage

To demonstrate the usage of the this library with DotStar LEDs, we'll use the board's Python REPL.

If you're using a SPI connection run the following code to import the necessary modules and initialize SPI with a strip of 30 DotStars:

```
import board
import adafruit_dotstar as dotstar
dots = dotstar.DotStar(board.SCK, board.MOSI, 30, brightness=0.2)
```

Or if you're using bit banged pins, run the following code:

```
import board
import adafruit_dotstar as dotstar
dots = dotstar.DotStar(board.D6, board.D5, 30, brightness=0.2)
```

Now you're ready to light up your DotStar LEDs using the following properties:

- **brightness** - The overall brightness of the LED
- **fill** - Color all pixels a given color.
- **show** - Update the LED colors if `auto_write` is set to `False`.

For example, to light up the first DotStar red:

```
dots[0] = (255, 0, 0)
```

![](https://cdn-learn.adafruit.com/assets/assets/000/063/410/medium800/led_strips_DotStar_First_LED_Red.jpg?1539287882)

To light up all the DotStars green:

```
dots.fill((0, 255, 0))
```

![](https://cdn-learn.adafruit.com/assets/assets/000/063/412/medium800/led_strips_DotStar_All_LEDs_Green.jpg?1539287993)

That's all there is to getting started with CircuitPython and DotStar LEDs!

Below is an example that turns all 30 LEDs random colors. To use, download the file, rename it to **code.py** and copy it to your board!

# Full Example Code
https://github.com/adafruit/Adafruit_CircuitPython_DotStar/blob/main/examples/dotstar_simpletest.py

# Adafruit DotStar LEDs

## Python Docs


## Featured Products

### Adafruit DotStar Digital LED Strip - Black 30 LED - Per Meter

[Adafruit DotStar Digital LED Strip - Black 30 LED - Per Meter](https://www.adafruit.com/product/2237)
Move over NeoPixels, there's a new LED strip in town! These fancy new DotStar LED strips are a great upgrade for people who have loved and used NeoPixel strips for a few years but want something even better. DotStar LEDs use generic 2-wire SPI, so you can push data much faster than with...

In Stock
[Buy Now](https://www.adafruit.com/product/2237)
[Related Guides to the Product](https://learn.adafruit.com/products/2237/guides)
### Adafruit DotStar Digital LED Strip - White 30 LED - Per Meter 5m

[Adafruit DotStar Digital LED Strip - White 30 LED - Per Meter 5m](https://www.adafruit.com/product/2238)
Move over NeoPixels, there's a new LED strip in town! These fancy new DotStar LED strips are a great upgrade for people who have loved and used NeoPixel strips for a few years but want something even better. DotStar LEDs use generic 2-wire SPI, so you can push data much faster than with...

In Stock
[Buy Now](https://www.adafruit.com/product/2238)
[Related Guides to the Product](https://learn.adafruit.com/products/2238/guides)
### Adafruit DotStar Digital LED Strip - Black 60 LED - Per Meter 4m

[Adafruit DotStar Digital LED Strip - Black 60 LED - Per Meter 4m](https://www.adafruit.com/product/2239)
Move over NeoPixels, there's a new LED strip in town! These fancy new DotStar LED strips are a great upgrade for people who have loved and used NeoPixel strips for a few years but want something even better. DotStar LEDs use generic 2-wire SPI, so you can push data much faster than with...

Out of Stock
[Buy Now](https://www.adafruit.com/product/2239)
[Related Guides to the Product](https://learn.adafruit.com/products/2239/guides)
### Adafruit DotStar Digital LED Strip - White 60 LED - Per Meter 4m

[Adafruit DotStar Digital LED Strip - White 60 LED - Per Meter 4m](https://www.adafruit.com/product/2240)
Move over NeoPixels, there's a new LED strip in town! These fancy new DotStar LED strips are a great upgrade for people who have loved and used NeoPixel strips for a few years but want something even better. DotStar LEDs use generic 2-wire SPI, so you can push data much faster than with...

In Stock
[Buy Now](https://www.adafruit.com/product/2240)
[Related Guides to the Product](https://learn.adafruit.com/products/2240/guides)
### Adafruit DotStar Digital LED Strip - Black 144 LED/m - One Meter

[Adafruit DotStar Digital LED Strip - Black 144 LED/m - One Meter](https://www.adafruit.com/product/2241)
Move over NeoPixels, there's a new LED strip in town! These fancy new DotStar LED strips are a great upgrade for people who have loved and used NeoPixel strips for a few years but want something even better. DotStar LEDs use generic 2-wire SPI, so you can push data much faster than with...

In Stock
[Buy Now](https://www.adafruit.com/product/2241)
[Related Guides to the Product](https://learn.adafruit.com/products/2241/guides)
### Adafruit DotStar Digital LED Strip - White 144 LED/m - One Meter

[Adafruit DotStar Digital LED Strip - White 144 LED/m - One Meter](https://www.adafruit.com/product/2242)
Move over NeoPixels, there's a new LED strip in town! These fancy new DotStar LED strips are a great upgrade for people who have loved and used NeoPixel strips for a few years but want something even better. DotStar LEDs use generic 2-wire SPI, so you can push data much faster than with...

In Stock
[Buy Now](https://www.adafruit.com/product/2242)
[Related Guides to the Product](https://learn.adafruit.com/products/2242/guides)
### Adafruit DotStar Digital LED Strip - Black 144 LED/m - 0.5 Meter

[Adafruit DotStar Digital LED Strip - Black 144 LED/m - 0.5 Meter](https://www.adafruit.com/product/2328)
Move over NeoPixels, there's a new LED strip in town! These fancy new DotStar LED strips are a great upgrade for people who have loved and used NeoPixel strips for a few years but want something even better. DotStar LEDs use generic 2-wire SPI, so you can push data much faster than with...

In Stock
[Buy Now](https://www.adafruit.com/product/2328)
[Related Guides to the Product](https://learn.adafruit.com/products/2328/guides)
### Adafruit DotStar Digital LED Strip - White 144 LED/m - 0.5 Meter

[Adafruit DotStar Digital LED Strip - White 144 LED/m - 0.5 Meter](https://www.adafruit.com/product/2329)
Move over NeoPixels, there's a new LED strip in town! These fancy new DotStar LED strips are a great upgrade for people who have loved and used NeoPixel strips for a few years but want something even better. DotStar LEDs use generic 2-wire SPI, so you can push data much faster than with...

In Stock
[Buy Now](https://www.adafruit.com/product/2329)
[Related Guides to the Product](https://learn.adafruit.com/products/2329/guides)

## Related Guides

- [LED Campfire](https://learn.adafruit.com/led-campfire.md)
- [Adafruit Class Library for Windows IoT Core](https://learn.adafruit.com/adafruit-class-library-for-windows-iot-core.md)
- [Pixie CyberWig - A Wearable WiFi LED Visualization ](https://learn.adafruit.com/wifi-pixie-cyberwig-wearable-visualization.md)
- [CircuitPython Painter](https://learn.adafruit.com/circuitpython-painter.md)
- [Supernova Poi](https://learn.adafruit.com/supernova-poi.md)
- [DotStar Belly Dance Fans](https://learn.adafruit.com/dotstar-belly-dance-fans.md)
- [Dauntless Dotstar Gauntlets](https://learn.adafruit.com/dotstar-dauntless-gauntlets.md)
- [Morning Star POV Double Staffs](https://learn.adafruit.com/pov-dotstar-double-staff.md)
- [Monster Matrix with WLED](https://learn.adafruit.com/monster-matrix-with-wled.md)
- [Bike Wheel POV Display](https://learn.adafruit.com/bike-wheel-pov-display.md)
- [Roll-up Video Light](https://learn.adafruit.com/roll-up-video-light.md)
- [Motorized POV LED Display](https://learn.adafruit.com/motorized-pov-led-display.md)
- [Make a Zelda Master Sword with the RP2040 Prop-Maker Feather](https://learn.adafruit.com/master-sword-rp2040.md)
- [Personal UV HotSpot Parasol](https://learn.adafruit.com/personal-blacklight-uv-parasol.md)
- [Rumi Sword - KPop Demon Hunters](https://learn.adafruit.com/rumi-sword.md)
