Arduino icon indicating copy to clipboard operation
Arduino copied to clipboard

Hardware SPI not working

Open tripzero opened this issue 11 years ago • 13 comments

I'm using adafruits dotstar library with a dotstar strip. Using hardware SPI doesn't seem to work with their example: https://github.com/adafruit/Adafruit_DotStar/blob/master/examples/strandtest/strandtest.ino

To test, change example data/clock pins to 13 and 14. run. Bitbanging SPI should work. A simple volt meter on pin 13 will read 3.xx volts. To fail, change:

Adafruit_DotStar strip = Adafruit_DotStar(
  NUMPIXELS, DATAPIN, CLOCKPIN, DOTSTAR_BRG);

to

Adafruit_DotStar strip = Adafruit_DotStar(
  NUMPIXELS, DOTSTAR_BRG);

This will tell the library to use the SPI library instead of bitbanging. When probing via volt meter, no voltage is read. Lights do nothing.

tripzero avatar Jun 11 '15 19:06 tripzero

Try this. Also, you need a logic level shifter on your data and clock.

GPIO13 = MOSI GPIO15 = CLK (I am pretty sure. Try dumping the SCK constant to serial to be certain.);

pin definition https://github.com/esp8266/Arduino/blob/25ae1dba790660198bf2aca18098efde6a3e0410/hardware/esp8266com/esp8266/variants/wifio/pins_arduino.h

ALSO ALSO : Make sure the GND going to your LED's share the GND going to the ESP.

#include <Adafruit_DotStar.h>
#include <SPI.h>

#define NUMPIXELS 8

#define DATAPIN    MOSI
#define CLOCKPIN   SCK
Adafruit_DotStar strip = Adafruit_DotStar(NUMPIXELS, DATAPIN, CLOCKPIN);

void setup() {
  strip.begin();
  strip.show();
}
int      head  = 0, tail = -10;
uint32_t color = 0xFF0000;

void loop() {

  strip.setPixelColor(head, color);
  strip.setPixelColor(tail, 0);
  strip.show();
  delay(500);

  if(++head >= NUMPIXELS) {
    head = 0;
    if((color >>= 8) == 0)
      color = 0xFF0000;
  }
  if(++tail >= NUMPIXELS) tail = 0;
}

donaldej avatar Jun 12 '15 13:06 donaldej

I'll try SCK. I'm using the 74AHCT125 for level shifting.

The sparkfun guide says 14 is spi clk. It may be an error in their documentation: https://learn.sparkfun.com/tutorials/esp8266-thing-hookup-guide/hardware-overview

tripzero avatar Jun 12 '15 15:06 tripzero

I think it is 14. I cant remember. I dont have it hooked up right now. I had it working using those constants though.

edit: Actually it is 14

https://github.com/esp8266/Arduino/blob/25ae1dba790660198bf2aca18098efde6a3e0410/hardware/esp8266com/esp8266/variants/generic/pins_arduino.h

donaldej avatar Jun 12 '15 15:06 donaldej

@iamthemadz did you use this constructor:

Adafruit_DotStar strip = Adafruit_DotStar( NUMPIXELS, DOTSTAR_BRG);

If you use the one in your example, it'll use those pins but bitbang instead of using the SPI library.

tripzero avatar Jun 12 '15 16:06 tripzero

Ah, no.

I only tried the other constructor.

donaldej avatar Jun 12 '15 16:06 donaldej

I think this line in the CPP file of the Lib is your problem:

SPI.setClockDivider((F_CPU + 4000000L) / 8000000L); // 8-ish MHz on Due

me-no-dev avatar Jun 12 '15 18:06 me-no-dev

replace with:

#ifdef ESP8266
SPI.setFrequency(8000000L);
#else
SPI.setClockDivider((F_CPU + 4000000L) / 8000000L); // 8-ish MHz on Due
#endif

me-no-dev avatar Jun 12 '15 18:06 me-no-dev

The above change seems to do something... but not what I expect. The lights turn on, but are extremely dim and after all the lights turn on, only the first LED changes colors (the others turn off).

tripzero avatar Jun 15 '15 00:06 tripzero

Check your power supply.. I had all kinds of problems with a 0.5A supply that I thought would be plenty enough for a couple of LEDs but it wasn't..

bfmike avatar Jun 20 '15 13:06 bfmike

from Adafruit's site: "Estimate up to 60 milliamps peak for each pixel at full brightness white." it's really best to supply anything external with separate LDO or whatever, in order to get stable power to the ESP. I have also scratched my bold head way too much, just to find that it was power issue. Exceptions are only some low power sensors. The ESP on it's own is quite hungry :)

me-no-dev avatar Jun 20 '15 13:06 me-no-dev

Is fixed?

tripzero avatar Jul 23 '15 20:07 tripzero

There was no feedback for one month since the last two suggestions, so I closed this. Feel free to reopen if these suggestions didn't help.

On Thu, Jul 23, 2015, 23:55 Kevron Rees [email protected] wrote:

Is fixed?

— Reply to this email directly or view it on GitHub https://github.com/esp8266/Arduino/issues/415#issuecomment-124237898.

igrr avatar Jul 23 '15 21:07 igrr

Thanks everyone for this advice. With the above SPI modification to the DotStar library, everything works great! It actually works fine without a level shifter, APA102s are fairly tolerant when it comes to signal voltage, it would seem (and the first LED shifts the voltage for subsequent ones). To recap, I connect CLK to pin 14 and DATA to pin 13, after applying the above patch to AdaFruit_DotStar.

Yona-Appletree avatar Oct 09 '15 05:10 Yona-Appletree