Problem mit Uno vs Mega bei gleichen Sketch

Hallo

ich habe folgends kleines Problem.
Ich nutze für ein Ambilight, Adalight mit folgendem Sketch.
Als Ansteuerung dient Ambibox unter Windows.

Meins sketch ist zwar etwas angepasst für APA102 4Wire und bei init Colorflash aber das macht keinen Unterschied.

Mit dem Uno funktioniert das ganze fehlerfrei, sollte doch mal was "hängen" Ambibox Software schliessen, öffnen und der sketch wird neu initialisiert -> Colorflash geht wieder alles.

Mit dem Mega funktionert das ganze auch, allerdings reagiert er nicht auf die Neuinitialisierung via Software, selbst Usb ziehen reicht nicht. Nur Computerneustart(manchmal auch 2mal).

Da das ganze auf dem Uno läuft, denke ich eher an ein Problem mit dem Serialusbtreiber für den Mega, oder die Ansteuerung des Mega im Sketch, da der Mega wohl intern mehr als eine ser. Schnittstelle hat.

Bin für Input egal in welche Richtung dankbar.

MfG Alex

Dann zeig uns mal Deinen umgebauten Sketch und nicht einen, den Du gar nicht benutzt.
Grüße Uwe

Hallo,

kein Problem hier ist mein Sketch.

// --- General Settings
static const uint16_t
Num_Leds   =  268;             // strip length
static const uint8_t
Brightness =  255;             // maximum brightness


// --- FastLED Setings

// 3 wire (pwm): NEOPIXEL BTM1829 TM1812 TM1809 TM1804 TM1803 UCS1903 UCS1903B UCS1904 UCS2903 WS2812 WS2852
//               S2812B SK6812 SK6822 APA106 PL9823 WS2811 WS2813 APA104 WS2811_40 GW6205 GW6205_40 LPD1886 LPD1886_8BIT
// 4 wire (spi): LPD8806 WS2801 WS2803 SM16716 P9813 APA102 SK9822 DOTSTAR

#define LED_TYPE APA102     // led strip type for FastLED

// For 3 wire led stripes line Neopixel/Ws2812, which have a data line, ground, and power, you just need to define DATA_PIN.
// For led chipsets that are SPI based (four wires - data, clock, ground, and power), both defines DATA_PIN and CLOCK_PIN are needed

// DATA_PIN, or DATA_PIN, CLOCK_PIN
//#define LED_PINS 6        // 3 wire leds
#define Led_Pins 12, 13     // 4 wire leds
#define COLOR_ORDER  BGR    // color order for bitbang

// --- Serial Settings
#define SERIAL_TX_BUFFER_SIZE 256
#define SERIAL_RX_BUFFER_SIZE 256

static const unsigned long
SerialSpeed    = 512000; // serial port speed
static const uint16_t
SerialTimeout  = 10;      // time before LEDs are shut off if no data (in seconds), 0 to disable

// --- Optional Settings (uncomment to add)
#define SERIAL_FLUSH         // Serial buffer cleared on LED latch
#define CLEAR_ON_START     // LEDs are cleared on reset
//#define GROUND_PIN 10      // additional grounding pin (optional)
//#define CALIBRATE          // sets all LEDs to the color of the first

// --- Debug Settings (uncomment to add)
//#define DEBUG_LED 13       // toggles the Arduino's built-in LED on header match
//#define DEBUG_FPS 8        // enables a pulse on LED latch

// --------------------------------------------------------------------

#include <FastLED.h>

CRGB leds[Num_Leds];
uint8_t * ledsRaw = (uint8_t *)leds;

// A 'magic word' (along with LED count & checksum) precedes each block
// of LED data; this assists the microcontroller in syncing up with the
// host-side software and properly issuing the latch (host I/O is
// likely buffered, making usleep() unreliable for latch). You may see
// an initial glitchy frame or two until the two come into alignment.
// The magic word can be whatever sequence you like, but each character
// should be unique, and frequent pixel values like 0 and 255 are
// avoided -- fewer false positives. The host software will need to
// generate a compatible header: immediately following the magic word
// are three bytes: a 16-bit count of the number of LEDs (high byte
// first) followed by a simple checksum value (high byte XOR low byte
// XOR 0x55). LED data follows, 3 bytes per LED, in order R, G, B,
// where 0 = off and 255 = max brightness.

