# Photon DotStar cannot get to work

**URL:** https://community.particle.io/t/photon-dotstar-cannot-get-to-work/58619
**Category:** Libraries
**Tags:** photon
**Created:** [December 1, 2020, 3:01pm UTC](https://community.particle.io/t/photon-dotstar-cannot-get-to-work/58619 "2020-12-01T15:01:35Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![marmageek](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/marmageek/32/27325_2.png) [@marmageek](https://community.particle.io/u/marmageek)
#### Post date: [December 1, 2020, 3:01pm UTC](https://community.particle.io/t/photon-dotstar-cannot-get-to-work/58619/1 "2020-12-01T15:01:35Z")

</div>

I can animate a reel of dotstars (APA102) on an Arduino using [adafruit/Adafruit\_DotStar](https://github.com/adafruit/Adafruit_DotStar); however, when I try to use the [technobly/Particle-DotStar](https://github.com/technobly/Particle-DotStar) I cannot get it to work (in neither bit-bang nor SPI modes).

I thought initially that the 40ns/V slew rate for the level shifter was interfering; however, I slowed the SPI down by 128 ( SPI\_CLOCK\_DIV128) and still no joy.

 ![IMG_3355](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/b/3/b313d98c2814d44947b16ea720b014d2fbdb3b1b.jpeg)

```auto
// This #include statement was automatically added by the Particle IDE.
#include <dotstar.h>

// GLOBALS
#define NUMPIXLES 30
#define DEBUG true

String app = "xmas-dot-2020: spi/64";
// not working-- trying bit-bang: 
Adafruit_DotStar strip(NUMPIXLES, DOTSTAR_BGR);
// strip(numpix, data, clock)
//Adafruit_DotStar strip(NUMPIXLES, D1, D0);

void testStrip() {
    // test primary colors
    //strip.fill(strip.Color(255,0,0));
    for (int i = 0; i<strip.numPixels(); i++ ) strip.setPixelColor(i, 255,0,0);
    strip.show();
    delay(5000);
    //strip.fill(strip.Color(0,255,0));
    for (int i = 0; i<strip.numPixels(); i++ ) strip.setPixelColor(i, 0,255,0);
    strip.show();
    delay(5000);
    //strip.fill(strip.Color(0,0,255));
    for (int i = 0; i<strip.numPixels(); i++ ) strip.setPixelColor(i, 0,0,255);
    strip.show();
    delay(5000);
    //strip.fill(strip.Color(255,255,255));
    for (int i = 0; i<strip.numPixels(); i++ ) strip.setPixelColor(i, 255,255,255);
    strip.show();
    delay(5000);
    strip.clear();
    strip.show();
}

void setup() {
    strip.begin();
    strip.show();
    Particle.variable("app", app);
    
    // 201130: slowing clock down for level-shifter skew rate.
    SPI.setClockDivider(SPI_CLOCK_DIV128);
    
    if (DEBUG) {
        testStrip();
        Particle.publish("log", "Finished test");
    }
}

void loop() {

}

```

---

<div class="post-metadata">

### Author: ![peekay123](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/peekay123/32/810_2.png) [@peekay123](https://community.particle.io/u/peekay123)
#### Post date: [December 1, 2020, 3:43pm UTC](https://community.particle.io/t/photon-dotstar-cannot-get-to-work/58619/2 "2020-12-01T15:43:18Z")

</div>

@marmageek, the level shifter should work but in the picture, you have it connected for software SPI while your code is setup for hardware SPI.

Also, in your picture, you have the GND from the Photon going to the “+” rail on your protoboard!!! I’m not sure how the Photon even works there.

I looks like you are supplying power externally so I assume it is rated to supply the Photon current (say 100-350mA) and the “full-on” dostar current of 30 x 3 x 20mA or 1.8Amps. A 2Amp or more 5v supply is required. Is that what you have?

---

<div class="post-metadata">

### Author: ![marmageek](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/marmageek/32/27325_2.png) [@marmageek](https://community.particle.io/u/marmageek)
#### Post date: [December 1, 2020, 5:07pm UTC](https://community.particle.io/t/photon-dotstar-cannot-get-to-work/58619/3 "2020-12-01T17:07:44Z")

</div>

Must be the angle of the picture… all grounds, 3.3V, and 5V lines are wired correctly. Regarding the picture you are correct as that the picture at the time was wired for bit-banging. As you can see, I wired both bit-bang and SPI (you can see the commented lines of code as well. I have tried both ways and still no luck.

---

<div class="post-metadata">

### Author: ![peekay123](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/peekay123/32/810_2.png) [@peekay123](https://community.particle.io/u/peekay123)
#### Post date: [December 1, 2020, 5:12pm UTC](https://community.particle.io/t/photon-dotstar-cannot-get-to-work/58619/4 "2020-12-01T17:12:43Z")

</div>

@marmageek, you have a black wire on the RHS of the picture going from the “+” of the protoboard bus to a pin on the Photon which looks like GND. If it isn’t connected to GND, then what is it connected to?

Also, if you have a multimeter, make sure you have power everywhere you expect it, including at the dotstar connector, ideally at the connector. Do you have an oscilloscope?

---

<div class="post-metadata">

### Author: ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)
#### Post date: [December 1, 2020, 5:24pm UTC](https://community.particle.io/t/photon-dotstar-cannot-get-to-work/58619/5 "2020-12-01T17:24:52Z")

</div>

NB: I have never had the need for a level shifter on genuine APA102 strips.

The APA102 protocol is also so simple that you don’t really need a library to drive them.  
If you want specific patterns and “animations” a library may be useful, but to merely set the color you wouldn’t need much more than this.

```cpp
#define LEDCOUNT 30
uint32_t led[1 + LEDCOUNT + LEDCOUNT/16 + 1]; // element 0 (leadin) ... LEDs ... 1 leadout clock per 2 LEDs (ceil)

void setup() {
  SPI.begin();
  SPI.setClockSpeed(8, MHZ);
  SPI.setBitOrder(MSBFIRST);

  for (i=1; i <= LEDCOUNT) 
    led[i] = 0xFF; // initialize all LEDs for full brighness
}

void sendAPA102() {
    SPI.transfer(led, NULL, sizeof(led), NULL);
}

```

---

<div class="post-metadata">

### Author: ![marmageek](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/marmageek/32/27325_2.png) [@marmageek](https://community.particle.io/u/marmageek)
#### Post date: [December 7, 2020, 1:17am UTC](https://community.particle.io/t/photon-dotstar-cannot-get-to-work/58619/6 "2020-12-07T01:17:50Z")

</div>

@peekay123— It is connected to - not +. The picture is misleading. It bends back to -.

---

<div class="post-metadata">

### Author: ![marmageek](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/marmageek/32/27325_2.png) [@marmageek](https://community.particle.io/u/marmageek)
#### Post date: [December 10, 2020, 5:16pm UTC](https://community.particle.io/t/photon-dotstar-cannot-get-to-work/58619/7 "2020-12-10T17:16:14Z")

</div>

@ScruffR Indeed it does work without the level-shifter in there.

I did note thought the the spec says [0x0000] +[0xFF][BB][GG][RR]+…+[0xFFFF].  
The tail actually turns on an extra pixel to white. So I am guessing you do not need the terminating 0xFFFF.

---

<div class="post-metadata">

### Author: ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)
#### Post date: [December 10, 2020, 7:43pm UTC](https://community.particle.io/t/photon-dotstar-cannot-get-to-work/58619/8 "2020-12-10T19:43:06Z")

</div>

Actually it would be a lead-in of 0x00000000 (32 zero bits) and a lead-out of all HIGH or all LOW bits (no mixing!) of at least `number_of_pixels / 2` bits. Since SPI can only transmit in 8 bit junks you may want to add on extra byte of 0x00 or 0xFF respectively.

Here you can find a good description of the protocol and also some clarification why the datasheets are not entirely accurate (especially the end frame description)

> **[Understanding the APA102 “Superled”](https://cpldcpu.wordpress.com/2014/11/30/understanding-the-apa102-superled/)**
>
> A couple of weeks ago I reported about a new type of RGB-LED with integrated controller, the APA102. One of the interesting new features of this device is a two-wire SPI interface instead of the pr…

---

<div class="post-metadata">

### Author: ![marmageek](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/marmageek/32/27325_2.png) [@marmageek](https://community.particle.io/u/marmageek)
#### Post date: [December 10, 2020, 10:12pm UTC](https://community.particle.io/t/photon-dotstar-cannot-get-to-work/58619/9 "2020-12-10T22:12:13Z")

</div>

Hey thanks for the reference. I see from this now why my extra lamp lit as my test strand was only 5 lamps. My Christmas tree strand, however, is 300 lamps so by that math, I’d need 150 extra bits!! So I guess my code needs to calculate the end frame length based on the strand. I should also send zeros since the value doesn’t matter (just the clock pulses).

---

<div class="post-metadata">

### Author: ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)
#### Post date: [December 11, 2020, 5:54am UTC](https://community.particle.io/t/photon-dotstar-cannot-get-to-work/58619/10 "2020-12-11T05:54:49Z")

</div>

> [@ScruffR](#):
>
> ```cpp
> uint32_t led[1 + LEDCOUNT + LEDCOUNT/16 + 1] // element 0 (leadin) ... LEDs ... 1 leadout clock per 2 LEDs (ceil)
> 
> ```

This is what that calculation in my suggested code does.  
Since it doesn't matter whether you have 1s or 0s in the lead-out you can just have the array initialized with 0s (as done by default) and use it as is.

BTW

> [@ScruffR](#):
>
> ```cpp
> SPI.transfer(led, NULL, sizeof(led), NULL);
> 
> ```

when you pass a callback function instead of NULL as final parameter, you can even have the transfer happen in the background without the rest of the code being blocked while updating the pixels.

e.g.

```cpp
  SPI.transfer(led, NULL, sizeof(led), []() { updateDone = true; } );

```

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/6/4/64635adccc35238caa19e9b553ec3e98b163d026.png) [@system](https://community.particle.io/u/system)
#### Post date: [February 9, 2021, 5:55am UTC](https://community.particle.io/t/photon-dotstar-cannot-get-to-work/58619/11 "2021-02-09T05:55:09Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
