VS1053 (MP3 player) not happy with CAN bus shield

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
paulvissers2005
 
Posts: 5
Joined: Thu Sep 26, 2013 5:15 pm

VS1053 (MP3 player) not happy with CAN bus shield

Post by paulvissers2005 »

Image

When I combine:
  • a good functioning combination of ArduinoUno + Adafruit MP3 player VS1053 with
    also good functioning combination of the same ArduinoUno + CAN bus shield from Seeedstudio,


then ... the stack of the 3 prints is not working (not fysically 3 on top of each other, connected as in my drawings)

I suspect the SPI bus, there might be a conflict. Or the interrupts. How do I change those settings? Or do I need to run the Adafruit on a different bus?

Image

Hope to hear from your experiences,
-paul-

About the project; I want the CAN bus in my DIY EV to play particular MP3 audio messages over the radio loudspeakers.

Image

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: VS1053 (MP3 player) not happy with CAN bus shield

Post by adafruit_support_mike »

I'm not familiar with the CAN bus shield, but you should be able to find the pins it uses by looking in the library that supports it.

Having multiple SPI devices share the same MOSI, MISO, and CLK lines doesn't cause any problems. Those are meant to be shared. Each device needs its own CS signal though (that's how the microcontroller selects the device it wants to talk to), and some devices also have RESET pins that need to be toggled to make them start working correctly.

Like I said, that information will all be in the library. The folks at Seeed might be able togive you a list of pins and signals their shield uses, then we can compare it to the ones used by the Music Maker.

paulvissers2005
 
Posts: 5
Joined: Thu Sep 26, 2013 5:15 pm

Re: VS1053 (MP3 player) not happy with CAN bus shield

Post by paulvissers2005 »

Image

I’ve updated my drawing with CAN bus connections, Mike [ shield drawing here and forum ]
CAN shield uses Interrupt 0 (pin D2 on ArduinoUno). Adafruit not. Adafruit stops during initialisiation at if (!musicplayer.begin()) …

You have more suggestions? Thanks for --all people-- input. -paul-

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

Re: VS1053 (MP3 player) not happy with CAN bus shield

Post by adafruit_support_bill »

Post the code that you are using.

paulvissers2005
 
Posts: 5
Joined: Thu Sep 26, 2013 5:15 pm

Re: VS1053 (MP3 player) not happy with CAN bus shield

Post by paulvissers2005 »

This is the code that I use to receive a CAN message with the Seeedstudio CAN bus shield, have it translated to a .mp3 filename and have it then played by the Adafruit VS1053. This code is a collection from both demos. The code is not finished and may contain errors, because it is not working properly.

Code: Select all

// UNO...13  werkt als simpele MP3 shield; alleen drukknop op PIN6 om file af te spelen.
// demo: CAN-BUS Shield, send data
// 14a blijft in de verkeerde LOOP hangen, maar 14 deed het nog wel gewoon, zonder CAN shield.

/*************************************************** 
  This is an example for the Adafruit VS1053 Codec Breakout

  Designed specifically to work with the Adafruit VS1053 Codec Breakout 
  ----> https://www.adafruit.com/products/1381

  Adafruit invests time and resources providing this open source code, 
  please support Adafruit and open-source hardware by purchasing 
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.  
  BSD license, all text above must be included in any redistribution
 ****************************************************/

// include SPI, MP3 and SD libraries
#include <mcp_can.h>
#include <SPI.h>
#include <Adafruit_VS1053.h>
#include <SD.h>
#include <stdio.h>

// define the pins used
//#define CLK 13       // SPI Clock, shared with SD card    DE CONNECTOR PINNEN MOETEN WEL INGESTOKEN BLIJVEN
//#define MISO 12      // Input data, from VS1053/SD card   DE CONNECTOR PINNEN MOETEN WEL INGESTOKEN BLIJVEN
//#define MOSI 11      // Output data, to VS1053/SD card    DE CONNECTOR PINNEN MOETEN WEL INGESTOKEN BLIJVEN
#define RESET 9      // VS1053 reset pin (output)
#define CS 10        // VS1053 chip select pin (output)
#define DCS 8        // VS1053 Data/command select pin (output)
#define DREQ 3       // VS1053 Data request pin (into Arduino)
#define CARDCS 4     // Card chip select pin
// hierna overgenomen uit de CAN demo file:
#define INT8U unsigned char
INT8U Flag_Recv = 0;
INT8U len = 0;
INT8U buf[8];
INT32U canId = 0x000;

Adafruit_VS1053_FilePlayer musicPlayer = Adafruit_VS1053_FilePlayer(RESET, CS, DCS, DREQ, CARDCS);
// Alternately, use 'soft SPI'. Requires Adafruit's flexible SD library
// Adafruit_VS1053_FilePlayer musicPlayer = Adafruit_VS1053_FilePlayer(MOSI, MISO, CLK, RESET, CS, DCS, DREQ, CARDCS);

const int buttonPin = 6;     // the number of the pushbutton pin
int buttonState = 0;         // variable for reading the pushbutton status
int previousButtonState = 0; // om op de flank te kunnen schakelen
String deel1, deel2, deel3, filenaam; 
char muzieknaam[14];

