Forum: Mikrocontroller und Digitale Elektronik APA102 LED Strip mit Arduino Nano ansteuern


von javascripti (Gast)


Lesenswert?

Hallo,

ich verzweifel bei der Ansteuerung eiens APA102 LED Strips mit meinem 
Arduino nano.

Folgendes Schaltbild verwende ich D8->ClockIn, D9->DataIn und ich 
arbeite mit einer externen Stromversorgung fuer den LED Streifen und 
habe den Ground vom externen Netzteil an den GND PIN vom Arduino Nano 
angeschlossen. Arduino Nano wird selbst mit von USB (PC) gespeist

Hier ist  das Programm:
1
/* This example shows how to display a moving rainbow pattern on
2
 * an APA102-based LED strip. */
3
4
/* By default, the APA102 library uses pinMode and digitalWrite
5
 * to write to the LEDs, which works on all Arduino-compatible
6
 * boards but might be slow.  If you have a board supported by
7
 * the FastGPIO library and want faster LED updates, then install
8
 * the FastGPIO library and uncomment the next two lines: */
9
// #include <FastGPIO.h>
10
// #define APA102_USE_FAST_GPIO
11
12
#include <APA102.h>
13
14
// Define which pins to use.
15
const uint8_t dataPin = 11;
16
const uint8_t clockPin = 12;
17
18
// Create an object for writing to the LED strip.
19
APA102<dataPin, clockPin> ledStrip;
20
21
// Set the number of LEDs to control.
22
const uint16_t ledCount = 5;
23
24
// Create a buffer for holding the colors (3 bytes per color).
25
rgb_color colors[ledCount];
26
27
// Set the brightness to use (the maximum is 31).
28
const uint8_t brightness = 1;
29
30
void setup()
31
{
32
}
33
34
/* Converts a color from HSV to RGB.
35
 * h is hue, as a number between 0 and 360.
36
 * s is the saturation, as a number between 0 and 255.
37
 * v is the value, as a number between 0 and 255. */
38
rgb_color hsvToRgb(uint16_t h, uint8_t s, uint8_t v)
39
{
40
    uint8_t f = (h % 60) * 255 / 60;
41
    uint8_t p = (255 - s) * (uint16_t)v / 255;
42
    uint8_t q = (255 - f * (uint16_t)s / 255) * (uint16_t)v / 255;
43
    uint8_t t = (255 - (255 - f) * (uint16_t)s / 255) * (uint16_t)v / 255;
44
    uint8_t r = 0, g = 0, b = 0;
45
    switch((h / 60) % 6){
46
        case 0: r = v; g = t; b = p; break;
47
        case 1: r = q; g = v; b = p; break;
48
        case 2: r = p; g = v; b = t; break;
49
        case 3: r = p; g = q; b = v; break;
50
        case 4: r = t; g = p; b = v; break;
51
        case 5: r = v; g = p; b = q; break;
52
    }
53
    return rgb_color(r, g, b);
54
}
55
56
void loop()
57
{
58
  uint8_t time = millis() >> 4;
59
60
  for(uint16_t i = 0; i < ledCount; i++)
61
  {
62
    uint8_t p = time - i * 8;
63
    colors[i] = hsvToRgb((uint32_t)p * 359 / 256, 255, 255);
64
  }
65
66
  ledStrip.write(colors, ledCount, brightness);
67
68
  delay(10);
69
}

Es tut sich rein gar nichts am LED streifen. Habt ihr Tipps?

von Moko (Gast)


Lesenswert?

Tausch mal die Pins...
D8=11
D9=12

von Sebastian (Gast)


Lesenswert?

Das Problem scheint in ledStrip.write() zu liegen. Wie ist diese Methode 
implementiert?

LG, Sebastian

von Javascripti (Gast)


Lesenswert?

Ist ja eine Lib funktion......hier der GitHub Link
https://github.com/pololu/apa102-arduino/blob/master/APA102.cpp

von Apollo M. (Firma: @home) (majortom)


Lesenswert?

Ich würde mir mal die komplette colors[i] anzeigen lassen, um zu 
kontrollieren ob sinnige Werte drin stehen!

von Sebastian (Gast)


Lesenswert?

Javascripti schrieb:
> Ist ja eine Lib funktion......hier der GitHub Link

Ob Lib-Funktion oder eigene ist ja zunächst nicht klar.

Ich sehe bei dir ist brightness 1 von 31. Das ist ziemlich dunkel. Ist 
das gewollt?

LG, Sebastian

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.