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

Thread: WS2812B LED Strip Blinks When Using Audio Adapter

  1. #1
    Junior Member
    Join Date
    Aug 2016
    Posts
    15

    WS2812B LED Strip Blinks When Using Audio Adapter

    Getting my Teensy 3.2 working with my WS2812b strip has been troubling me. I have the LED data signal going through a SN74HCT245N chip which is wired as shown in the picture from Pabloantxon on this page. I also have the ground pin on the Teensy connected to the ground on the LED strip. The Teensy is getting power through the USB.

    This is where I think the problem is, but I don't know why. The code in loop() just creates a rainbow. When I comment out the code automatically generated by the GUI tool and the audio code in setup(), the rainbow shows perfectly. When it is not commented out (as shown below), the first 40-50 LEDs in the strip are white with a very quick flickering.


    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include "FastLED.h"
    #include "math.h"
    #include <SerialFlash.h>
    #include <SD.h>
    #define NUM_LEDS 300
    #define DATA_PIN 3
    CRGB leds[NUM_LEDS];

    // GUItool: begin automatically generated code
    AudioInputI2S i2s1; //xy=219.1999969482422,183
    AudioMixer4 mixer1; //xy=403.1999969482422,203.1999969482422
    AudioAnalyzeFFT1024 fft1024; //xy=547.1999969482422,239
    AudioConnection patchCord1(i2s1, 0, mixer1, 0);
    AudioConnection patchCord2(i2s1, 1, mixer1, 1);
    AudioConnection patchCord3(mixer1, fft1024);
    AudioControlSGTL5000 audioShield; //xy=446.1999969482422,317
    // GUItool: end automatically generated code

    // TOUCHSCREEN PINS
    #define CS_PIN 8
    #define TIRQ_PIN 2
    XPT2046_Touchscreen ts(CS_PIN, TIRQ_PIN); // Param 2 - Touch IRQ Pin - interrupt enabled polling
    #define TFT_CS 21
    #define TFT_DC 20
    #define TFT_RST 255 // 255 = unused, connect to 3.3V
    #define TFT_MOSI 7
    #define TFT_SCLK 14
    #define TFT_MISO 12
    ILI9341_t3 tft = ILI9341_t3(TFT_CS, TFT_DC, TFT_RST, TFT_MOSI, TFT_SCLK, TFT_MISO);

    //const int myInput = AUDIO_INPUT_LINEIN;
    const int myInput = AUDIO_INPUT_MIC;

    void setup() {
    // AUDIO STUFF
    AudioMemory(12);
    audioShield.enable();
    audioShield.inputSelect(myInput);

    // configure the mixer to equally add left & right
    mixer1.gain(0, 0.5);
    mixer1.gain(1, 0.5);

    Serial.begin(9600);
    FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
    LEDS.setBrightness(90);
    LEDS.clear();
    }

    void loop() {
    LEDS.clear();
    fill_rainbow(leds, NUM_LEDS, 0, 5);
    FastLED.show();
    }

  2. #2
    Junior Member
    Join Date
    Aug 2016
    Posts
    15
    Hey guys, I'm still stuck on this. I've narrowed the problem down to these 3 lines:

    AudioConnection patchCord1(i2s1, 0, mixer1, 0);
    AudioConnection patchCord2(i2s1, 1, mixer1, 1);
    AudioConnection patchCord3(mixer1, fft1024);

    When they are commented out, the lights show perfectly. When just 1 of lines is not commented out, the first 50 something lights flicker a bright white. Below is a more cleaned up version of the code. What's frustrating me is that I have both the LED strip and the audio adapter working perfectly when they are separate. Once I try to use them both in the same program, it doesn't work.

    I don't know what else to add but if there is any more information you need from me, please don't hesitate to ask and I'll do my best to give it to you. Any help is much appreciated!

    #include "FastLED.h"
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include "math.h"
    #include <SerialFlash.h>
    #include <SD.h>
    #define NUM_LEDS 300
    #define DATA_PIN 7
    CRGB leds[NUM_LEDS];

    // GUItool: begin automatically generated code
    AudioInputI2S i2s1; //xy=219.1999969482422,183
    AudioMixer4 mixer1; //xy=403.1999969482422,203.1999969482422
    AudioAnalyzeFFT1024 fft1024; //xy=547.1999969482422,239
    //AudioConnection patchCord1(i2s1, 0, mixer1, 0);
    //AudioConnection patchCord2(i2s1, 1, mixer1, 1);
    //AudioConnection patchCord3(mixer1, fft1024);
    AudioControlSGTL5000 audioShield; //xy=446.1999969482422,317
    // GUItool: end automatically generated code

    const int myInput = AUDIO_INPUT_LINEIN;

    void setup() {
    // AUDIO STUFF
    AudioMemory(12);
    audioShield.enable();
    audioShield.inputSelect(myInput);

    // configure the mixer to equally add left & right
    mixer1.gain(0, 0.5);
    mixer1.gain(1, 0.5);

    Serial.begin(9600);
    FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
    LEDS.setBrightness(90);
    LEDS.clear();
    }
    void loop() {
    LEDS.clear();
    for ( int i = 0; i < 299; i++) leds[i] = CHSV(i,255,255); // Displays a rainbow
    FastLED.show();
    }
    Wiring info:

    The audio adapter isn't stacked on the Teensy, but I have these wires connected (through a breadboard) since I only need Line In, Mic, and FFT working: 3.3V, LRCLK, SDA, SCL, RX, MCLK, BCLK, GND.

    This is my wiring of an SN74HCT245N chip except I do not have a capacitor across the 5V and GN pins.
    Click image for larger version. 

Name:	SN74HCT245N.jpg 
Views:	126 
Size:	99.8 KB 
ID:	8094

    To reiterate, my LED strip works perfectly without audio being used. And my audio processing through the Line In and Mic both work perfectly without the LED strip being used.
    Last edited by Haybur; 09-08-2016 at 07:45 PM.

  3. #3
    I believe Audio library uses interrupts. And according to Adafruit NeoPixel Überguide

    The control signal has very strict timing requirements

    Usually this means it is not very compatible with interrupts.

    Maybe you could try:
    Code:
    AudioNoInterrupts(); // interrupts off
    
    // Your led stuff here
    
    AudioInterrupts();
    I have no idea if this works, and I don't have any smart led hardware for testing.

  4. #4
    Junior Member
    Join Date
    Aug 2016
    Posts
    15
    Thanks for the reply Pazi. I finally got around to testing that out and it does change what happens but it isn't necessarily fix. The LEDs that would blink a bright white are now blinking in a color that is close to what they are supposed to be in the rainbow. There is also a group blinking further down the strip when that didn't happen before. I'm continuing to look for a solution and I think I'll have to go into the code of what the audioConnection lines actually do since I'm all out of other ideas.

Posting Permissions

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