static const uint8_t magic[] = {
  'A', 'd', 'a'
};
#define MAGICSIZE  sizeof(magic)

// Check values are header byte # - 1, as they are indexed from 0
#define HICHECK    (MAGICSIZE)
#define LOCHECK    (MAGICSIZE + 1)
#define CHECKSUM   (MAGICSIZE + 2)

enum processModes_t {Header, Data} mode = Header;

static int16_t
c;
static uint16_t
outPos;
static uint32_t
bytesRemaining;
static unsigned long
t,
lastByteTime,
lastAckTime;

// Debug macros initialized
#ifdef DEBUG_LED
#define ON  1
#define OFF 0

#define D_LED(x) do {digitalWrite(DEBUG_LED, x);} while(0)
#else
#define D_LED(x)
#endif

#ifdef DEBUG_FPS
#define D_FPS do {digitalWrite(DEBUG_FPS, HIGH); digitalWrite(DEBUG_FPS, LOW);} while (0)
#else
#define D_FPS
#endif

void setup() {
#ifdef GROUND_PIN
  pinMode(GROUND_PIN, OUTPUT);
  digitalWrite(GROUND_PIN, LOW);
#endif

#ifdef DEBUG_LED
  pinMode(DEBUG_LED, OUTPUT);
  digitalWrite(DEBUG_LED, LOW);
#endif

#ifdef DEBUG_FPS
  pinMode(DEBUG_FPS, OUTPUT);
#endif

  FastLED.addLeds<LED_TYPE, Led_Pins, COLOR_ORDER>(leds, Num_Leds);
  FastLED.setBrightness(Brightness);

#ifdef CLEAR_ON_START
  FastLED.show();
#endif

  // initial RGB flash

  LEDS.showColor(CRGB(255, 0, 0));
  delay(700);
  LEDS.showColor(CRGB(0, 255, 0));
  delay(700);
  LEDS.showColor(CRGB(0, 0, 255));
  delay(700);
  LEDS.showColor(CRGB(255, 255, 255));
  delay(700);
  LEDS.showColor(CRGB(0, 0, 0));

  Serial.begin(SerialSpeed);
  Serial.print("Ada\n"); // Send ACK string to host

  lastByteTime = lastAckTime = millis(); // Set initial counters
}

void loop() {
  adalight();
}

void adalight() {
  t = millis(); // Save current time

  // If there is new serial data
  if ((c = Serial.read()) >= 0) {
    lastByteTime = lastAckTime = t; // Reset timeout counters

    switch (mode) {
      case Header:
        headerMode();
        break;
      case Data:
        dataMode();
        break;
    }
  }
  else {
    // No new data
    timeouts();
  }
}

void headerMode() {
  static uint8_t
  headPos,
  hi, lo, chk;

  if (headPos < MAGICSIZE) {
    // Check if magic word matches
    if (c == magic[headPos]) {
      headPos++;
    }
    else {
      headPos = 0;
    }
  }
  else {
    // Magic word matches! Now verify checksum
    switch (headPos) {
      case HICHECK:
        hi = c;
        headPos++;
        break;
      case LOCHECK:
        lo = c;
        headPos++;
        break;
      case CHECKSUM:
        chk = c;
        if (chk == (hi ^ lo ^ 0x55)) {
          // Checksum looks valid. Get 16-bit LED count, add 1
          // (# LEDs is always > 0) and multiply by 3 for R,G,B.
          D_LED(ON);
          bytesRemaining = 3L * (256L * (long)hi + (long)lo + 1L);
          outPos = 0;
          memset(leds, 0, Num_Leds * sizeof(struct CRGB));
          mode = Data; // Proceed to latch wait mode
        }
        headPos = 0; // Reset header position regardless of checksum result
        break;
    }
  }
}

void dataMode() {
  // If LED data is not full
  if (outPos < sizeof(leds)) {
    dataSet();
  }
  bytesRemaining--;

  if (bytesRemaining == 0) {
    // End of data -- issue latch:
    mode = Header; // Begin next header search
    FastLED.show();
    D_FPS;
    D_LED(OFF);
#ifdef SERIAL_FLUSH
    serialFlush();
#endif
  }
}

void dataSet() {
#ifdef CALIBRATE
  if (outPos < 3)
    ledsRaw[outPos++] = c;
  else {
    ledsRaw[outPos] = ledsRaw[outPos % 3]; // Sets RGB data to first LED color
    outPos++;
  }
#else
  ledsRaw[outPos++] = c; // Issue next byte
#endif
}

