Problem mit mehreren NeoPixel Strip's

Hallo zusammen,

Ich bin gerade am Bau eines Würfels welcher auf jeder Seite ein 8x8 Neopixel Gitter kriegt. Ich habe jede Seite einzeln als Strip gebaut, d.h. pro Strip sind das 64 NeoPixel_LED’s. Der Anfang der Ansteuerung funktionierte auch noch recht gut, allerdings merke ih jetzt als ich eine Funktion (turn_right(front):wink: anwenden will, das diese nicht richtig funktionieren will, sobald mehrere Strip’s aktiv sind. Genauer gesagt sie wird mindestens 2 mal aus geführt nachher nicht mehr.

Kann mir jemand helfen? die if Abfragen in der void Loop sollten denn Durchlauf durch diese Loop beschleunigen.

Hier noch mein Code

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif

//Pin definition for each Side/each LED-Strip with 64 Pixel's
#define Pin0 6
#define Pin1 7
#define Pin2 8
#define Pin3 9
#define Pin4 10
#define Pin5 11

// Define Strip's
Adafruit_NeoPixel strip0 = Adafruit_NeoPixel(64, Pin0, NEO_GRB + NEO_KHZ800); //front
Adafruit_NeoPixel strip1 = Adafruit_NeoPixel(64, Pin1, NEO_GRB + NEO_KHZ800); //rear
Adafruit_NeoPixel strip2 = Adafruit_NeoPixel(64, Pin2, NEO_GRB + NEO_KHZ800); //bottom
Adafruit_NeoPixel strip3 = Adafruit_NeoPixel(64, Pin3, NEO_GRB + NEO_KHZ800); //top
Adafruit_NeoPixel strip4 = Adafruit_NeoPixel(64, Pin4, NEO_GRB + NEO_KHZ800); //left_side
Adafruit_NeoPixel strip5 = Adafruit_NeoPixel(64, Pin5, NEO_GRB + NEO_KHZ800); //right_side

// Define Colors
uint32_t yellow = strip0.Color(255, 255, 0);
uint32_t white = strip0.Color(255, 255, 255);
uint32_t blue = strip0.Color(0, 0, 255);
uint32_t green = strip0.Color(0, 255, 0);
uint32_t orange = strip0.Color(255, 75, 0);
uint32_t red = strip0.Color(255, 0, 0);

// Define Startingcolor of sides
uint32_t front[8][8] = {{red, red, red, red, red, red, red, red}, {red, red, red, red, red, red, red, red}, {red, red, red, red, red, red, red, red}, {red, red, red, red, red, red, red, red}, {red, red, red, red, red, red, red, red}, {red, red, red, red, red, red, red, red}, {red, red, red, red, red, red, red, red}, {red, red, red, red, red, red, red, red}};
uint32_t back[8][8] = {{orange, orange, orange, orange, orange, orange, orange, orange}, {orange, orange, orange, orange, orange, orange, orange, orange}, {orange, orange, orange, orange, orange, orange, orange, orange}, {orange, orange, orange, orange, orange, orange, orange, orange}, {orange, orange, orange, orange, orange, orange, orange, orange}, {orange, orange, orange, orange, orange, orange, orange, orange}, {orange, orange, orange, orange, orange, orange, orange, orange}, {orange, orange, orange, orange, orange, orange, orange, orange}};
uint32_t left[8][8] = {{blue, blue, blue, blue, blue, blue, blue, blue}, {blue, blue, blue, blue, blue, blue, blue, blue}, {blue, blue, blue, blue, blue, blue, blue, blue}, {blue, blue, blue, blue, blue, blue, blue, blue}, {blue, blue, blue, blue, blue, blue, blue, blue}, {blue, blue, blue, blue, blue, blue, blue, blue}, {blue, blue, blue, blue, blue, blue, blue, blue}, {blue, blue, blue, blue, blue, blue, blue, blue}};
uint32_t right[8][8] = {{green, green, green, green, green, green, green, green}, {green, green, green, green, green, green, green, green}, {green, green, green, green, green, green, green, green}, {green, green, green, green, green, green, green, green}, {green, green, green, green, green, green, green, green}, {green, green, green, green, green, green, green, green}, {green, green, green, green, green, green, green, green}, {green, green, green, green, green, green, green, green}};
uint32_t top[8][8] = {{yellow, yellow, yellow, yellow, yellow, yellow, yellow, yellow}, {yellow, yellow, yellow, yellow, yellow, yellow, yellow, yellow}, {yellow, yellow, yellow, yellow, yellow, yellow, yellow, yellow}, {yellow, yellow, yellow, yellow, yellow, yellow, yellow, yellow}, {yellow, yellow, yellow, yellow, yellow, yellow, yellow, yellow}, {yellow, yellow, yellow, yellow, yellow, yellow, yellow, yellow}, {yellow, yellow, yellow, yellow, yellow, yellow, yellow, yellow}, {yellow, yellow, yellow, yellow, yellow, yellow, yellow, yellow}};
uint32_t bottom[8][8] = {{white, white, white, white, white, white, white, white}, {white, white, white, white, white, white, white, white}, {white, white, white, white, white, white, white, white}, {white, white, white, white, white, white, white, white}, {white, white, white, white, white, white, white, white}, {white, white, white, white, white, white, white, white}, {white, white, white, white, white, white, white, white}, {white, white, white, white, white, white, white, white}};
uint32_t duplicate[8][8];

// Save of previous Colors
uint32_t front_old[8][8];
uint32_t back_old[8][8];
uint32_t left_old[8][8];
uint32_t right_old[8][8];
uint32_t top_old[8][8];
uint32_t bottom_old[8][8];

// Write all stripes blank
void setup()
{
  strip0.setBrightness(200);
  strip1.setBrightness(200);
  strip2.setBrightness(200);
  strip3.setBrightness(200);
  strip4.setBrightness(200);
  strip5.setBrightness(200);
  strip0.begin();
  strip1.begin();
  strip2.begin();
  strip3.begin();
  strip4.begin();
  strip5.begin();
  strip0.show();
  strip1.show();
  strip2.show();
  strip3.show();
  strip4.show();
  strip5.show();
  for (int g = 0; g < 8; g++)
  {
    front[2][g] = blue;
    front[3][g] = blue;
    front[4][g] = green;
    front[5][g] = green;
    front[6][g] = white;
    front[7][g] = white;
  }
  delay(100);
}

void loop()
{
  if (front != front_old)
  {
    pannel(strip0, front);
  }
  if (back != back_old)
  {
    pannel(strip1, back);
  }
  if (left != left_old)
  {
    pannel(strip2, left);
  }
  if (right != right_old)
  {
    pannel(strip3, right);
  }
  if (top != top_old)
  {
    pannel(strip4, top);
  }
  if (bottom != bottom_old)
  {
    pannel(strip5, bottom);
  }
  backup_array(front, front_old);
  backup_array(back, back_old);
  backup_array(left, left_old);
  backup_array(right, right_old);
  backup_array(top, top_old);
  backup_array(bottom, bottom_old);
  turn_right(front);
  delay(500);
}

void pannel(Adafruit_NeoPixel strip, uint32_t pannel[8][8])
{
  strip.begin();
  strip.show();
  for (int x = 0; x < 8; x++)
  {
    int column = 8 * x;
    for (int y = 0; y < 8; y++)
    {
      strip.setPixelColor(column + y, pannel[x][y]);
    }
  }
  strip.show();
}

void backup_array(uint32_t Array[8][8], uint32_t BackupArray[8][8])
{
  for (int a = 0; a < 8; a++)
  {
    for (int b = 0; b < 8; b++)
    {
      BackupArray[a][b] = Array[a][b];
    }
  }
}

void duplicate_array(uint32_t Array[8][8])
{
  for (int a = 0; a < 8; a++)
  {
    for (int b = 0; b < 8; b++)
    {
      duplicate[a][b] = Array[a][b];
    }
  }
}

void turn_left(uint32_t turn_l[8][8])
{
  duplicate_array(turn_l);
  for (int c = 0; c < 8; c++)
  {
    for (int z = 0; z < 8; z++)
    {
      if ((z == 1) || (z == 3) || (z == 5) || (z == 7))
      {
        turn_l[z][7 - c] = duplicate[z][c];
      }
    }
  }
  duplicate_array(turn_l);
  for (int c = 0; c < 8; c++)
  {
    for (int z = 0; z < 8; z++)
    {
      turn_l[7 - c][z] = duplicate[z][c];
    }
  }
  duplicate_array(turn_l);
  for (int c = 0; c < 8; c++)
  {
    for (int z = 0; z < 8; z++)
    {
      if ((z == 1) || (z == 3) || (z == 5) || (z == 7))
      {
        turn_l[z][7 - c] = duplicate[z][c];
      }
    }
  }
}

void turn_right(uint32_t turn_r[8][8])
{
  duplicate_array(turn_r);
  for (int d = 0; d < 8; d++)
  {
    for (int w = 0; w < 8; w++)
      if ((w == 1) || (w == 3) || (w == 5) || (w == 7))
      {
        turn_r[w][7 - d] = duplicate[w][d];
      }
  }
  duplicate_array(turn_r);
  for (int d = 0; d < 8; d++)
  {
    for (int w = 0; w < 8; w++)
    {
      turn_r[d][7 - w] = duplicate[w][d];
    }
  }
  duplicate_array(turn_r);
  for (int d = 0; d < 8; d++)
  {
    for (int w = 0; w < 8; w++)
      if ((w == 1) || (w == 3) || (w == 5) || (w == 7))
      {
        turn_r[w][7 - d] = duplicate[w][d];
      }
  }
}

Lg Simon

Wie sieht denn Deine Versorgung der LED aus?

8x8 LED x 6 Seiten man 3 Farben mal 20 mA = 23A schafft das Deine Versorgung?

Gruß Tommy

Stromprobleme habe ich keine, da ich vorerst nur mit 3 Seiten arbeite. Ich würde mal behaupten am Strom kann es nicht liegen, sonst könnte es denn Command ja nicht 2mal ausführen... Ich verwende einen 200W stepdown und ein Labornetzeil, mit den 3 Seiten braucht er im moment "nur" 16 W. Oder brauch ich vl. noch mehr kondensatoren? Einer ist schon verbaut (bin im moment nicht sicher ob 470uF oder 1000uF).

Lg Simon

Ich gehe mal nicht davon aus, dass es ein RAM Problem sein sollte, da ich einen Arduino Mega verwende.

Lg Simon

Siki: Stromprobleme habe ich keine, da ich vorerst nur mit 3 Seiten arbeite. Ich würde mal behaupten am Strom kann es nicht liegen, sonst könnte es denn Command ja nicht 2mal ausführen... Ich verwende einen 200W stepdown und ein Labornetzeil, mit den 3 Seiten braucht er im moment "nur" 16 W.

Wie kommst Du auf nur 16W?

Wieso willst Du 6 verschiedene Strips an den Arduino anschließen und nicht 1 einzigen der alle 6 Seiten des Würfels beinhaltet. Hast Du den Schutzwiderstand zwiscehn Arduino un dem ersten Neopixel angeschlossen?

Grüße Uwe

Schutzwiderstand habe ich, ich verwende 6 einzelne strips, da dies aus meiner Sicht einfacher zu handeln ist und ich den Würfel ein stück weit zerlegn können muss. Insbesondere dann wenn ich den Rubikcube programmiere (4x4x4 und 2x2x2).

Auf nur 16 Watt komme ich, in dem ich alle LED's dimme und nicht immer alle Farben an sind.

So funktioniert es, aber sobald ich den Multilinecomment rausnehme nicht.. :confused:

void loop()
{
  if (front != front_old)
  {
    pannel(strip0, front);
  }
  /*
  if (back != back_old)
  {
    pannel(strip1, back);
  }
  if (left != left_old)
  {
    pannel(strip2, left);
  }
  if (right != right_old)
  {
    pannel(strip3, right);
  }
  if (top != top_old)
  {
    pannel(strip4, top);
  }
  if (bottom != bottom_old)
  {
    pannel(strip5, bottom);
  }
  */
  backup_array(front, front_old);
  /*
  backup_array(back, back_old);
  backup_array(left, left_old);
  backup_array(right, right_old);
  backup_array(top, top_old);
  backup_array(bottom, bottom_old);
  */
  turn_right(front);
  delay(500);
}

Lg Simon

Was ich noch gemerkt habe ist, dass die abfrage mit if(back != back_old) nicht richtig funktioniert, er macht das nach der if Schleife auch dann, wenn gar nichts geändert wurde.

Ich habe bei den Neopixel sowohl 470Ω vor der ersten LED in der Data Line und auch einen 1000uF 16V Kondensator verbaut.

Lg Simon

Bin mir nicht ganz sicher, aber bis vor kurzem hat NeoPixel den Output an mehreren Ausgängen gar nicht unterstützt? Ist das neu das NeoPixel das jetzt auch kann?

Grüße Heiko

Mehrer Strip’s geht laut “Adafruit NeoPixel Überguide” und ich kann es bestätigen, das was man nicht darf ist ein diesen Adafruit Type als Vaiable einer Funktion verwenden “Adafruit_NeoPixel”.
Sprich mein Problem war hier:

void pannel(Adafruit_NeoPixel strip, uint32_t pannel[8][8])
{
  strip.begin();
  for (int x = 0; x < 8; x++)
  {
    int column = 8 * x;
    for (int y = 0; y < 8; y++)
    {
      strip.setPixelColor(column + y, pannel[x][y]);
      strip.show();
    }
  }
}

Wenn man das einsetzt dann gibts keine Probleme mehr:

void Front(uint32_t pannel[8][8])
{
  for (count1 = 0; count1 < 8; count1++)
  {
    column = 8 * count1;
    for (count2 = 0; count2 < 8; count2++)
    {
      strip0.setPixelColor(column + count2, pannel[count1][count2]);
    }
  }
  strip0.show();
}

void Back(uint32_t pannel[8][8])
{
  for (count1 = 0; count1 < 8; count1++)
  {
    column = 8 * count1;
    for (count2 = 0; count2 < 8; count2++)
    {
      strip1.setPixelColor(column + count2, pannel[count1][count2]);
    }
  }
  strip1.show();
}

void Left(uint32_t pannel[8][8])
{
  for (count1 = 0; count1 < 8; count1++)
  {
    column = 8 * count1;
    for (count2 = 0; count2 < 8; count2++)
    {
      strip2.setPixelColor(column + count2, pannel[count1][count2]);
    }
  }
  strip2.show();
}

void Right(uint32_t pannel[8][8])
{
  for (count1 = 0; count1 < 8; count1++)
  {
    column = 8 * count1;
    for (count2 = 0; count2 < 8; count2++)
    {
      strip3.setPixelColor(column + count2, pannel[count1][count2]);
    }
  }
  strip3.show();
}

void Top(uint32_t pannel[8][8])
{
  for (count1 = 0; count1 < 8; count1++)
  {
    column = 8 * count1;
    for (count2 = 0; count2 < 8; count2++)
    {
      strip4.setPixelColor(column + count2, pannel[count1][count2]);
    }
  }
  strip4.show();
}

void Bottom(uint32_t pannel[8][8])
{
  for (count1 = 0; count1 < 8; count1++)
  {
    column = 8 * count1;
    for (count2 = 0; count2 < 8; count2++)
    {
      strip5.setPixelColor(column + count2, pannel[count1][count2]);
    }
  }
  strip5.show();
}

Lg Simon

Und hier noch als Abschluss mein weiter entwickelter, bis jetzt funktionierende code:

#include <SoftwareSerial.h>

SoftwareSerial mySerial(12, 13); // RX, TX

char bluetooth_in;

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif

//Pin definition for each Side/each LED-Strip with 64 Pixel's
#define Pin0 6
#define Pin1 7
#define Pin2 8
#define Pin3 9
#define Pin4 10
#define Pin5 11

int brightness = 255;

// Define Strip's
Adafruit_NeoPixel strip0 = Adafruit_NeoPixel(64, Pin0, NEO_GRB + NEO_KHZ800); //front
Adafruit_NeoPixel strip1 = Adafruit_NeoPixel(64, Pin1, NEO_GRB + NEO_KHZ800); //rear
Adafruit_NeoPixel strip2 = Adafruit_NeoPixel(64, Pin2, NEO_GRB + NEO_KHZ800); //bottom
Adafruit_NeoPixel strip3 = Adafruit_NeoPixel(64, Pin3, NEO_GRB + NEO_KHZ800); //top
Adafruit_NeoPixel strip4 = Adafruit_NeoPixel(64, Pin4, NEO_GRB + NEO_KHZ800); //left_side
Adafruit_NeoPixel strip5 = Adafruit_NeoPixel(64, Pin5, NEO_GRB + NEO_KHZ800); //right_side

// Define Colors
uint32_t yellow = strip0.Color(255, 255, 0);
uint32_t white = strip0.Color(255, 255, 255);
uint32_t blue = strip0.Color(0, 0, 255);
uint32_t green = strip0.Color(0, 255, 0);
uint32_t orange = strip0.Color(255, 75, 0);
uint32_t red = strip0.Color(255, 0, 0);

// Define Startingcolor of sides
uint32_t front[8][8];
uint32_t back[8][8];
uint32_t left[8][8];
uint32_t right[8][8];
uint32_t top[8][8];
uint32_t bottom[8][8];

// Save of previous Colors
uint32_t front_old[8][8];
uint32_t back_old[8][8];
uint32_t left_old[8][8];
uint32_t right_old[8][8];
uint32_t top_old[8][8];
uint32_t bottom_old[8][8];

// Count var
int count1;
int count2;
int column;

// Write all stripes blank
void setup()
{
  //Bluetooth
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
  Serial.println("Goodnight moon!");
  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);
  mySerial.println("Hello, world?");

  // NeoPixel's
  strip0.setBrightness(brightness);
  strip1.setBrightness(brightness);
  strip2.setBrightness(brightness);
  strip3.setBrightness(brightness);
  strip4.setBrightness(brightness);
  strip5.setBrightness(brightness);
  strip0.begin();
  strip1.begin();
  strip2.begin();
  strip3.begin();
  strip4.begin();
  strip5.begin();
  strip0.show();
  strip1.show();
  strip2.show();
  strip3.show();
  strip4.show();
  strip5.show();
  for (count1 = 0; count1 < 8; count1++)
  {
    for (count2 = 0; count2 < 8; count2++)
    {
      front[count1][count2] = red;
      back[count1][count2] = orange;
      left[count1][count2] = blue;
      right[count1][count2] = green;
      top[count1][count2] = yellow;
      bottom[count1][count2] = white;
    }
  }
  for (count1 = 0; count1 < 8; count1++)
  {
    front[2][count1] = blue;
    front[3][count1] = blue;
    front[4][count1] = green;
    front[5][count1] = green;
    front[6][count1] = white;
    front[7][count1] = white;
  }
  delay(100);
}

