VS1053.h and SD.h libraries crash i2C bus (Music Maker 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
User avatar
mikarmin
 
Posts: 19
Joined: Mon Oct 03, 2022 5:23 pm

VS1053.h and SD.h libraries crash i2C bus (Music Maker Shield)

Post by mikarmin »

I purchased the MusicMaker shield with amplifier. I installed pass through headers on all pins (including the 6 pin ICSP header). I connected to an Arduino Uno Rev3. I first opened the example sketch player_Simple from the VS1053.h library v1.2.1 and successfully played music with an SD card installed with 2 tracks loaded. Then I added a 128x64 oled screen to the i2C pins (A4, A5) and loaded the SSD1306_128x64_i2C sample sketch from the ssd1306.h library v2.5.7. Once again, example worked perfect and got full screen functionality. I then attempted to combine the two. The minute I declared the screen while having either the VS1053.h library or the SD.h library included, the screen would fail the begin() method. Once I commented out the #include statements on these libraries, the i2C attached screen would work normally. Can someone help me understand why I can't use the i2C circuit/protocol on the musicmaker shield? Is there an issue in the latest sets of libraries? I could try reverting back libraries but these are all Adafruit libraries and products. Thanks

User avatar
mikeysklar
 
Posts: 13824
Joined: Mon Aug 01, 2016 8:10 pm

Re: VS1053.h and SD.h libraries crash i2C bus (Music Maker Shield)

Post by mikeysklar »

I've seen other examples in forum threads of people using i2c with the Music Maker shield.

If you load the VS1053.h and setup the shield first and then try to initialize the display do you get the same behavior?

Can you post a photo of how you have connected the display to the shield?

User avatar
mikarmin
 
Posts: 19
Joined: Mon Oct 03, 2022 5:23 pm

Re: VS1053.h and SD.h libraries crash i2C bus (Music Maker Shield)

Post by mikarmin »

12c setup. 2 wires only. Can use A4, A5 or the SDA, SCL pins. Works fine with example sketches either pins. Here is my sketch. No matter what order, if I declare the screen with the VS1053 or SD libraries included it will not get past begin() method for the screen.

Code: Select all

// include SPI, MP3 and SD libraries
#include <SPI.h>
#include <Adafruit_VS1053.h>
#include <SD.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

// These are the pins used for the music maker shield
#define MP3_RESET  -1        // VS1053 reset pin (unused!)
#define SD_CS       4        // SD Card select pin 
#define MP3_CS      7        // VS1053 chip select pin (output)
#define DREQ        3        // VS1053 Data request, ideally an Interrupt pin, common between breakout and shield
#define MP3_DCS     6        // VS1053 Data/command select pin (output)

//This is the definition needed for the OLED display using i2C protocol
#define SCREEN_WIDTH  128   // OLED display width,  in pixels
#define SCREEN_HEIGHT 64    // OLED display height, in pixels
#define OLED_ADDRESS  0x3C  //OLED i2C address 
#define OLED_RESET     -1   // Reset pin # (or -1 if sharing Arduino reset pin)
// On an arduino UNO:       A4(SDA), A5(SCL)  is defined by the Wire Library

//Create new objects of each item attached to Arduino
Adafruit_VS1053_FilePlayer musicPlayer = Adafruit_VS1053_FilePlayer(MP3_RESET, MP3_CS, MP3_DCS, DREQ, SD_CS);
Adafruit_SSD1306 oled(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);


void setup() {
  Serial.begin(9600);
  beginMusicMaker();
  beginScreen();
  
 
}

void loop() {
  while(1);  //Do nothing  verifying screen
}

void beginScreen(){

   if (!oled.begin(SSD1306_SWITCHCAPVCC, OLED_ADDRESS)) { //initialize the screen
    Serial.println(F("SSD1306 allocation failed"));
    while (true); // Don't proceed, loop forever
   }
   Serial.println("OLED Screen Found");
   // Show initial display buffer contents on the screen --
   // the library initializes this with an Adafruit splash screen.
   oled.display();
   delay(2000); // Pause for 2 seconds
   oled.clearDisplay();  // Clear the buffer
   oled.setTextSize(1);          // text size
   oled.setTextColor(WHITE);     // text color
   oled.setCursor(0, 10);        // position to display
   oled.println("OLED SCREEN ATTACHED!"); // text to display
   oled.display();               // show on OLED
}


void beginMusicMaker(){

  if (!musicPlayer.begin()) { // initialise the music player
     Serial.println(F("Couldn't find VS1053, Check wiring"));
     while (true); // Don't proceed, loop forever
  }
  Serial.println("MP3 Shield Found");
  oled.println("Music Maker Found");
  oled.display();
  
  
   if (!SD.begin(SD_CS)) {
    Serial.println(F("SD Card failed, or not present"));
    for(;;); // Don't proceed, loop forever
  }
  Serial.println("Micro SD Card Found");
  oled.display();
}
Attachments
screensetup.jpg
screensetup.jpg (207.29 KiB) Viewed 384 times

User avatar
mikarmin
 
Posts: 19
Joined: Mon Oct 03, 2022 5:23 pm

Re: VS1053.h and SD.h libraries crash i2C bus (Music Maker Shield)

Post by mikarmin »

I ordered a bootloader programmer to use on the iCSP pins to check if Arduino boot needs to be updated. The Atmega16U2 chip is at the latest serial firmware version (read VID, PID before programming, grabbed latest hex file and programmed and re-read) although this should be connection only between usb and serial but thought I would double check. Once again, not sure how the boot on the ATmega328P could cause this but trying to get everything current. Programmer should be here tomorrow. Will update once I load latest boot to see if behavior changes

User avatar
mikeysklar
 
Posts: 13824
Joined: Mon Aug 01, 2016 8:10 pm

Re: VS1053.h and SD.h libraries crash i2C bus (Music Maker Shield)

Post by mikeysklar »

Thank you for the photo and code share.

Are you able to use the display when connecting through hardware i2c SCL/SDA on D19/D18 pass-through to the connected MusicMaker? You had mentioned that the software i2c is not working with A4/A5, but it was not clear to me if the hardware i2c pins were working.
AFC67AD2-DBB1-4696-AD31-63EAD4C61A4F.jpeg
AFC67AD2-DBB1-4696-AD31-63EAD4C61A4F.jpeg (832.76 KiB) Viewed 376 times

User avatar
mikarmin
 
Posts: 19
Joined: Mon Oct 03, 2022 5:23 pm

Re: VS1053.h and SD.h libraries crash i2C bus (Music Maker Shield)

Post by mikarmin »

Same behavior regardless of the pass thru pins or using A4/A5.

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

Re: VS1053.h and SD.h libraries crash i2C bus (Music Maker Shield)

Post by adafruit_support_bill »

not sure how the boot on the ATmega328P could cause this
I suspect you are looking at a memory problem. The Atmega328 has only 2K of RAM. Your 128x64 display is going to take 1/2 of that for its frame buffer. The SD card needs 512 bytes for the block buffer. And you typically need to keep at least 500 bytes free for the stack & system overhead. Upgrading to a processor with more RAM like the Metro M0 should clear up the problem.

https://learn.adafruit.com/memories-of- ... ot-dot-dot

User avatar
mikarmin
 
Posts: 19
Joined: Mon Oct 03, 2022 5:23 pm

Re: VS1053.h and SD.h libraries crash i2C bus (Music Maker Shield)

Post by mikarmin »

As stated, I can keep the OLED screen connected to either pins through the stacked music maker shield and get it to work perfectly using sample sketches from Adafruit SSD1306 library or any other code I write using the screen. I just removed the musicmaker shield and plugged the screen into the Uno R3 directly. Loaded the SSD1306 library sample code. Worked perfect. Used the #include statements for the VS1503 and/or the SD library. Nothing else, no code calling methods or declarations from it, shield not even attached. Screen fails the begin method. Definitely seems to point to an issue with the libraries

User avatar
mikarmin
 
Posts: 19
Joined: Mon Oct 03, 2022 5:23 pm

Re: VS1053.h and SD.h libraries crash i2C bus (Music Maker Shield)

Post by mikarmin »

Or RAM, that seems to make sense but would hope we could have a music maker shield and a screen attached to an UNO R3. Is there a way to monitor RAM utilization in say a "debug" type environment?

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

Re: VS1053.h and SD.h libraries crash i2C bus (Music Maker Shield)

Post by adafruit_support_bill »

The buffers are going to get allocated as soon as you declare the music player and oled objects. Simple math says that they both won't fit on an UNO 328. You might be able to just squeeze them in on something like a Leonardo (Atmega32U4 has 2.5K). An M0 would give you plenty of elbow room.
Is there a way to monitor RAM utilization in say a "debug" type environment?
See the "Measuring Memory Usage" page in the link above. Debugging options in the UNO are pretty limited. Just opening the Serial port will cost you another 64 bytes for the serial buffer.

User avatar
mikarmin
 
Posts: 19
Joined: Mon Oct 03, 2022 5:23 pm

Re: VS1053.h and SD.h libraries crash i2C bus (Music Maker Shield)

Post by mikarmin »

Hello,

Thanks. If I wanted to go Metro route , I would really like to go with the M4 metro express or the M4 Airlift express which are both sold out, everywhere..... I ordered the M4 grand central since I could find one of those. Figure adding the ESP32 and a bluetooth circuit to it won't hinder it and definitely gives headroom. Once the M4 Airlifts are back in stock, that will be on the way. Or maybe I will switch to Feathers and CircuitPython 100%. Thanks again. The Uno is outdated but I didn't realize just how much.... I have a Pi and used it for FRC robotics camera recognition purposes but shied away from normal development due to Linux kernel. Well guess now I can play with both the Arduino IDE AND CircuitPython. Thanks again.

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

Re: VS1053.h and SD.h libraries crash i2C bus (Music Maker Shield)

Post by adafruit_support_bill »

I'm still a big fan of the Atmega processors for simple embedded controls. But as soon as you start getting into more memory intensive things like graphics and file systems you start to run out of space really quickly.

More modern processors like the ARM give you more resources to work with. The Grand Central will give you a huge boost in both memory and speed.

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

Return to “Arduino Shields from Adafruit”