1

I’m trying to make an art sculpture, with an Arduino-uno, a servomotor and a seeduino musicshield v2.0. I’m making the servo motor moving a stick with the attached fans of the servo, and I want to synchronize the servo motor with the music shield and when the motor is stopped(about one minute), the music(about one minute of music) will play and when de motor is moving the music will be stopped.

I'm super noobie with the code. I tried something like this but, is not moving at all, neither my servo or my musicshield when I write this:

#include <SD.h>
#include <SPI.h>
#include <arduino.h>
#include <MusicPlayer.h>

#include <Servo.h>
Servo myservo;

int val;//for the servo

void setup() {
  //setup for the music shield
  Serial.begin(9600);
  player.begin();  //will initialize the hardware and set default mode to be normal.
  player.addToPlaylist("a.mp3");
  //setup for the servo
   myservo.attach( 9 );
}
void loop() {
  mover();
  if ( val == 90) {
    music();
  }
}

void mover () {
  val = 0;// start point
  myservo.write(val);
  delay(800); 

  val = 90;
  myservo.write(val);
  delay(60000);//wait for 1 min
}

void music () {

  player.play();  
}

when I write this my servo moves, but obviously my music wouldn't play

#include <SD.h>
#include <SPI.h>
#include <arduino.h>
#include <MusicPlayer.h>

#include <Servo.h>
Servo myservo;

int val;//for the servo




void setup() {
  //setup for the music shield
 Serial.begin(9600);
  player.begin();  //will initialize the hardware and set default mode to be normal.
  player.addToPlaylist("a.mp3");
  //setup for the servo
   myservo.attach( 9 );
 }

void loop() {
mover();

 }

 void mover () {
val = 0;// start point
myservo.write(val);
delay(800); 

val = 90;//
myservo.write(val);
delay(60000);//wait for 1 min
}

void music () {

  player.play();  //do some leisurely job
} 

And the music will play when I write this, obviously the servomotor don't move, so I'm think I have a problem mixing my servomotor and the musicshield(seeeduino music shield v2.0, and I want the music start when my servo motor is in this point of val=90 delay(60000)

 #include <SD.h>
    #include <SPI.h>
    #include <arduino.h>
    #include <MusicPlayer.h>

    #include <Servo.h>
    Servo myservo;

    int val;//for the servo




    void setup() {
      //setup for the music shield
     Serial.begin(9600);
      player.begin();  //will initialize the hardware and set default mode to be normal.
      player.addToPlaylist("a.mp3");
      //setup for the servo
       myservo.attach( 9 );
      }

    void loop() {

   player.play();  
     }

    void mover () {
    val = 0;// start point
    myservo.write(val);
    delay(800); 

    val = 90;//
    myservo.write(val);
    delay(60000);//wait for 1 min
    }
  • with is not working I mean is not moving at all, neither my servo or the music, but when I compile I don't have any mistakes messages – Egm May 22 '17 at 14:20
  • 1
    Break the problem down into pieces. First get the servo working without the distraction of the music. Then get the music working without the distraction of the servo. Then combine them. Does the servo work when you write a simple program to move it? – Mark Smith May 22 '17 at 14:27
  • yes, the servo is moving without the musicshield, and the musicshield is working without the servo, I'm having trouble combining both of them – Egm May 22 '17 at 14:32
  • That is very useful information. Could you edit it into your question please? – Mark Smith May 22 '17 at 14:33
  • yes, of course, thank you for helping me, I'm noobie at making questions too – Egm May 22 '17 at 14:35
1

Is this the MusicPlayer.h that you have? https://github.com/Seeed-Studio/Music_Shield

From the description it says:

The music player reads data from SD card and then feed into the VS1053 chip via SPI bus. This is done in TIMER1's ISR with a interval of 2ms. This job has a high priority and uses the cpu exclusively. In the spare cpu time, player does some process control, like play/pause.

That's the same timer that Servo.h uses. So the two libraries are not compatible. You could try using ServoTimer2 library or rewriting this library to get the 2ms timer with Timer 2.

  • thank you, yes that's my musicshield, I think I will try the ServoTimer2 – Egm May 23 '17 at 4:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.