Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hardware SPI not working #415

Closed
tripzero opened this issue Jun 11, 2015 · 13 comments
Closed

Hardware SPI not working #415

tripzero opened this issue Jun 11, 2015 · 13 comments

Comments

@tripzero
Copy link

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.

@donaldej
Copy link

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;
}

@tripzero
Copy link
Author

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

@donaldej
Copy link

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

@tripzero
Copy link
Author

@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.

@donaldej
Copy link

Ah, no.

I only tried the other constructor.

@me-no-dev
Copy link
Collaborator

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
Copy link
Collaborator

replace with:

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

@tripzero
Copy link
Author

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).

@bfmike
Copy link

bfmike commented Jun 20, 2015

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..

@me-no-dev
Copy link
Collaborator

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 :)

@igrr igrr closed this as completed Jul 23, 2015
@tripzero
Copy link
Author

Is fixed?

@igrr
Copy link
Member

igrr commented Jul 23, 2015

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 notifications@github.com wrote:

Is fixed?


Reply to this email directly or view it on GitHub
#415 (comment).

@Yona-Appletree
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants