How to stop Music Maker from playing song to read a sensor

This is a special forum devoted to educators using Adafruit and Arduino products for teaching.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
efeigenbaum
 
Posts: 102
Joined: Fri Feb 24, 2017 3:23 pm

How to stop Music Maker from playing song to read a sensor

Post by efeigenbaum »

I want to have the Music Maker play music ONLY while an event is happening as read by a sensor. (It will only play music while an accelerometer measures acceleration). Is there a way to interrupt the music so that it can read a sensor and then shut off the music if no new motion is detected? Thanks.

User avatar
adafruit_support_bill
 
Posts: 88112
Joined: Sat Feb 07, 2009 10:11 am

Re: How to stop Music Maker from playing song to read a sens

Post by adafruit_support_bill »

There is the reset pin 'RST' - Somewhat of a brute-force approach.: https://learn.adafruit.com/adafruit-aud ... -pins-3-15

A better approach is to have a silent track associated with trigger pin 0 and your other sound associated with a higher number pin. If you pull pin 0 to ground, any other sound will stop and it will play your silent track. https://learn.adafruit.com/adafruit-aud ... triggering

User avatar
efeigenbaum
 
Posts: 102
Joined: Fri Feb 24, 2017 3:23 pm

Re: How to stop Music Maker from playing song to read a sens

Post by efeigenbaum »

Thanks. I hadn't thought of that!

User avatar
efeigenbaum
 
Posts: 102
Joined: Fri Feb 24, 2017 3:23 pm

Re: How to stop Music Maker from playing song to read a sens

Post by efeigenbaum »

Can you please give me a little more detail on how to do this? The music maker is going to receive information from a radio signal to start playing music if a boolean flag is true. If it's false, we want shut off the music (or play a silent track as you suggest.) Can you please explain in detail what we need to do to to make this happen?

User avatar
adafruit_support_bill
 
Posts: 88112
Joined: Sat Feb 07, 2009 10:11 am

Re: How to stop Music Maker from playing song to read a sens

Post by adafruit_support_bill »

he music maker is going to receive information from a radio signal to start playing music if a boolean flag is true.
That presumes that you have some sort of radio module and a processor running a program that can interpret the information. Based on that boolean flag being true, your program would need to set some GPIO pin LOW to trigger the sound to be played on the Fx board.

To turn off the sound, you would use the very same processor to set a different GPIO pin to LOW to play the silent track. Since the triggers are prioritized by Fx pin number, you would associate the silent track with Fx pin 0 so that it would effectively stop any track that was currently playing.

User avatar
efeigenbaum
 
Posts: 102
Joined: Fri Feb 24, 2017 3:23 pm

Re: How to stop Music Maker from playing song to read a sens

Post by efeigenbaum »

Another related question:

Can the radio transceiver, nRF24L01, be used with the music maker? The pins it uses are:

1 - GND
2 - VCC 3.3V !!! NOT 5V
3 - CE to Arduino pin 7
4 - CSN to Arduino pin 8
5 - SCK to Arduino pin 13
6 - MOSI to Arduino pin 11
7 - MISO to Arduino pin 12

I think that the music maker uses pins 7, 11, 12, and 13. Any idea how I can get around this and use the transceiver?

User avatar
adafruit_support_bill
 
Posts: 88112
Joined: Sat Feb 07, 2009 10:11 am

Re: How to stop Music Maker from playing song to read a sens

Post by adafruit_support_bill »

My apologies, the advice above was assuming you were using one of the Fx sound boards. https://www.adafruit.com/?q=fx
The MusicMaker is a bit more complex of a board.

The SPI pins: 11, 12 and 13 are fixed, but they can be shared by other SPI devices.
Pin 7 is required for chip-select on the VS1053. If the library for your radio module supports different pin options, you could use that. Otherwise, you would need to hack both the board and the library for the MusicMaker.

User avatar
efeigenbaum
 
Posts: 102
Joined: Fri Feb 24, 2017 3:23 pm

Re: How to stop Music Maker from playing song to read a sens

Post by efeigenbaum »

I think I can change the 7 pin to something else. Thanks.

By the way, if I have the mp3 track playing in the background could I simply use the command musicPlayer.currentTrack.close(); to stop playing it?

User avatar
adafruit_support_bill
 
Posts: 88112
Joined: Sat Feb 07, 2009 10:11 am

Re: How to stop Music Maker from playing song to read a sens

Post by adafruit_support_bill »

Are you programming in Arduino (C++) or Python?
The Arduino library for the VS1053 has a stopPlaying() function.

Python has a stop_playback() function.

User avatar
efeigenbaum
 
Posts: 102
Joined: Fri Feb 24, 2017 3:23 pm

Re: How to stop Music Maker from playing song to read a sens

Post by efeigenbaum »

Yes I am using an Arduino Uno.

User avatar
efeigenbaum
 
Posts: 102
Joined: Fri Feb 24, 2017 3:23 pm

Re: How to stop Music Maker from playing song to read a sens

Post by efeigenbaum »

Do you know where I can find the keywords/functions for the VS1053.h library? I've searched but can't find it.

User avatar
adafruit_support_bill
 
Posts: 88112
Joined: Sat Feb 07, 2009 10:11 am

Re: How to stop Music Maker from playing song to read a sens

Post by adafruit_support_bill »

The shield guide is a little out-of date: https://learn.adafruit.com/adafruit-mus ... ethods-8-1

The library source is always the most up-to-date reference.
The public functions for the Adafruit_VS1053_FilePlayer start at line 166:
https://github.com/adafruit/Adafruit_VS ... t_VS1053.h

User avatar
efeigenbaum
 
Posts: 102
Joined: Fri Feb 24, 2017 3:23 pm

Re: How to stop Music Maker from playing song to read a sens

Post by efeigenbaum »

The musicPlayer.stopPlaying() function works beautifully. Thanks so much for all your help.

User avatar
adafruit_support_bill
 
Posts: 88112
Joined: Sat Feb 07, 2009 10:11 am

Re: How to stop Music Maker from playing song to read a sens

Post by adafruit_support_bill »

Good to hear it is working for you. Thanks for the follow-up.

User avatar
efeigenbaum
 
Posts: 102
Joined: Fri Feb 24, 2017 3:23 pm

Re: How to stop Music Maker from playing song to read a sens

Post by efeigenbaum »

Referring to an earlier post here I am having trouble getting my radio transceivers to work with the music maker...it is using pins 11, 12, and 13 for communication - the same pins that the music maker is using for those things. I am getting strange results ... I’m trying to send a single integer(7) as a test but it is receiving(or randomly printing) the integer 1285. Any ideas why? I can send the code if that would help. I’ve commented out most of it to try to debug it. When I connected it to to different transceiver not using the music shield it works fine,

Locked
Please be positive and constructive with your questions and comments.

Return to “For Educators”