Connecting DotStar (APA102C) LEDs To Fubarino SD

BobCochran
Posts: 20
Joined: Mon Jan 12, 2015 3:09 am

Re: Connecting DotStar (APA102C) LEDs To Fubarino SD

Post by BobCochran » Fri Jan 23, 2015 3:52 am

Thank you, Brian and Jason! I will keep plugging away at the code going byte by byte and I'll also see if I can get that 8 channel logic analyzer. I spent the evening reading about logic analyzers and thinking about how to bring this up to my spouse.

Bob

BobCochran
Posts: 20
Joined: Mon Jan 12, 2015 3:09 am

Re: Connecting DotStar (APA102C) LEDs To Fubarino SD

Post by BobCochran » Sat Jan 24, 2015 1:52 am

(Excited look) Jason, your suggestion seems to have worked. I changed my code to use byte arrays for the start, led, and end frames of the APA102C device and now the chip is cycling through the colors. The funny thing is...it starts with green, then blue, then red. I had thought it would start with red, then green, then blue. This has something to do with the most/least significant bit transfer ordering, does it?

Brian, I got spouse permission to order the logic analyzer. I will do that some time this weekend.

My code and a photo follow.

Thank you, Brian and Jason, for your advice!

Bob

Code: Select all

/*
  Test APA102C (DotStar) LED
  
  This example controls APA102C "DotStar" LED.
  
 
 created 21 January 2015
 by Bob Cochran
 
 
 
*/


// include the SPI library:
#include <SPI.h>

//Define a set of test data frames for the APA102C, as unsigned byte arrays

byte myStartFrame[4] = {0, 0, 0, 0};                // LED "start frame" see datasheet page 3
byte ledFrame1[4] = {0B11111111, 0B11111111, 0, 0}; // this appears to select green
byte ledFrame2[4] = {0B11111111, 0, 0B11111111, 0}; // this appears to select a weakened blue
byte ledFrame3[4] = {0B11111111, 0, 0, 0B11111111}; // this appears to select red
byte endLedFrame[4] = {0xff, 0xff, 0xff, 0xff};     // The end frame of the LED

// set pin 27 as the slave select for the LED?
// It should not be needed?
const int slaveSelectPin = 27;

void setup() {
  Serial.begin(115200);
  delay(3000);
  Serial.println("Test message in the setup loop\n");
  // set the slaveSelectPin as an output:
  pinMode (slaveSelectPin, OUTPUT);
  // initialize SPI:
  SPI.begin(); 
}

void loop() {
  
  // transfer 4 byte unsigned longs to the Dotstar
    
      digitalWrite(slaveSelectPin, LOW);
      
      for (int i = 0; i < 4; i++) {
         SPI.transfer(myStartFrame[i]);
      }
      
      for (int j = 0; j < 4; j++) {
        
        SPI.transfer(ledFrame1[j]);
      }
      
      for (int k = 0; k < 4; k++) {
        
        SPI.transfer(endLedFrame[k]);
      }
      
      digitalWrite(slaveSelectPin, HIGH);
      delay(5000);
      
      /* The code above seems to be selecting green. 
       * let us try ledFrame2[] and see what color 
       * we get.                                   */
      
      digitalWrite(slaveSelectPin, LOW);
      
      for (int i = 0; i < 4; i++) {
         SPI.transfer(myStartFrame[i]);
      }
      
      for (int j = 0; j < 4; j++) {
        
        SPI.transfer(ledFrame2[j]);
      }
      
      for (int k = 0; k < 4; k++) {
        
        SPI.transfer(endLedFrame[k]);
      }
      
      digitalWrite(slaveSelectPin, HIGH);
      delay(5000);
      
       /* The code above seems to be selecting blue. 
       * let us try ledFrame3[] and see what color 
       * we get.                                   */
      
      digitalWrite(slaveSelectPin, LOW);
      
      for (int i = 0; i < 4; i++) {
         SPI.transfer(myStartFrame[i]);
      }
      
      for (int j = 0; j < 4; j++) {
        
        SPI.transfer(ledFrame3[j]);
      }
      
      for (int k = 0; k < 4; k++) {
        
        SPI.transfer(endLedFrame[k]);
      }
      
      digitalWrite(slaveSelectPin, HIGH);
      delay(5000);
      
           
    }
 
dotstar_running_from_pic32_board_small.jpg
dotstar_running_from_pic32_board_small.jpg (219.44 KiB) Viewed 1017 times
[/color][/size]

dangeljs
Posts: 82
Joined: Thu Jun 09, 2011 8:22 pm

Re: Connecting DotStar (APA102C) LEDs To Fubarino SD

Post by dangeljs » Sat Jan 24, 2015 4:08 am

Bob,

Glad to hear it worked! I know that feeling you get when you finally get something to work after spending frustrating hours trying what seems like everything. So I'm sure you have a little high.

As for the bit order, I wouldn't think this would have been a problem since you are only sending bytes of all 1's or all 0's. I wonder if the datasheet has a misprint on the ordering of the green and blue byte order.

It sounds like you are on the right track to fun project.

Enjoy,

Jason

ricklon
Posts: 178
Joined: Sun May 22, 2011 6:59 am

Re: Connecting DotStar (APA102C) LEDs To Fubarino SD

Post by ricklon » Mon Dec 21, 2015 7:44 pm

The Dotstar Library from Adafruit works great. Both hardware SPI and SoftSPI both function.

Here's a link to some examples:
https://github.com/fubarlabs/circuitsun ... ster/week4

I recommend using the chipKIT-core plus Arudino.
http://chipkit.net/wiki/index.php?title=ChipKIT_core

Post Reply