void setup() {
  // EERST de CAN BUS SET UP IN PLAKKEN:
  Serial.begin(115200);    // init can bus, baudrate: 100k
  if(CAN.begin(CAN_100KBPS) ==CAN_OK) Serial.print("can init ok!!\r\n");
  else Serial.print("Can init fail!!\r\n");
  attachInterrupt(0, MCP2515_ISR, FALLING); //start interrupt, werkt via pin=2(PWM) VRIJ LATEN

  // HIERNA de MP3 STUKKEN:
  // initialize the pushbutton pin as an input:
  // pinMode(buttonPin, INPUT);     
  pinMode(buttonPin, INPUT_PULLUP);           // set pin to input
deel1 = String("track0");
deel3 = String(".mp3");
filenaam = "trackleeg"; // zo wordt straks de bestandsnaaam opgebouwd.

  Serial.begin(9600);
  delay(1000);
  Serial.println("Adafruit VS1053 Library Test");

  // initialise the music player
  if (!musicPlayer.begin()) {
    Serial.println("VS1053 not found");
    while (1);  // don't do anything more
  }

  musicPlayer.sineTest(0x44, 500);    // Make a tone to indicate VS1053 is working
 
  if (!SD.begin(CARDCS)) {
    Serial.println("SD failed, or not present");
    while (1);  // don't do anything more
  }
  Serial.println("SD OK!");
  
  // Set volume for left, right channels. lower numbers == louder volume!
  musicPlayer.setVolume(20,20);

  /***** Two interrupt options! *******/ 
  // This option uses timer0, this means timer1 & t2 are not required
  // (so you can use 'em for Servos, etc) BUT millis() can lose time
  // since we're hitchhiking on top of the millis() tracker
  //musicPlayer.useInterrupt(VS1053_FILEPLAYER_TIMER0_INT);
  
  // This option uses a pin interrupt. No timers required! But DREQ
  // must be on an interrupt pin. For Uno/Duemilanove/Diecimilla
  // that's Digital #2 or #3
  // See http://arduino.cc/en/Reference/attachInterrupt for other pins
  // *** This method is preferred
  if (! musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT))
    Serial.println("DREQ pin is not an interrupt pin");
    Serial.println("nu GING GONG afspelen");
    musicPlayer.playFullFile("track003.mp3"); //gong en gong back. ARDUINO WACHT tot het is afgelopen. Knoppendrukken heeft nu geen zin.
}

//  INTERRUPT afloop van de CAN bus MEDEDELING HIER:
void MCP2515_ISR()
{
  Flag_Recv = 1;
}


void loop() {  
  delay(50);     // zonder delay, is de bus accuut 95% belast. Met deze delay(50) nog maar 3%

  // Alternately, we can just play an entire file at once
  // This doesn't happen in the background, instead, the entire
  // file is played and the program will continue when it's done!
  // musicPlayer.playFullFile("track002.mp3");

  // Start playing a file, then we can do stuff while waiting for it to finish
  // if (! musicPlayer.startPlayingFile("track001.mp3"))  //frog 
  // {
  //   Serial.print("Could not open file");
  //   return;
  // }
  if(Flag_Recv)     // check if data was received
  {
    Flag_Recv = 0;     //clear flag
    CAN.readMsgBuf(&len, buf);    // read data,  len= DLC= DataLengthChar,    buf: data
    canId = CAN.getCanId();
    Serial.print(len);
    Serial.print("  en de data is: ");
    for (int i = 0; i < len; i ++)  // print to show and check
    {
      Serial.print(buf[i]); 
      Serial.print("   ");
    }
      Serial.print("CAN ID = ");
      Serial.println(canId);

       deel2 = String(buf[0], DEC); 
       filenaam = deel1 + deel2 +  deel3;  
       filenaam.toCharArray(muzieknaam, sizeof(muzieknaam)); 
       musicPlayer.startPlayingFile(muzieknaam); 
    
    // if (buf[0] == 11)     // TEST dan is deboodschap voor de MP3 bestemd
    // {
    //   musicPlayer.startPlayingFile("track011.mp3");
    // }
  }




  Serial.println(",");    // begonnen met knop af te tasten

  // File is playing in the background
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == LOW) 
  {     
    if (previousButtonState == HIGH) 
    {
      previousButtonState = LOW;
      musicPlayer.startPlayingFile("track001.mp3");
    }
  } 
  else 
  {      // buttonState is dus HIGH
    if (previousButtonState == LOW) {previousButtonState = HIGH;}
  }

  while (musicPlayer.playingMusic) {
    // file is now playing in the 'background' so now's a good time
    // to do something else like handling LEDs or buttons :)
    // Serial.print(".");
    delay(100);
  }
  // Serial.println("Done playing music");
}
--paul—

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

Re: VS1053 (MP3 player) not happy with CAN bus shield

Post by adafruit_support_bill »

From the code and your drawings, it looks like both VS1053 and the CAN bus shield are using pin 10 for chip select.

paulvissers2005
 
Posts: 5
Joined: Thu Sep 26, 2013 5:15 pm

Re: VS1053 (MP3 player) not happy with CAN bus shield

Post by paulvissers2005 »


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

Return to “Arduino Shields from Adafruit”