Connecting DotStar (APA102C) LEDs To Fubarino SD

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

Connecting DotStar (APA102C) LEDs To Fubarino SD

Post by BobCochran » Mon Jan 19, 2015 10:19 pm

Friends,

I want to try connecting my Fubarino SD board to one (1) DotStar LED -- here is the datasheet. https://www.adafruit.com/images/product ... PA102C.pdf I mounted this on an Adafruit "5050 LED Breakout" board.

I would like to run the DotStar from the Fubarino using the FastLed library. I have downloaded it from GitHub.

My question is about the connections needed to the Fubarino. I believe that the Fubarino has all 3.3v logic outputs, so I need to add a 74AHCT125 level shifter to shift the clock and data signals to 5v. Am I correct about this?

Secondly, the Fubarino offers SPI on silkscreen pins 24, 25, 26 and 27. I believe that I can use the pin 24 -- SCK as my clock signal, and pin 25 -- SDI as my data signal. Is this correct as well? This is another way of saying I am just now learning how to use hardware SPI.

Thanks!

Bob Cochran

EmbeddedMan
Posts: 597
Joined: Tue May 24, 2011 9:24 pm
Location: Minneapolis, MN
Contact:

Re: Connecting DotStar (APA102C) LEDs To Fubarino SD

Post by EmbeddedMan » Tue Jan 20, 2015 12:02 am

Bob,

How similar are the DotStard LEDs and NeoPixels? We have a great DMA based library for NeoPixels that works quite well on Fubarino SD. If they're similar enough, I'd suggest trying out our library. You can see a good instruction of how to use it here:

http://www.instructables.com/id/Getting ... ilent-chi/

*Brian

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

Re: Connecting DotStar (APA102C) LEDs To Fubarino SD

Post by BobCochran » Tue Jan 20, 2015 10:47 pm

Hi Brian,

The DotStar has additional pin connections as compared to the NeoPixel. I have both types of LEDs here with me. The Neopixels need 5v, ground, data in and data out connections; the DotStars need data in, clock signal in, ground, data out, clock signal out, and 5v. That is why I was asking about the SPI pins on the Fubarino.

You can be sure I will play with the Neopixel code you suggest -- I have lots of NeoPixels here, as rings, strips, and through-hole (4 wire) LEDs. But I also have one single DotStar that I soldered to a breakout board and it is the DotStar that grabs my interest at the moment.

I will experiment and see if i succeed. If I let the magic smoke out somewhere -- well, that is life, c'est la vie. I will try again. Eventually I will succeed.

Bob

User avatar
majenko
Site Admin
Posts: 2164
Joined: Wed Nov 09, 2011 7:51 pm
Location: UK
Contact:

Re: Connecting DotStar (APA102C) LEDs To Fubarino SD

Post by majenko » Tue Jan 20, 2015 11:20 pm

DotStar just uses a fairly standard serial interface. Treat them like each LED is 3 74HC164 shift registers.

Just connect MOSI (aka SDO) to the data in, and SCK to the clock in. Provide it with power and ground, then just use SPI to transfer groups of three bytes - one group for each LED. If you have a chain of 100 LEDs that will be 300 bytes.

You only need to send the colour data when you want it to change - no need to keep refreshing like NeoPixels.
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".

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

Re: Connecting DotStar (APA102C) LEDs To Fubarino SD

Post by BobCochran » Wed Jan 21, 2015 6:50 pm


Here is what I have done so far. I decided to edit some of the code I found in the examples, even though it was SPI code tailored to an Analog Devices potentiometer and not a DotStar LED. In addition, I hope to attach a photo of my wiring of the Fubarino to an 74AHCT125N level converter. The problem is, the DotStar turns on just fine. But it does not cycle through the red, green, and blue colors as I intend. Instead it shows just a steady, constant, pinkish color.

Any advice for fixing this is appreciated.

So many thanks!

Bob

Code: Select all

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


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

//Define a test color value

int myRGB0[3] = {255, 0, 0};
int myRGB1[3] = {0, 255, 0};
int myRGB2[3] = {0, 0, 255};

// set pin 27 as the slave select for the digital pot:
// const int slaveSelectPin = 27;

void setup() {
  // set the slaveSelectPin as an output:
 // pinMode (slaveSelectPin, OUTPUT);
  // initialize SPI:
  SPI.begin(); 
}

void loop() {
  // go through the six channels of the digital pot:
  for (int d1 = 0; d1 < 3; d1++) { 
    // transfer bytes to the Dotstar
    
      SPI.transfer(myRGB0[d1]);
      delay(10);
      
    }
   
   delay(2000);
   
   for (int d2 = 0; d2 < 3; d2++) { 
    // transfer bytes to the Dotstar
    
      SPI.transfer(myRGB1[d2]);
      delay(10);
      
    }
    
    delay(2000);
    
    for (int d3 = 0; d3 < 3; d3++) { 
    // transfer bytes to the Dotstar
    
      SPI.transfer(myRGB2[d3]);
      delay(10);
      
    }
    
    delay(2000);
    
  }

