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

Thread: Line-in noise when using an LED library

  1. #1
    Junior Member
    Join Date
    Aug 2018
    Posts
    4

    Line-in noise when using an LED library

    Hi there! Completely new to hardware projects, but I've had a friend direct me this way.

    The project I'm working on is fairly simple. Our burning man camp has a camp theme song that we play.... over... and over... and over again. So my idea was to make a button that anyone could walk up to and hit, and the song would play through our stereo. It needs a line-in for whatever current music is playing, the audio file stored on the device, a big button, and an output. I set up a Teensy 3.2 with an audio shield, put our song on an SD card and got to work.

    My buddy helped me solder everything together, complete with a line-in and an extra WS2812 LED set thing he had lying around. It's been fun putting all of the code together and making it work.

    Now when putting it all together, the issue I'm having is that as soon as I turn on even one LED, I get a ton of high pitched noise coming through the line-in. It doesn't happen if I stop the audio passthrough, and doesn't happen if I turn the LED off.

    Here's my very basic sample code trying to pinpoint the issue.

    Code:
    /*
     * A simple hardware test which receives audio from the audio shield
     * Line-In pins and send it to the Line-Out pins and headphone jack.
     *
     * This example code is in the public domain.
     */
    
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    #include <Adafruit_NeoPixel.h>
    
    // GUItool: begin automatically generated code
    AudioInputI2S            i2s1;           //xy=200,69
    AudioOutputI2S           i2s2;           //xy=365,94
    AudioConnection          patchCord1(i2s1, 0, i2s2, 0);
    AudioConnection          patchCord2(i2s1, 1, i2s2, 1);
    AudioControlSGTL5000     sgtl5000_1;     //xy=302,184
    // GUItool: end automatically generated code
    
    
    const int myInput = AUDIO_INPUT_LINEIN;
    //const int myInput = AUDIO_INPUT_MIC;
    
    #define LED_PIN 3
    
    Adafruit_NeoPixel strip = Adafruit_NeoPixel(9, LED_PIN);
    
    void setup() {
      strip.begin();
      strip.show(); // init all pixels to off
      
      // Audio connections require memory to work.  For more
      // detailed information, see the MemoryAndCpuUsage example
      AudioMemory(12);
    
      // Enable the audio shield, select input, and enable output
      sgtl5000_1.enable();
      sgtl5000_1.inputSelect(myInput);
      sgtl5000_1.volume(.75);
      sgtl5000_1.adcHighPassFilterFreeze();
      // sgtl5000_1.lineInLevel(2);
    
      strip.setPixelColor(0, 240, 0, 240);
      strip.show();
    }
    
    elapsedMillis volmsec=0;
    
    void loop() {
      // every 50 ms, adjust the volume
      if (volmsec > 50) {
        float vol = analogRead(15);
        vol = vol / 1023.0;
        //audioShield.volume(vol); // <-- uncomment if you have the optional
        volmsec = 0;               //     volume pot on your audio shield
      }
    
      
    }

    I've tried both NeoPixel and FastLED, and both give me the same issue.

    I was hoping for it to passthrough audio, while my big red button slowly breathes with the leds inside of it, tempting someone to come smash it. My friend told me never to output audio while LEDs are going, but that can't be right, can it?

    Thanks for any help!
    (Quick edit: Should I have posted this in technical support? Don't want to double post so I'll leave it here for now.)

  2. #2
    Junior Member
    Join Date
    Aug 2018
    Posts
    4
    I moved my LED pin to pin 5 to give the WS2812Serial library a shot, and I still get the same crazy line-in noise. https://github.com/PaulStoffregen/WS2812Serial

    For now I'm just going to move my LED logic / control to a second microcontroller. Any advice that someone has about whether or not this line-in noise is normal when powering an LED, please let me know. Thanks!

  3. #3
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    18,497
    These sorts of problems are usually "ground loop" related. Usually this is the simplest solution.

    https://www.pjrc.com/store/audio_ground_isolator.html

    Powering the audio source from a battery, with no wired connections other than the audio signal, is another way to test.

  4. #4
    Junior Member
    Join Date
    Aug 2018
    Posts
    4
    Thanks, Paul! Running it off a USB battery instead of my computer's USB seems to work. Really thought it'd be a long shot. Also bought an audio ground isolator to check out.

    Thanks again!

  5. #5
    Junior Member
    Join Date
    Aug 2018
    Posts
    4
    Quick update to this. The audio ground isolator didn't do much of anything when the setup is connected to the computer. But everything works great off of battery power. Thanks again!

Posting Permissions

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