I want to use a cAPA102 light strip to use as an audio visualizer. The light strip uses spi to communicate using MOSI for the data and then a clock signal. I looked over the wiring, and it seems right to me. Also I ran: root@bela:~# ls -l /dev/spi* and got the following messages.

crw------- 1 root root 153, 0 Nov  3 17:16 /dev/spidev1.0
crw------- 1 root root 153, 1 Nov  3 17:16 /dev/spidev2.0
crw------- 1 root root 153, 2 Nov  3 17:16 /dev/spidev2.1

I then found a library that I know works because I used it just with the pocket beagle.

#include "cAPA102.hpp"

if(cAPA102_Init(6, 2, 0, 128) == 0)
		std::cout<<"works";
cAPA102_Set_Pixel_RGB(5, 255, 0, 0);
cAPA102_Refresh();

This code initializes the strip, then sets the 5th led to red.
I put this code in an auxiliary task, and then straight in setup and it does not light up. I am using spi 2.0 by the way which corresponds to spi 1. Also I am using an external battery to supply the power. When I ran it on the pocket beagle itself it ran fine, but it wont do anything with the bela.

which pins is this connected to? Are those pins set to SPI with config-pin ?

I just did config-pin and it did not change anything. the data line is connected to the data line is connected to pin 25 and the clock is connected to pin 29

so you'd need

config-pin P2.25 spi 
config-pin P2.29 spi_sclk

Does the first one give you an error?
What about the chip select? Is that connected somewhere?

Neither of those commands cause errors. What do you mean by a chip select?

The SPI is a three or four wire protocol. normally there is one clock line, one or two data lines (mosi and/or miso) and then one chip select line, used to tell the device when It should be paying attention to the other lines. Does your device not have a chip select line? Can you link to a datasheet or tutorial?

Oh gotcha. The light strip does not have a chip select. The only lines that it has are 5v, ground, data, and clock

#include <Bela.h>
#include "cAPA102.hpp"
#include <iostream>

AuxiliaryTask lightTask;		// Auxiliary task to read/write BLE

void lights(void* data);

int readCount = 0;			// How long until we read again...
int readIntervalSamples = 100; // How many samples between reads
int readInterval = 1;

bool setup(BelaContext *context, void *userData)
{
	if(cAPA102_Init(6, 2, 1, 128) == 0)
		std::cout<<"works";
	cAPA102_Refresh();
	lightTask = Bela_createAuxiliaryTask(lights, 90, "light");
	return true;
}

void render(BelaContext *context, void *userData)
{
		if(++readCount >= readIntervalSamples) {
			readCount = 0;
			Bela_scheduleAuxiliaryTask(lightTask);
		}
	
}

void cleanup(BelaContext *context, void *userData)
{

}

void lights(void* data){
	cAPA102_Set_Pixel_RGB(5, 255, 0, 0);
	cAPA102_Refresh();
	usleep(5000);
}

is there some other setting that I am forgetting to do?

you didn't provide the full working code, so I created an example with your code, replacing

#include "cAPA102.hpp"

with

extern "C" {
#include "cAPA102.h"
}

When I run it (after the config-pin commands above), I can see the expected activity on the P2.25 and P2.29 pins on my bench oscilloscope. Not sure if this means anything for the display itself, as I don't have the device, but there is some data being transmitted.
Here is the full code: https://github.com/giuliomoro/bela-cAPA102

What is your wiring? The SPI bus is 3.3V, is it enough for the LEDs?

also worth mentioning: I see a

#define BITRATE 32000000

in the header file, but the actual clock rate I see on the scope is more like 24MHz (I seem to remember the SPI peripheral on the PocketBeagle only does 24 or 48MHz, not in-betweens).

We added the extern and changed the bit rate. We connected it to our oscilloscope, and did not get any usable data. We connected the probe to clock and still got garbage.

    achampagne We added the extern and changed the bit rate.

    just to make sure we are on exactly the same page, could you either run my code exactly as is, or send me some full code that you want me to run to test on my side?

    achampagne changed the bit rate

    I was not suggesting that necessarily, just warning that the effective rate is slower than the expected one, but I really doubt that this would make any difference for the application at hand.

    achampagne We connected it to our oscilloscope, and did not get any usable data.

    Define garbage ? Can you scope both the CLK and MOSI line with the APA102 device disconnected, take a picture and send it over?

    Our oscilloscope was being fiddly but we fixed it where we got some usable stuff. Yellow is clock and blue is MOSI. We ran you code exactly, but for some reason the lights are not turning on. I don't know exactly what the oscilloscope should be outputting. I'm guessing that the light strip might be bad, I know its receiving enough power off of the battery.

    alt text

    [I attached your picture above. Maybe the issue is not file size but image size]

    That looks ok. The values being written from C++ (obtained applying

    diff --git a/cAPA102.c b/cAPA102.c
    index a37043c..fe5a3ee 100644
    --- a/cAPA102.c
    +++ b/cAPA102.c
    @@ -146,6 +146,9 @@ void cAPA102_Refresh(void){
         for (i = cAPA012_BUF.number * 4 + 4; i < buf_len; i++)
             *(tx + i) = 0x01;
    +	for(unsigned int n = 0; n < buf_len; ++n){
    +		printf("tx[%d]: 0x%x\n", n, tx[n]);
    +	}
         ret = ioctl(cAPA012_BUF.fd_spi, SPI_IOC_MESSAGE(1), &tr);
         if (ret < 1)
             fprintf(stdout, "[Error] can't send spi message\n");

    )

    are:

    tx[0]: 0x0
    tx[1]: 0x0
    tx[2]: 0x0
    tx[3]: 0x0
    tx[4]: 0xff
    tx[5]: 0x0
    tx[6]: 0x0
    tx[7]: 0x0
    tx[8]: 0xff
    tx[9]: 0x0
    tx[10]: 0x0
    tx[11]: 0x0
    tx[12]: 0xff
    tx[13]: 0x0
    tx[14]: 0x0
    tx[15]: 0x0
    tx[16]: 0xff
    tx[17]: 0x0
    tx[18]: 0x0
    tx[19]: 0x0
    tx[20]: 0xff
    tx[21]: 0x0
    tx[22]: 0x0
    tx[23]: 0x0
    tx[24]: 0xff
    tx[25]: 0x0
    tx[26]: 0x0
    tx[27]: 0xff
    tx[28]: 0x1
    tx[29]: 0x1

    What you should expect is the MOSI line to be high when transmitting a 1 and low when transmitting a 0. Each burst of the clock (which is actually 8 periods of a squarewave at 24MHz) corresponds to one byte.

    I get this on my scope:

    alt text

    which matches perfectly.

    If you zoom out a bit on yours you'd probably get something similar. I'd say it's the LED strip that is faulty ... In case you suspect the Bela image, you can always try to flash a beagleboard.org image on a spare SD card and see if it works with that.

    It was the lightstrip. we replaced it and it worked.