SparkFun Forums 

Where electronics enthusiasts find answers.

Questions &/or issues related to products in the Audio category should be posted in this forum.
#205981
Hello,

i'm new to the sparkfun-community and i just started to work with arduino some months ago. I've already made some small projects with a stepper motor and another project with a SD-Card-mp3 player for arduino. For my next project i would like to work with audio reactive stepper motor control. To do that, i already bought the SPARKFUN SPECTRUM SHIELD , an Arduino Uno and a hand full of the wellknown 28BYJ-48 Stepper Motors (5V) and the matching ULN2003APG shields.

In the description of the SPARKFUN SPECTRUM Shield it is mentioned that it can also be used to control motors (audio reactive). Unfortunately I couldn't find a code or a manual for it yet. Is there any tutorial to set up the SPECTRUM SHIELD for that kind of motor controlling?
The SPARKFUN SPECTRUM Shield divides an audio signal into 7 frequency ranges (bands). I would like to drive 7 stepper motors in combination with the Shield. Each of these motors should move in one direction with constant speed as soon as the respective frequency range reaches a certain sound level.

Does anyone know the SPECTRUM SHIELD and can help me? Or has someone already carried out a similar project and can give me some advices? Maybe an Arduino UNO is not enough powered... and I should rather use a bigger microcontroller? I am grateful for any advice. I'm looking for hints on the coding and the wiring.

I attached a rough scheme of my planned project.
Image

Would love to get some help from the community!
You do not have the required permissions to view the files attached to this post.
#205984
The Uno doesn't directly have enough I/O pins to drive the 7 steppers, since the ULN2003APG boards take 4 pins each. Possibly a Mega or use some shift registers like a 74HC595 to get additional I/O pins. As for the code, I'd start with SparkFun_PWM_Demo.ino and change Graph_Frequencies() to compare the spectrum values, and if over the threshold, run the motor.

/mike
#206038
thanks for your fast respond. i will at first try it with one motor (28BYJ-48) and shield for just one frequency. But the idea with the 74HC595 sounds good. I will have a look on that too!
Also i thought to use a programmable stepper-motor-shield (like: Grove - I2C Motor Driver, or something like that ) - so the ports of the Spectrum shield and the Arduino will do just fine and all the main information of the stepper comes from the shield. The SPECTRUM SHIELD just gives the Stepper Shield the information to start or to stop.

Another question: why are there 2 MSGEQ7 build in on the Spectrum Shield? In the manual it is written, that this is used for stereo-audio. But that would mean, that i acutally have two times 7 ports going out (14 pins). But thats actually not the case? Can i push the SPECTRUM SHIELD somehow to give me 14 frequencie-ports out?
#206066
Each MSGEQ7 would give the output signals for the same 7 frequency bands, so unless you have two different audio sources or a stereo signal, you would get roughly the same data out of each of them. You may be able to take one and shift the clock frequency (by changing the R or C on the CKIN pin) as the filters appear to track the clock. According to https://forum.arduino.cc/index.php?topic=394167.0 this should work.
/mike
#206214
I've made some progress with my project.
Image

I wrote my first small code! :D
With this code i can light up LED's to the 7 Frequency-Bands, when the volume level of each freq-band reaches a specific value.
Find a small video here:
https://www.youtube.com/watch?v=al5oVSO ... e=youtu.be

here is the small code: (mostly i changed the last few lines of code from the original demo)
Code: Select all
Sketch by Alex Rex, 24.07.2019
based on:
SparkFun Spectrum Shield PWM Demo
Toni Klopfenstein @ SparkFun Electronics
February 2015
https://github.com/sparkfun/Spectrum_Shield

*********************************************************************************/

//Declare Spectrum Shield pin connections
#define STROBE 4        /* #define constantName value */
#define RESET 5         /* #define constantName value */
#define DC_One A0       /* Analog Pin A0 with the name DC_one */
#define DC_Two A1       /* Analog Pin A1 with the name DC_Two */


//Define LED connections on the shield
int LED[] = {3, 6, 7, 9, 10, 11, 12}; /* for the seven LED's  */