void loop()
{
  if (mySerial.available())
  {
    bluetooth_in = mySerial.read();
    Serial.write(bluetooth_in);
  }
  if (Serial.available())
  {
    mySerial.write(Serial.read());
  }
  if (bluetooth_in == 'r')
  {
    turn_right(front, front_old);
  }
  if (bluetooth_in == 'l')
  {
    turn_left(front, front_old);
  }
  if (bluetooth_in == 'F')
  {
    Front(front);
  }
  if (bluetooth_in == 'B')
  {
    Back(back);
  }
  if (bluetooth_in == 'L')
  {
    Left(left);
  }
  if (bluetooth_in == 'R')
  {
    Right(right);
  }
  if (bluetooth_in == 'T')
  {
    Top(top);
  }
  if (bluetooth_in == 'U')
  {
    Bottom(bottom);
  }
  //Serial.println("Turn");
  delay(100);
  //turn_right(front);
  //Serial.println("Loop End");
}

void Front(uint32_t pannel[8][8])
{
  for (count1 = 0; count1 < 8; count1++)
  {
    column = 8 * count1;
    for (count2 = 0; count2 < 8; count2++)
    {
      strip0.setPixelColor(column + count2, pannel[count1][count2]);
    }
  }
  strip0.show();
}

void Back(uint32_t pannel[8][8])
{
  for (count1 = 0; count1 < 8; count1++)
  {
    column = 8 * count1;
    for (count2 = 0; count2 < 8; count2++)
    {
      strip1.setPixelColor(column + count2, pannel[count1][count2]);
    }
  }
  strip1.show();
}

