Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 4 of 4

Thread: WS2812Serial question - conflict between FastLED and Adafruit NeoPixel libraries?

  1. #1
    Junior Member
    Join Date
    Dec 2019
    Posts
    3

    WS2812Serial question - conflict between FastLED and Adafruit NeoPixel libraries?

    For a small WS2812 based led project I'm using both FastLED and Adafruit NeoMatrix libraries (mainly for displaying text) and this was running perfectly on an Arduino Nano. However, I need to control it with an iOS app using bluetooth communication so I had to step away from the Nano/Bluno controllers as they are not capable of processing the BT communication together with these led libraries.
    So I moved to a Teensy 3.2 controller (3 UARTS) and WS2812Serial and first what I tried to do is get my led patterns working again. However, each of the libraries separately are working correctly (I've tested them successfully with the library examples), but as soon as I fire the FastLED.show() command, the subsequent patterns using NeoMatrix.show() don't work (the program doesn't crash, but the leds are just not being controlled). As soon as FastLED pattern comes along it works as usual. On the Nano/Bluno platform I had no problems with switching between these libraries.

    Here are some code snippets which show which libraries are included and how they are used:

    Code:
    #include <WS2812Serial.h>
    #define USE_WS2812SERIAL
    #include <FastLED.h>
    
    // Adafruit stuff
    #include <Adafruit_GFX.h>
    #include <Adafruit_NeoMatrix.h>
    #include <Adafruit_NeoPixel.h>
    #include <Fonts/Picopixel.h>
    
    #define DATA_PIN  5
    #define LED_TYPE  WS2812SERIAL
    #define COLOR_ORDER BRG
    #define NUM_LEDS  64
    
    ....
    
    // FastLED declarations
    // Declare array of leds including extra 'safety' pixel
    CRGB leds_plus_safety_pixel[NUM_LEDS + 1];
    CRGB* const leds(leds_plus_safety_pixel + 1);
    
    // Adafruit declarations
    Adafruit_NeoMatrix ledsNeo = Adafruit_NeoMatrix(WIDTH, HEIGHT, DATA_PIN,
      NEO_MATRIX_TOP + NEO_MATRIX_LEFT + NEO_MATRIX_ROWS + NEO_MATRIX_PROGRESSIVE,
      NEO_GRB + NEO_KHZ800);
    
    ....
    
    // Setup
    void setup() {
      delay(3000); // 3 second delay for recovery
      
      // FastLED LED strip initializer
      FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
      FastLED.setBrightness(128);
    
      // Adafruit LED strip initializer + text message stuff
      ledsNeo.begin();
      ledsNeo.setBrightness(128);
      ledsNeo.setRemapFunction(remapFn);
      ledsNeo.setFont(&Picopixel);
      ledsNeo.setTextWrap(false);
    
      // Serial communication with Serial Monitor
      Serial.begin(BAUDRATE);
      while (!Serial);  // Wait until Serial is ready
    
      Serial.print("Serial communication started at "); Serial.println(BAUDRATE);
      Serial.println(" ");
    }
    
    ....
    
    // Main loop
    void loop()
    {
      // Prepare patterns to display and set the corresponding library to use for the show() function -> bAdafruit
      .....
    
      if (bAdafruit) {
        // Adafruit GFX
        ledsNeo.show();
        delay(25);
        bAdafruit = false; // will be set by the pattern above
      } else { 
        // FastLED
        FastLED.show();
        // insert a delay to keep the framerate modest
        FastLED.delay(25);
      }
    }

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    21,323
    Simply including those other libs will not make Adafruit_NeoMatrix play nice. Adafruit designed their library to block interrupts.

    To make this work smoothly, you need to completely remove all use of Adafruit_NeoMatrix.

  3. #3
    Junior Member
    Join Date
    Dec 2019
    Posts
    3
    Hi Paul,
    Thanks for your prompt reply. Are you aware of any alternative matrix oriented library, especially for text processing?

  4. #4
    Junior Member
    Join Date
    Dec 2019
    Posts
    3
    I rhink I already have found a FastLED port of the GFX library here http://jorgen-vikinggod.github.io/LEDMatrix/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •