Go Down

Topic: Spectrum Shield - LED // Mid frequency problem (Read 264 times) previous topic - next topic

DerSteiN

Hello Forum,

I'm currently working on a project at my university and I'm new to the Arduino-World. We want to build a facade-prototype that reacts to sound frequencies.

I use the Arduino UNO and Sparkfun's FrequencySpectrum Shield.

To test the Spectrum Shield, I have build a basic LED setup from this spectrum-shield-hookup-guide.

Now my problem: The three midrange frequencie LED's are not turning OFF. When I try and turn off the music, the LED's remain ON. They blink slightly and dimm down when i turn off the music but ultimately they don't turn OFF. The low- and high- frequency LED's work propperly.

Is there something wrong with my code?
Is there something wrong with my setup?

Here is the code I use:
Code: [Select]

/********* Definieren der SpectrumShield connections zu UNO *********/
#define STROBE 4
#define RESET 5
#define DC_One A0
#define DC_Two A1

/********* Definieren der Arduino connections. Hier die Servo Ausgänge *********/
int LED[] = {7, 8, 9, 10, 11, 12, 13};

/********* Definieren der Spectrum Variablen *********/
int freq_amp;
int Frequencies_One[7];
int Frequencies_Two[7];
int i;

/********************Setup Loop*************************/
void setup() {
  //Set LED pin configurations
  for(i=0; i<7; i++)
  {
    pinMode(LED[i], OUTPUT);
    digitalWrite(LED[i], LOW);
  }

  //Set spectrum Shield pin configurations
  pinMode(STROBE, OUTPUT);
  pinMode(RESET, OUTPUT);
  pinMode(DC_One, INPUT);
  pinMode(DC_Two, INPUT); 
  digitalWrite(STROBE, HIGH);
  digitalWrite(RESET, HIGH);

  //Initialize Spectrum Analyzers
  digitalWrite(STROBE, LOW);
  delay(1);
  digitalWrite(RESET, HIGH);
  delay(1);
  digitalWrite(STROBE, HIGH);
  delay(1);
  digitalWrite(STROBE, LOW);
  delay(1);
  digitalWrite(RESET, LOW);
}

/****************Main Function Loop***************************/
void loop() {

  Read_Frequencies();
  Graph_Frequencies();
  delay(50);

}

/*************Pull frquencies from Spectrum Shield****************/
void Read_Frequencies(){
  //Read frequencies for each band
  for (freq_amp = 0; freq_amp<7; freq_amp++)
  {
    Frequencies_One[freq_amp] = analogRead(DC_One);
    Frequencies_Two[freq_amp] = analogRead(DC_Two);
    digitalWrite(STROBE, HIGH);
    digitalWrite(STROBE, LOW);
  }
}

/***************Light LEDs based on frequencies******************/
void Graph_Frequencies(){
   for( i= 0; i<7; i++)
   {
     if(Frequencies_Two[i] > Frequencies_One[i]){
        analogWrite(LED[i], Frequencies_Two[i]/4);
     }
     else{
        analogWrite(LED[i], Frequencies_One[i]/4);
     }
   }
}


The final plan is to break the 7 frequencies into 3 frequencies that each run a servo.


Please help me out on this. I just started and directly have my first problem  :smiley-eek: :D


Attached is a photo of my setup. (I havent soldered anything yet, so please ignore the cables i used to connect the shield with the Arduino xD)

Grumpy_Mike

#1
Jan 20, 2019, 01:13 am Last Edit: Jan 20, 2019, 01:16 am by Grumpy_Mike
Quote
Is there something wrong with my code?
Yes looks like it.

The analogue write only works on pins 3, 5, 6, 9, 10, and 11, and you are using pins 7, 8, 9, 10, 11, 12, 13

Fix that and you will find the same behaviour on all pins. This is due to noise on the signal from the chip. There is nothing you can do about this so you have to set a threshold in software by subtracting a number from both channels say 200.

DerSteiN

Quote
The analogue write only works on pins 3, 5, 6, 9, 10, and 11
Since the pin 5 is used by the SpectrumShield does that mean that I can only connect 5 LED's?


Thanks for the fast reply!

DerSteiN

I got it working with a threshold. The lights go OFF now. They also react on the music I play, but they don't show the frequency spectrum they should (I tested it with this audio spectrum).

Since I can only use 5 LED's, I changed the integer range accordingly - it might be wrong though, since it doesn't work properly.

Any suggestions what I do wrong or what I can try to get the correct frequencies?

Code: [Select]
/********* Definieren der SpectrumShield connections zu UNO *********/
#define STROBE 4
#define RESET 5
#define DC_One A0
#define DC_Two A1

/********* Definieren der Arduino connections. Hier die Servo Ausgänge *********/
int LED[] = {3, 6, 9, 10, 11};

/********* Definieren der Spectrum Variablen *********/
int freq_amp;
int Frequencies_One[5];
int Frequencies_Two[5];
int i;

/********************Setup Loop*************************/
void setup() {
  //Set LED pin configurations
  for(i=0; i<5; i++)
  {
    pinMode(LED[i], OUTPUT);
    digitalWrite(LED[i], LOW);
  }

  //Set spectrum Shield pin configurations
  pinMode(STROBE, OUTPUT);
  pinMode(RESET, OUTPUT);
  pinMode(DC_One, INPUT);
  pinMode(DC_Two, INPUT); 
  digitalWrite(STROBE, HIGH);
  digitalWrite(RESET, HIGH);

  //Initialize Spectrum Analyzers
  digitalWrite(STROBE, LOW);
  delay(1);
  digitalWrite(RESET, HIGH);
  delay(1);
  digitalWrite(STROBE, HIGH);
  delay(1);
  digitalWrite(STROBE, LOW);
  delay(1);
  digitalWrite(RESET, LOW);
}

/****************Main Function Loop***************************/
void loop() {

  Read_Frequencies();
  Graph_Frequencies();
  delay(40);

}

/*************Pull frquencies from Spectrum Shield****************/
void Read_Frequencies(){
  //Read frequencies for each band
  for (freq_amp = 0; freq_amp<5; freq_amp++)
  {
    Frequencies_One[freq_amp] = analogRead(DC_One);
    Frequencies_Two[freq_amp] = analogRead(DC_Two);

        if (Frequencies_One[freq_amp] < 120) Frequencies_One[freq_amp] = 0;
        if (Frequencies_Two[freq_amp] < 120) Frequencies_Two[freq_amp] = 0;
   
    digitalWrite(STROBE, HIGH);
    digitalWrite(STROBE, LOW);
  }
}

/***************Light LEDs based on frequencies******************/
void Graph_Frequencies(){
   for( i= 0; i<5; i++)
   {
     if(Frequencies_Two[i] > Frequencies_One[i]){
        analogWrite(LED[i], Frequencies_Two[i]/4);
     }
     else{
        analogWrite(LED[i], Frequencies_One[i]/4);
     }

     Serial.println("two");
     Serial.println(Frequencies_Two[i]);
     Serial.println(Frequencies_One[i]);
   }
}

Grumpy_Mike

#4
Jan 20, 2019, 10:52 am Last Edit: Jan 20, 2019, 10:54 am by Grumpy_Mike
What is wrong is that each time you read the chip you only read five values. So the first time the code is run you read values zero to four. The next time you read the chip you read values 5, 6, 0, 1, 2. The next time you read values 3, 4, 5, 6, 0 and so on.

You should read all seven values from the chip and then on the graphic display function select the values you want to put to the LEDs.

Go Up