Compile errors with Neopixel library and Dotstar library on Raspberry Pi


#41

I added this line to setup() in my sketch above, but the behaviour is still the same:

The sketch sets the colour and intensity but for the wrong pixel #…
:sweat:


#42

Do you see the difference :wink:

As I said


#43

I modified this, but still no change in behaviour…

For this I’ll have to experiment…


#44

In order to mimik the wanted initialisation that setLEDs(-1) (or any equivalent call) performs you need to do this at least once

  for (int px = 0; px < LEDCOUNT; px++)
    pxBuffer[px] = 0x000000E0;

setLEDs() had this for() loop inside its belly, setAPA102Color() is not featuring any loop hence, calling it for one pixel will always only set one pixel.

Also since you added the SPI.transfer() call to your setAPA102Color() you are sacrificing performance whenever you want to set multiple pixels before actually needing to show them.
Hence I had the separation between updating the pixel buffer (pxBuffer[]) and the actual transfer.


#45

Thanks! that was the golden tip!!!
I modified set-up like this and all works fine!
:open_mouth:

:ok_hand::yum:


#46

I rather tend to not provide ready-meal answers but rather want my code to be understandable and hence understood :wink:
It’s much more rewarding for me when I know I was able to explain a concept than just provide a solution.

With the for() loop in place that setAPA102Color(-1,0,0,0,31) call is superfluous as it wouldn’t anyway do what setLEDs(-1,0,0,0,31) would have done if it were still there :sunglasses:


#47

That’s fantastic! Even I can now understand this… :rofl:


#48

OK, I can now test this on a Photon.
Next step is to use it on the RPi…

=> Can you maybe give me a tip also how to modify this sketch to use software SPI with any 2 pins as CLK & MOSI?

(In case hardware SPI does not work for RPi …)


#49

If you have a SW SPI library then the actual LED stuff should work just the same.


#50

As you know, the DOTSTARs work without a library in this case.
Do you mean a library which does just that: Replace the SPI pins with two other pins?
I searched in the Web-IDE for SPI libraries and could not find this… Any tips?


#51

Yup, that’s what I meant.
But it doesn’t need to be SPI at all. That’s just the most convenient and fastest way for hundreds or even thousands of pixels that can be controlled via DMA without too much impact on the foreground logic.

All you need is one pin that goes hi/lo for each bit to transfer and another to actually transmit the state of the data bit. Timing is completely irrelevant which makes things quite simple.


#52

OK, currently, the setup() looks like this with hardware SPI:

void setup()
{
  SPI.begin();
  SPI.setClockSpeed(8, MHZ);
  SPI.setBitOrder(MSBFIRST);
  // All DOTSTARs must be pre-set to "0xE0" once:
  for (int px = 0; px < LEDCOUNT; px++)
    pxBuffer[px] = 0x000000E0;
}

So, I will search for an existing library for software SPI…
I’ll be back! :male_detective:


#53

I found a few libraries and will try them out.

Do you believe this one may work also on Particle devices?

I’ll try it out tomorrow when I can make some more time…


#54

Originally when you asked …

… I got the impression you already had a SW SPI library in mind and hence I suggested you can use that as is.

But if you aren’t already using one, there is little use in getting one just for that.
The reason being

Any SW SPI library will probably have just as much (potentially even more) performance impact on the rest of your code as doing it without all the extra SPI kerfuffle any library needs to bring along to implement proper SPI.

The simplest approach I’d think of would be shiftOut()
DotStars don’t need anymore than that.


#55

Ok, sounds good, thanks!

I never used this command but will try something tomorrow.

:wave: