Pages: [1]   Go Down
Author Topic: MP3 SPI bus transfer question  (Read 1766 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi, 
I'm successfully using Bill Porter's mp3 shield library to launch mp3s with an IR controller.  I also want a string of ws2801 lights to run at the same time.  Since both are using the SPI bus I need to transfer per the code here (the notes indicate that this example also has a shift register on the SPI bus):

Code:
  //disable interrupts to avoid collisions on the SPI bus between this code //and the MP3player library
  MP3player.pauseDataStream();

  //shift data
  tempIO = SPI.transfer(HIBYTE(output));
  tempIO<<8;
  tempIO = SPI.transfer(LOBYTE(output));

  //latch output on shift registers
  digitalWrite(OUTLATCH,LOW);
  digitalWrite(OUTLATCH,HIGH);
  digitalWrite(OUTLATCH,LOW);

  //enable interrupts
  MP3player.resumeDataStream();

Here's my attempt, but it's not working and I was hoping someone could point out my errors:

Code:
void loop() {
int key = getIRKey();
if (key !=0) {
switch(key) {
case 144: MP3player.playTrack(1); break;
//disable interrupts to avoid collisions on the SPI bus between this code //and the MP3player library
MP3player.pauseDataStream();
colorWipe(Color(0, 0, 0), 500);
colorWipe(Color(10, 10, 10), 20);
colorWipe(Color(50, 50, 50), 10);
colorWipe(Color(100, 100, 100), 20);
colorWipe(Color(150, 150, 150), 10);
colorWipe(Color(200, 200, 200), 10);
colorWipe(Color(255, 255, 255), 20);
colorWipe(Color(100, 100, 100), 20);
colorWipe(Color(10, 10, 10), 10);
colorWipe(Color(0, 0, 0), 10);
//enable interrupts
MP3player.resumeDataStream();
case 145: MP3player.playTrack(2); break;
case 146: MP3player.playTrack(3); break;
case 147: MP3player.playTrack(4); break;
}
}
}

What happens now is that the music will play but he lights won't. 
Thanks.   
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 446
Posts: 23872
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
switch(key) {
case 144: MP3player.playTrack(1); break;  <<< when the code hits this break, it goes to the }; at the end of the switch(){...} and continues
//disable interrupts to avoid collisions on the SPI bus between this code //and the MP3player library
MP3player.pauseDataStream();
colorWipe(Color(0, 0, 0), 500);
colorWipe(Color(10, 10, 10), 20);
colorWipe(Color(50, 50, 50), 10);
colorWipe(Color(100, 100, 100), 20);
colorWipe(Color(150, 150, 150), 10);
colorWipe(Color(200, 200, 200), 10);
colorWipe(Color(255, 255, 255), 20);
colorWipe(Color(100, 100, 100), 20);
colorWipe(Color(10, 10, 10), 10);
colorWipe(Color(0, 0, 0), 10);
//enable interrupts
MP3player.resumeDataStream();
case 145: MP3player.playTrack(2); break;
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi -
Thanks so much for taking a look at what's up.  I tried your code but didn't have any luck.  Music still played but no lights.  Then I tried moving break; around to a few places and what happens in one instance is kind of promising:

If I put it here:
Code:
         //enable interrupts
        MP3player.resumeDataStream(); break;

The lights turn on (they don't do the color wipe).  Then, after the length of time that would be the light sequence- the mp3 plays.  The lights just stay on.  What do you think?

Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 446
Posts: 23872
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't know what the colorwipe command does, maybe you need some time in between each one to see any effect?
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
I really appreciate you helping me out like this.  Here's a bit about the colorwipe.  It's from Adafruit strandtest:  https://github.com/adafruit/Adafruit-WS2801-Library and I just kind of tweaked it to get the result I want.  It basically just steps up the lights one after another and then back down again. 

In conjunction with the code I posted above for the function I'm working with, it also has this component towards the end of the sketch:
Code:
// fill the dots one after the other with said color
// good for testing purposes
void colorWipe(uint32_t c, uint8_t wait) {
  int i;
 
  for (i=0; i < strip.numPixels(); i++) {
      strip.setPixelColor(i, c);
      strip.show();
      delay(wait);
  }
}
/* Helper functions */
// Create a 24 bit color value from R,G,B
uint32_t Color(byte r, byte g, byte b)
{
uint32_t c;
c = r;
c <<= 8;
c |= g;
c <<= 8;
c |= b;
return c;
}

So that's all the colorwipe does.  Now when I run it by itself it fades the strand up and down no problem.  When I try it as I described, I get either nothing or the weird response depending on where I put break;  So, I'm wondering if any of this new info helps you to help me? 

Thanks again!
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 446
Posts: 23872
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

When the code hits
break;
it jumps to the end of the switch segment.

So if you want the music, and the colorwipe, I imagine it would need to be:
Code:
case 144: MP3player.playTrack(1);
//disable interrupts to avoid collisions on the SPI bus between this code //and the MP3player library
MP3player.pauseDataStream();
colorWipe(Color(0, 0, 0), 500);
colorWipe(Color(10, 10, 10), 20);
colorWipe(Color(50, 50, 50), 10);
colorWipe(Color(100, 100, 100), 20);
colorWipe(Color(150, 150, 150), 10);
colorWipe(Color(200, 200, 200), 10);
colorWipe(Color(255, 255, 255), 20);
colorWipe(Color(100, 100, 100), 20);
colorWipe(Color(10, 10, 10), 10);
colorWipe(Color(0, 0, 0), 10);
//enable interrupts
MP3player.resumeDataStream();
break;

the delay here in colorwipe
      delay(wait);
will keep anything else from happening
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Still not the solution.  The lights go on full white and stay on--they don't execute properly.  At the same time (and this is promising because it shows there's a bit of SPI sharing happening) I get a split-second burst of the mp3.  Then the lights just hang around on.  I pulled this from the developer's board and was wondering if it might have an impact?  Not sure how to implement if it is.

"Noting spi.transfer() is also called by refill from an interrupt and hence it needs to be interlocked with the interrupts by surrounding it: e.i."

Code:
MP3player.pauseDataStream();
bar = SPI.transfer(foo);
MP3player.resumeDataStream();
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 446
Posts: 23872
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Need some real programming help here, this is  beyond my SPI experience. Sorry.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

OK.  Thanks so much for helping at all.  I'll let you know if I can crack it.
Logged

Pages: [1]   Go Up
Jump to: