Sound with ESP32 - ...
 
Notifications
Clear all

Sound with ESP32 - I2S Protocol

57 Posts
5 Users
4 Reactions
6,099 Views
 Ppez
(@ppez)
Member
Joined: 2 years ago
Posts: 7
 

@zander It is the MP3 Player Code at https://dronebotworkshop.com/esp32-i2s/


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 4 years ago
Posts: 7410
 

@ppez Ok, thought so. See my post at https://forum.dronebotworkshop.com/postid/36993/

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 4 years ago
Posts: 7410
 

@ppez Sorry, you are going to be used as an example via random chance.

Computers at the lowest level work in binary, a bit is either ON or OFF, there is no maybe or half on state. As a result similar rules apply to code but a bit more complex. Therefore when debugging or asking for help (I assume you have read ALL the help files listed on the right just below your avatar) you also must be precise. The 'code' you posted was flawed two ways. First it isn't in a code box, second you probably typed it in by hand which is a NO NO. Since it is as you later said a copy of Bill's code than a link as you finally did is sufficient otherwise copy paste the entire RELEVANT code. Relevant means you don't need all the code if it is not involved in the issue.

I often ask for experience level and languages mastered. For example I have a little over 75,000 hours prior to retiring in 2004. And I have 'mastered' at least 4 languages and a lot more if counting all the modern clones of C. By knowing this we can use language you might understand, otherwise I will use my personal experience language and it will probably make no sense to you.

Small example. Your error re "Audio' does not name a type" to me is an obvious missing library. Since Bill's instructions include instructions re which library to use I now must assume you can't read see pic1 and pic2 which is the clickable github link. I will bet you have no idea what github is. Even if you click the link it will not help if you don't know what to look for. Pic3 shows you the green button to click then click the download zip file. After it is downloaded, learn how to install a library. Start at the arduino.cc web site, find the info on Libraries and you will get to pic4, that will take you to HERE  

Now it should compile, just be aware that sometimes you need to re-start the IDE, I have not yet determined a pattern, sometimes I do sometimes I don't.

Now you are ready.

Questions?

Screenshot 2023 01 16 at 12.02.39
Screenshot 2023 01 16 at 12.02.57
Screenshot 2023 01 16 at 12.04.53
Screenshot 2023 01 16 at 12.07.41

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 4 years ago
Posts: 7410
 

@ppez Finding the Libraries doc pages is a little tricky so I will give it to you. After arduino.cc is loaded, click on Documentation then Reference in the drop down. Then look on the left side and find Libraries. Now just read.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
 Ppez
(@ppez)
Member
Joined: 2 years ago
Posts: 7
 

@zander I did fix the problem. as suggested it was a library issue. Thank you.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 4 years ago
Posts: 7410
 

@ppez Yes, it can be tricky, sometimes Bill spells out the full library link and sometimes it's just a small single word link. I find sliding the cursor along the text as I read finds those pesky almost hidden links as in this case. Also the kind of error you got is the hallmark signature that you forgot to include the library. Spotting that comes with experience, next time you will know.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
 Ppez
(@ppez)
Member
Joined: 2 years ago
Posts: 7
 

Now that I have the library issue resolved, another probem has appeared. At the conclusion of the upload, "Error accessing microSD card! " appears on the serial monitor. I have rewired everything several times, tried two microSD breakout boards (Adafruit and a cheap one), and 2 microSD cards.

 

/*
ESP32 SD I2S Music Player
esp32-i2s-sd-player.ino
Plays MP3 file from microSD card
Uses MAX98357 I2S Amplifier Module
Uses ESP32-audioI2S Library -  https://github.com/schreibfaul1/ESP32-audioI2S 
*
DroneBot Workshop 2022
 https://dronebotworkshop.com 
*/

// Include required libraries
#include "Arduino.h"
#include "Audio.h"
#include "SD.h"
#include "FS.h"

// microSD Card Reader connections
#define SD_CS 5
#define SPI_MOSI 23
#define SPI_MISO 19
#define SPI_SCK 18

// I2S Connections
#define I2S_DOUT 22
#define I2S_BCLK 26
#define I2S_LRC 25

// Create Audio object
Audio audio;

void setup() {

// Set microSD Card CS as OUTPUT and set HIGH
pinMode(SD_CS, OUTPUT);
digitalWrite(SD_CS, HIGH);

// Initialize SPI bus for microSD Card
SPI.begin(SPI_SCK, SPI_MISO, SPI_MOSI);

// Start Serial Port
Serial.begin(115200);

// Start microSD Card
if(!SD.begin(SD_CS))
{
Serial.println("Error accessing microSD card!");
while(true);
}

// Setup I2S
audio.setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT);