void Left(uint32_t pannel[8][8])
{
  for (count1 = 0; count1 < 8; count1++)
  {
    column = 8 * count1;
    for (count2 = 0; count2 < 8; count2++)
    {
      strip2.setPixelColor(column + count2, pannel[count1][count2]);
    }
  }
  strip2.show();
}

void Right(uint32_t pannel[8][8])
{
  for (count1 = 0; count1 < 8; count1++)
  {
    column = 8 * count1;
    for (count2 = 0; count2 < 8; count2++)
    {
      strip3.setPixelColor(column + count2, pannel[count1][count2]);
    }
  }
  strip3.show();
}

void Top(uint32_t pannel[8][8])
{
  for (count1 = 0; count1 < 8; count1++)
  {
    column = 8 * count1;
    for (count2 = 0; count2 < 8; count2++)
    {
      strip4.setPixelColor(column + count2, pannel[count1][count2]);
    }
  }
  strip4.show();
}

void Bottom(uint32_t pannel[8][8])
{
  for (count1 = 0; count1 < 8; count1++)
  {
    column = 8 * count1;
    for (count2 = 0; count2 < 8; count2++)
    {
      strip5.setPixelColor(column + count2, pannel[count1][count2]);
    }
  }
  strip5.show();
}

void backup_array(uint32_t Array[8][8], uint32_t BackupArray[8][8])
{
  for (count1 = 0; count1 < 8; count1++)
  {
    for (count2 = 0; count2 < 8; count2++)
    {
      BackupArray[count1][count2] = Array[count1][count2];
    }
  }
}