dotstar_conected_fubarino_small.jpg
dotstar_conected_fubarino_small.jpg (290.77 KiB) Viewed 1959 times
[/color][/size]

EmbeddedMan
Posts: 597
Joined: Tue May 24, 2011 9:24 pm
Location: Minneapolis, MN
Contact:

Re: Connecting DotStar (APA102C) LEDs To Fubarino SD

Post by EmbeddedMan » Thu Jan 22, 2015 4:09 am

I would strongly suggest throwing a logic analyzer (Saleae makes some great ones that aren't too expensive) and seeing what's actually coming out those pins. That's the best way to find what's wrong with the code.

*Brian

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

Re: Connecting DotStar (APA102C) LEDs To Fubarino SD

Post by BobCochran » Thu Jan 22, 2015 4:24 am

I'm having progress, of a sort. A lot of it is learning very basic C or C++ code, reading about how SPI is used, and then referring to the APA102C datasheet. It looks like the APA102C is expecting a "start frame" of 32 bits of zeroes, that is an "unsigned long", yes? Then it specifies a "LED frame" where the most significant 3 bits are on. followed by 5 bits that I assume can be anything, followed by three, 8-bit values in most significant bit to least significant bit order. Finally there is an "end frame" of 32 bits of all 1s.

If I try to transfer this using the code below, and hoping I will see the color red for a little more than 2 seconds followed by green for 3 seconds, I get the color red, and all the time.

It seems possible that I need to set a timing signal of some kind. The data sheet specifies a refresh rate of "400 cycle". That talks about timing, right? I'm not certain how to set a proper timing signal for it.

Brian, I just saw (part of?) your post while I was editing this one. I'll try to learn how to use a logic analyzer or my very expensive but only one time used Tektronix scope.

Thanks

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 test data frame for the APA102C

unsigned long startFrame = 0; //LED Start frame see datasheet page 3
unsigned long ledFrame1 = 0B11100000111111110000000000000000; // this appears to select red
unsigned long ledFrame2 = 0B11100000000000001111111100000000; // Hopefully this selects green
unsigned long endLedFrame = 0B11111111111111111111111111111111; // The end frame of the LED

byte myRGB0[3] = {255, 0, 0};
byte myRGB1[3] = {0, 255, 0};
byte myRGB2[3] = {0, 0, 255};

// 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() {
  // go through the six channels of the digital pot:
  // transfer 4 byte unsigned longs to the Dotstar
    
      digitalWrite(slaveSelectPin, LOW);
      SPI.transfer(startFrame);
      SPI.transfer(ledFrame1);
      SPI.transfer(endLedFrame);
      digitalWrite(slaveSelectPin, HIGH);
      delay(20);
      delay(2000);
      
      digitalWrite(slaveSelectPin, LOW);
      SPI.transfer(startFrame);
      SPI.transfer(ledFrame2);
      SPI.transfer(endLedFrame);
      digitalWrite(slaveSelectPin, HIGH);
      delay(3000);    
      
    }
       


[/color][/size]

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

Re: Connecting DotStar (APA102C) LEDs To Fubarino SD

Post by BobCochran » Thu Jan 22, 2015 10:45 pm


I did look at the Saleae website and I will see if my spouse grants permission for purchasing one. Probably their smallest model. I need to check if their analyzer software works on OS X and Linux.

It will be interesting to make the leap from thinking about my code to understanding logic analyzer output and relating that output to lines of code.

I also took a quick look at parts of the APA102 code that is in the FastLed 3.0.3 release. I can't at all claim to be a skilled C or C++ person, but whoever wrote the APA102 *.h code seems to be using "start frames" and "LED fraames" too, but it looks to me as if the frames are being defined as unsigned bytes where I'm using unsigned longs.

Don't laugh, but I actually tried to include the FastLed library in MPIDE. When the code got compile errors, and I at last realized it is meant for AVR and Freescale parts, I had a "smacks head" moment.

Bob

EmbeddedMan
Posts: 597
Joined: Tue May 24, 2011 9:24 pm
Location: Minneapolis, MN
Contact:

Re: Connecting DotStar (APA102C) LEDs To Fubarino SD

Post by EmbeddedMan » Fri Jan 23, 2015 12:02 am

Yes, their software runs on Mac OS and Linux just fine. Their little 4 channel one is sure cute. If you can manage the price of the 8-channel though, I'd suggest it, as there are lots of times when 4 bits isn't quite enough, but 99% of the time 8 is (for me anyway, and I use my Saleae's almost daily).

*Brian

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

Re: Connecting DotStar (APA102C) LEDs To Fubarino SD

Post by dangeljs » Fri Jan 23, 2015 2:47 am

Bob,

It may be worth trying to send your data byte by byte, instead of putting a 32bit word in the 'SPI.transfer()' function. I tried doing a search on the MPIDE SPI library and it doesn't look like it supports any input parameter that isn't a byte size, so maybe that is part of your problem.

Also the 5 global bits appear to refer to the LED brightness, so instead of setting to zero try using all ones or some value larger than zero.

Not sure if this is the answer to all your problems but I hope it helps.

Best of luck,

Jason

Post Reply