// Set Volume
audio.setVolume(15);

// Open music file
audio.connecttoFS(SD,"/MYMUSIC.mp3");

}

void loop()
{
audio.loop();
}

   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 4 years ago
Posts: 7410
 

@ppez Are you getting that msg once or repetitively?

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
 Ppez
(@ppez)
Member
Joined: 2 years ago
Posts: 7
 

@zander many times, as I said, different cards, different readers, different wiring.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 4 years ago
Posts: 7410
 

@ppez Sorry, I should have been more clear but your answer is instructive too.

What I meant was when you run the sketch, do you see line after line of that message as opposed to it just happening once.

Part 2.

Different readers points to a wiring error.

Different cards is unlikely in the extreme and easily tested on your computer.

Wiring is the chief suspect. I assume a breadboard and dupont wires, they can be quite flaky as we tend to buy the cheapest thinking it won't matter. Maybe yes, maybe no. Use your VOM in continuity mode and meter from the reader wipers to the esp32.

Place either your digital probe or VOM in auto or volts on pin 5 of the SD reader. If it shows 5V then the reader is defective, if it shows 0 then the esp32 is defective.

BTW, if you order parts in bulk, and one is bad, sometimes they all are because they are cheap clones that may be garbage. I would look for a very simple SD reader test script to determine if the reader is ok or not. Although the chances of 2 random TF cards being bad is remote, bring a 3rd card into play (make sure the write protect is in the correct orientation)

Once you are 99.99999% sure the TF cards are ok (test each on your computer) then determine if the reader is ok via a simple sketch, that only leaves wiring and the esp32. Change pins, use esp32 in a different sketch that uses the same pin. That will determine if it's the esp32 or wiring.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
 Ppez
(@ppez)
Member
Joined: 2 years ago
Posts: 7
 

Been away from this for a few days but now back at it. Thanks to the help here, some progress but now get the following message on the serial monitor after uploading.

 

Guru Meditation Error: Core 1 panic'ed (StoreProhibited). Exception was unhandled.
Core 1 register dump:
PC : 0x4008c1ca PS : 0x00060533 A0 : 0x8008e1f6 A1 : 0x3ffb1880
A2 : 0xb3cf0a0d A3 : 0x0000abab A4 : 0xb33fffff A5 : 0x00000001
A6 : 0x00060320 A7 : 0x0000cdcd A8 : 0x0000abab A9 : 0x3ffb1bd0
A10 : 0x3ffc25a8 A11 : 0x3ffc2e70 A12 : 0x3f400144 A13 : 0x00000000
A14 : 0x3ffc01a8 A15 : 0xff000000 SAR : 0x00000006 EXCCAUSE: 0x0000001d
EXCVADDR: 0xb3cf0a0d LBEG : 0x400889ea LEND : 0x400889f5 LCOUNT : 0x00000000

ELF file SHA256: 0000000000000000

Backtrace: 0x4008c1ca:0x3ffb1880 0x4008e1f3:0x3ffb18b0 0x4008e82d:0x3ffb18d0 0x40081a3d:0x3ffb18f0 0x40081c74:0x3ffb1910 0x4008150f:0x3ffb1930 0x400dabe1:0x3ffb1950 0x400dd3e7:0x3ffb1bd0 0x400dd857:0x3ffb1f60 0x400d185d:0x3ffb1f80 0x400eb41e:0x3ffb1fb0 0x4008b24e:0x3ffb1fd0

Rebooting...
ets Jul 29 2019 12:21:46

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1216
ho 0 tail 12 room 4
load:0x40078000,len:10944
load:0x40080400,len:6388
entry 0x400806b4

 

And it repeats, seemingly forever.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 4 years ago
Posts: 7410
 

@ppez That's a CPU crash dump. I used to deal in that stuff everyday, but for a different processor. I doubt there is much expertise here for that. Start by simply commenting out big chunks of code to do a simple divide and conquer. If you are messing with interrupts, file system, timers, events then those are suspects. Also every string operation is a suspect, especially those that 'grow' or 'access' a string and those in loops are most suspect. Just comment them out one at a time until you find it.

Start with the ESP decoder HERE, copy the dump down to just before the reboot msg and see what you get, if lucky it will give you the statement causing the problem.

Those are just my first cut general problem solving hunches, I don't have the training on this architecture to go very much deeper.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
Page 4 / 4