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

Thread: Flicker in rainbow with audiolib and analog input

  1. #1
    Junior Member
    Join Date
    Feb 2017
    Posts
    4

    Flicker in rainbow with audiolib and analog input

    Hi all,

    I'm using a octows2811 to drive 50 leds in a single strip as a test for audio visualization. When I use the teensyduino rainbow example to test my setup I get a perfectly smooth running rainbow effect. When I add the code for the audio connections the led strip starts to flicker. From the code on github I deduce that both are doing dma transfers and whatnot. This is unfortunately above my skill. The analog input is connected to pins 17/18 -A3/A4 for stereo input using the suggested input schematic seen in the designer for the audio libray. I'm guessing the reading of the analog input is interfering with the output to the leds somehow...

    Is there any way to adjust the code below (simplest listing that shows the flickering derived from a sample) to prevent the led strip from flickering?

    Code:
    #include <Arduino.h>
    
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    
    #include <OctoWS2811.h>
    
    
    // GUItool: begin automatically generated code
    AudioInputAnalogStereo   adcsInput(A3, A4);          //xy=190,287
    
    // GUItool: end automatically generated code
    
    #include <OctoWS2811.h>
    
    const int ledsPerStrip = 50;
    
    DMAMEM int displayMemory[ledsPerStrip*6];
    int drawingMemory[ledsPerStrip*6];
    
    const int config = WS2811_GRB | WS2811_800kHz;
    
    OctoWS2811 leds(ledsPerStrip, displayMemory, drawingMemory, config);
    
    int rainbowColors[180];
    
    
    void setup() {
      pinMode(1, OUTPUT);
      digitalWrite(1, HIGH);
      for (int i=0; i<180; i++) {
        int hue = i * 2;
        int saturation = 100;
        int lightness = 50;
        // pre-compute the 180 rainbow colors
        rainbowColors[i] = makeColor(hue, saturation, lightness);
      }
      digitalWrite(1, LOW);
      leds.begin();
    }
    
    
    void loop() {
      rainbow(10, 2500);
    }
    
    
    // phaseShift is the shift between each row.  phaseShift=0
    // causes all rows to show the same colors moving together.
    // phaseShift=180 causes each row to be the opposite colors
    // as the previous.
    //
    // cycleTime is the number of milliseconds to shift through
    // the entire 360 degrees of the color wheel:
    // Red -> Orange -> Yellow -> Green -> Blue -> Violet -> Red
    //
    void rainbow(int phaseShift, int cycleTime)
    {
      int color, x, y, offset, wait;
    
      wait = cycleTime * 1000 / ledsPerStrip;
      for (color=0; color < 180; color++) {
        digitalWrite(1, HIGH);
        for (x=0; x < ledsPerStrip; x++) {
          for (y=0; y < 8; y++) {
            int index = (color + x + y*phaseShift/2) % 180;
            leds.setPixel(x + y*ledsPerStrip, rainbowColors[index]);
          }
        }
        leds.show();
        digitalWrite(1, LOW);
        delayMicroseconds(wait);
      }
    }

  2. #2
    Haven't looked through the code in-depth yet, but have you tried to power the LEDs externally just to eliminate that as a problem. And maybe run the same code that is problematic without any audio lines connected to the teensy.

  3. #3
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    14,874
    Try this:

    Code:
    void rainbow(int phaseShift, int cycleTime)
    {
      int color, x, y, offset, wait;
    
      wait = cycleTime * 1000 / ledsPerStrip;
      for (color=0; color < 180; color++) {
        elapsedMicros usec=0;
        digitalWrite(1, HIGH);
        for (x=0; x < ledsPerStrip; x++) {
          for (y=0; y < 8; y++) {
            int index = (color + x + y*phaseShift/2) % 180;
            leds.setPixel(x + y*ledsPerStrip, rainbowColors[index]);
          }
        }
        leds.show();
        digitalWrite(1, LOW);
        while (usec <= wait) { /* wait */ }
      }
    }
    Please let me know if this resolves the problem? If so, I'll update the OctoWS2811 example. (if not, I look into this issue, but let's try this quick guess first....)

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    14,874
    Or maybe try it like this:

    Code:
    void rainbow(int phaseShift, int cycleTime)
    {
      int color, x, y, offset, wait;
    
      wait = cycleTime * 1000 / ledsPerStrip;
      elapsedMicros usec=0;
      for (color=0; color < 180; color++) {
        digitalWrite(1, HIGH);
        for (x=0; x < ledsPerStrip; x++) {
          for (y=0; y < 8; y++) {
            int index = (color + x + y*phaseShift/2) % 180;
            leds.setPixel(x + y*ledsPerStrip, rainbowColors[index]);
          }
        }
        leds.show();
        digitalWrite(1, LOW);
        while (usec <= wait) { /* wait */ }
        usec -= wait;
      }
    }

  5. #5
    Junior Member
    Join Date
    Feb 2017
    Posts
    4
    Hi thanks for the replies

    @jondavid, I already had an external power supply connected. But tried both with and without. Only difference I can make out is that the leds are much lower brightness without the external brick making flicker more noticeable. Although removing the audio lines should make little difference, because the problem can be triggered by turning a line of code on and off, I did try and saw no difference.

    @PaulStoffregen, I tried both you examples and they make no difference to my problem. I sort-of expected that because my original code does use a similar setup to eliminate the delay call. I never brought that over to the example as I wanted it as clean a demo as I could get. Simply comment out the AudioInputAnalogStereo line and bye bye problem (and any chance at effects ).

    I made a short video to demonstrate. First with audioinput line commented out and then with it on in second half of video. I think the difference is clear enough to see.
    small video demo

    I also tried with the fastled library (not using any octows2811 options). It shows the same problem.

    Hope this is fixable.

    For what is it worth I do think you should update the examples with your example code as it nicely shows animation without delay statements.
    Last edited by bzuidgeest; 03-20-2017 at 07:43 PM.

  6. #6
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    14,874
    I can't view the video with Firefox on Linux. Not surprising from Microsoft Onedrive. Maybe upload as an unlisted video on Youtube?

  7. #7
    Junior Member
    Join Date
    Feb 2017
    Posts
    4
    Actually that is surprising. I checked and the video (and one drive) work perfectly fine on my Linux mint (kde) installation. But that is not important right now. I have uploaded it to you-tube as suggested. Don't expect anything fancy

    video

Posting Permissions

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