void modify(uint32_t turn_r[8][8], uint32_t backup_turn_r[8][8])
{
  backup_array(turn_r, backup_turn_r);
  for (count1 = 0; count1 < 8; count1++)
  {
    for (count2 = 0; count2 < 8; count2++)
    {
      if ((count2 == 1) || (count2 == 3) || (count2 == 5) || (count2 == 7))
      {
        turn_r[count2][7 - count1] = backup_turn_r[count2][count1];
      }
    }
  }
}

void turn_left(uint32_t turn_l[8][8], uint32_t backup_turn_l[8][8])
{
  modify(turn_l, backup_turn_l);
  backup_array(turn_l, backup_turn_l);
  for (count1 = 0; count1 < 8; count1++)
  {
    for (count2 = 0; count2 < 8; count2++)
    {
      turn_l[7 - count1][count2] = backup_turn_l[count2][count1];
    }
  }
  modify(turn_l, backup_turn_l);
}

void turn_right(uint32_t turn_r[8][8], uint32_t backup_turn_r[8][8])
{
  modify(turn_r, backup_turn_r);
  backup_array(turn_r, backup_turn_r);
  for (count1 = 0; count1 < 8; count1++)
  {
    for (count2 = 0; count2 < 8; count2++)
    {
      turn_r[count1][7 - count2] = backup_turn_r[count2][count1];
    }
  }
  modify(turn_r, backup_turn_r);
}

Lg Simon

Siki: Auf nur 16 Watt komme ich, in dem ich alle LED's dimme und nicht immer alle Farben an sind.

Das istz vieleicht der Durchschnittsverbrauch aber sicher nicht der Momentanverbrauch. Die Spannungsversorgung mußt Du auf momentanverbrauch auslegen da ansonsten auch mit dicken Elkos die Spannung zusammenbricht.

Grüße Uwe