void timeouts() {
  // No data received. If this persists, send an ACK packet
  // to host once every second to alert it to our presence.
  if ((t - lastAckTime) >= 1000) {
    Serial.print("Ada\n"); // Send ACK string to host
    lastAckTime = t; // Reset counter

    // If no data received for an extended time, turn off all LEDs.
    if (SerialTimeout != 0 && (t - lastByteTime) >= (uint32_t) SerialTimeout * 1000) {
      memset(leds, 0, Num_Leds * sizeof(struct CRGB)); //filling Led array by zeroes
      FastLED.show();
      mode = Header;
      lastByteTime = t; // Reset counter
    }
  }
}

void serialFlush() {
  while (Serial.available() > 0) {
    byte r = Serial.read();
  }
}

Ich habe wie gesagt, das obrige nur angepasst für 4pin Apa102, serial buffer erhöht, und den RGB flash.

Danke schon mal für drüberschauen.

MfG Alex

Da das ganze auf dem Uno läuft, denke ich eher an ein Problem mit dem Serialusbtreiber für den Mega, oder die Ansteuerung des Mega im Sketch, da der Mega wohl intern mehr als eine ser. Schnittstelle hat.

Der Mega wird vom gleichen Treiber angesteuert, das beide den gleichen Prozessor für die USB-Anbindung verwenden (ATmega16U2), welcher die gleiche Firmware fährt.

Der Mega hat wohl mehr als eine serielle Schnittstelle, aber die erste wird praktisch identisch angesteuert wie beim UNO.

Deine Beschreibung des Problems deutet weniger auf ein Arduino-Problem, sondern mehr auf ein PC-Problem.

Arduino-seitig würde ich eher erwarten, dass der UNO Probleme bereitet, da Du sehr viel RAM verbrauchst. Der Mega hat viermal soviel RAM wie der UNO.

Hi deshalb wollte ich ja den Mega nutzen weil der Ram mit knapp wird.
Beim Uno nimmt windows eine standard serial Treiber, beim Mega steht direkt Mega.. da.
Ob das nun ein anderer Treiber, oder bloß eine inf mit angepasstem Name ist, habe ich noch nicht überprüft.
Ich werde mal den standart serial Treiber beim Mega aufzwingen, mal schauen was da passiert.

jasch:
Hi deshalb wollte ich ja den Mega nutzen weil der Ram mit knapp wird.
Beim Uno nimmt windows eine standard serial Treiber, beim Mega steht direkt Mega.. da.
Ob das nun ein anderer Treiber, oder bloß eine inf mit angepasstem Name ist, habe ich noch nicht überprüft.
Ich werde mal den standart serial Treiber beim Mega aufzwingen, mal schauen was da passiert.

Das liest sicht so, als ob du mit Nachbauten, also keine Originalen Arduinos arbeitest.
Grundsätzlich kein Problem, allerdings braucht jeder seinen eigenen Treiber.
Zeige doch mal einen Link besser Hyperlink deiner Arduinos.
Oder ein Foto der Platinen bzw. welche USB-Serialwandler drauf sind.

Der Mega ist ein originaler (Arduino Mega 2560 Rev3), der Uno nicht (Eleg), das erklärt zumindest den Treiber.
Mit einem orig. Uno ist es aber ident. .
Es hat also irgendwas mit dem serialinit vom Mega zu tun (standard serial treiber aufzwingen brachte keinen Unterschied).

Ich habe jetzt aber eine Lösung gefunden, den Mega ohne Neustart neu zu init. .

Ambibox Software schliessen -> Ambibox neu starten(hier startet beim Uno der init) ->
in Ambibox "Leds" ausschalten -> ca 10s warten -> init erfolgt(LED flash) -> Leds in Ambibox aktivieren -> geht

Damit kann ich zwar gut Leben, aber mich würde halt inter. warum das so ist.

Den Mega habe ich deshalb genommen, weil ich am überlegen war, die Led Anzahl zu erhöhen.
(60/m -> 144/m)
mom habe ich 268, das wären dann über 600, und dann wäre der Uno def. am Ende.
Da ambibox aber mom "nur" 400 unterstützt habe ich das dann erstmal gelassen.

MfG Alex