//Define spectrum variables
int freq_amp;           /* variable for the 7 Frequency-Bands of the MSGEQ7 */
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); /* Input from MSGEQ7 to arduino */
  pinMode(DC_Two, INPUT); /* Input from MSGEQ7 to arduino */
  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(25);                
 
}


/*******************Pull frequencies from Spectrum Shield********************/
void Read_Frequencies(){  /* Read volume value 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 Output Value*************/
void Graph_Frequencies(){
   for( i= 0; i<7; i++)
   {
     if(Frequencies_One[i] >= 220) /* ~110 for piano songs, 175 - 340 for pop-songs (songs with a beat)*/
     {
        digitalWrite(LED[i], HIGH);
      
     }
     else{
        digitalWrite(LED[i], LOW);
     }
   }
}

What's next for my project?:
Now I would like 7 stepper motors to be switched on/off instead of the 7 LEDs. I think it would be best if the >digitalOut< of the Spectrum-shield go to a programmable Stepper-Shield and start / interrupt a loop program there.

Can someone give me a hint which stepper shields can do this? Does anyone have a hint for the right code for the Spectrum Analyzer Shield to do something like this?

The exact movement of the motors has not yet been determined. I would just say: turn clockwise at constant speed. Maybe I would extend the movement of the motor later: e.g. gently starting and gently stopping of the motor ... or something similar. But i will come to this later on ..

I would be very happy about an answer / thoughts / hints.
You do not have the required permissions to view the files attached to this post.
#206252
Huray! Today I managed to make a stepper motor move, when a specific audio frequency in a audiosignal reaches a specific level. //

See a video here: https://www.youtube.com/watch?v=u0zMcRt ... e=youtu.be

I added a stepper motor code into my previous code. I declared two Variables BAND and LEVEL.
With BAND i will tell the stepper shield, which frequency band to read.
With LEVEL i tell the stepper shield, what level in that specific frequency band must be reached, until the loop starts.
If the LEVEL reaches a value under LEVEL, then the stepper will stop.

Find the new code here:
Code: Select all
/****************************************************************************** 
Sketch by Alex Rex
based on:
SparkFun Spectrum Shield PWM Demo
Toni Klopfenstein @ SparkFun Electronics
February 2015
https://github.com/sparkfun/Spectrum_Shield

*********************************************************************************/

//Declare Spectrum Shield pin connections
#define STROBE 4        /* #define constantName value */
#define RESET 5         /* #define constantName value */
#define DC_One A0       /* Analog Pin A0 with the name DC_one */
#define DC_Two A1       /* Analog Pin A1 with the name DC_Two */


//Define LED connections on the shield
int LED[] = {3, 6, 7, 9, 10, 11, 12}; /* for the seven LED's  */

//Define spectrum variables
int freq_amp;           /* variable for the 7 Frequency-Bands of the MSGEQ7 */
int Frequencies_One[7]; 
int Frequencies_Two[7]; 
int i;         

int level = 125;  /*minimum level of sound to trigger LED or STEPPER*/
                  /* ~110 for piano songs, 175 - 340 for pop-songs (songs with a beat)*/
int band = 3;     /*7 frequency bands, choose: 0,1,2,3,4,5,6*/  
                  /*0 = ~63Hz , 1 = ~160Hz , 2 = ~400Hz , 3 = ~1000Hz , 4 = ~2500Hz , 5 = 6250Hz , 6 = 16000Hz */  

//Stepper Motor Shield pin connections
#define STEPPER_PIN_1 0 /*IN1*/
#define STEPPER_PIN_2 1 /*IN2*/
#define STEPPER_PIN_3 2 /*IN3*/
#define STEPPER_PIN_4 8 /*IN4*/
int step_number = 0;

/********************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); /* Input from MSGEQ7 to arduino */
  pinMode(DC_Two, INPUT); /* Input from MSGEQ7 to arduino */
  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);

  //Set Stepper Shield pin configurations
  pinMode(STEPPER_PIN_1, OUTPUT);
  pinMode(STEPPER_PIN_2, OUTPUT);
  pinMode(STEPPER_PIN_3, OUTPUT);
  pinMode(STEPPER_PIN_4, OUTPUT);
}


/**************************Main Function Loop*****************************/
void loop() {
  
  Read_Frequencies();       
  Graph_Frequencies();      
  delay(25);
  
  OneStep(false);
  delay(2);                
 
}


/*******************Pull frequencies from Spectrum Shield********************/
void Read_Frequencies(){  /* Read volume value 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 Output Value*************/
void Graph_Frequencies(){
   for( i= 0; i<7; i++)
   {
     if(Frequencies_One[i] >= level)
     {
        digitalWrite(LED[i], HIGH);
      
     }
     else{
        digitalWrite(LED[i], LOW);
     }
   }
}

/**************Stepper Motor Moving to Level Value of one Band from EQ*************/
void OneStep(bool dir){
    if(Frequencies_One[band] >= level){
switch(step_number){
  case 0:
  digitalWrite(STEPPER_PIN_1, HIGH);
  digitalWrite(STEPPER_PIN_2, LOW);
  digitalWrite(STEPPER_PIN_3, LOW);
  digitalWrite(STEPPER_PIN_4, LOW);
  break;
  case 1:
  digitalWrite(STEPPER_PIN_1, LOW);
  digitalWrite(STEPPER_PIN_2, HIGH);
  digitalWrite(STEPPER_PIN_3, LOW);
  digitalWrite(STEPPER_PIN_4, LOW);
  break;
  case 2:
  digitalWrite(STEPPER_PIN_1, LOW);
  digitalWrite(STEPPER_PIN_2, LOW);
  digitalWrite(STEPPER_PIN_3, HIGH);
  digitalWrite(STEPPER_PIN_4, LOW);
  break;
  case 3:
  digitalWrite(STEPPER_PIN_1, LOW);
  digitalWrite(STEPPER_PIN_2, LOW);
  digitalWrite(STEPPER_PIN_3, LOW);
  digitalWrite(STEPPER_PIN_4, HIGH);
  break;
} 
  }else{
    switch(step_number){
  case 0:
  digitalWrite(STEPPER_PIN_1, LOW);
  digitalWrite(STEPPER_PIN_2, LOW);
  digitalWrite(STEPPER_PIN_3, LOW);
  digitalWrite(STEPPER_PIN_4, LOW);   /*HIGH*/
  break;
  case 1:
  digitalWrite(STEPPER_PIN_1, LOW);
  digitalWrite(STEPPER_PIN_2, LOW);
  digitalWrite(STEPPER_PIN_3, LOW);  /*HIGH*/
  digitalWrite(STEPPER_PIN_4, LOW);
  break;
  case 2:
  digitalWrite(STEPPER_PIN_1, LOW);
  digitalWrite(STEPPER_PIN_2, LOW);  /*HIGH*/
  digitalWrite(STEPPER_PIN_3, LOW);
  digitalWrite(STEPPER_PIN_4, LOW);
  break;
  case 3:
  digitalWrite(STEPPER_PIN_1, LOW);  /*HIGH*/
  digitalWrite(STEPPER_PIN_2, LOW);
  digitalWrite(STEPPER_PIN_3, LOW);
  digitalWrite(STEPPER_PIN_4, LOW);


} 
  }
step_number++;
  if(step_number > 3){
    step_number = 0;
  }
}
LED-STEPPER-Sound-reactive-alex-rex.jpg
Thats pretty cool!
But now i wanna use one stepper motor for each frequency band (7 Bands = 7 Motors).
I thougt about to use some I²C - Motor Shields. Someone can recomand anything, that will work?
The LED's will disappear in the final project - i just let them connected for now, to see the different frequency bands appear.

WHY ALL THAT?
In the End of the project i would like to visualize Audio in material form. (Not as LED's, Beamer or Displays!)
The Motors (Rotors, or Actuators) should move some structure (or similar objects), that will interpret the Audio into moving material. I'm still in the beginning with that project. As for now.
You do not have the required permissions to view the files attached to this post.
#207082
This looks awesome mate, well done! I have an idea for a haptic feedback headband that takes audio inputs from a 7.1 surround system to drive the haptic motors on the same channels. So you could wear the headband and feel the direction of the sound as well as hear it. Do you think your system could be modified to achieve this? I have never done anything like this, I found this board after doing a bit of google searching on how it might be possible!