r/ArduinoHelp • • 22d ago

Bluepad32 end curly bracket error

/r/esp32projects/comments/1xp1ubo/bluepad32_end_curly_bracket_error/

I hope someone can help with this. I’ve been trying to use Bluepad32 to pair a ps5 controller with my esp32-s3. I need it to control a music player and four servos. My code is fine and has all closed curly brackets, but the verify output keeps telling me I need an ending curly brackets after input at the very end of my code. I think it has to do with the FreeRTOS file.

I have no idea how to fix this. Please help! I’ve been trying to fix this for several days. If I add the curly bracket to the FreeRTOS file, it just breaks more.

1 Upvotes

15 comments sorted by

View all comments

Show parent comment

1

u/gm310509 21d ago

Again I refer you to the posting guide in the comment above.

The Serial Monitor (which is what I assume you mean by Serial manager) won't just randomly say "it didn’t have the space to connect to the SD card".

The Serial Monitor only displays what is sent to it from your program via a Serial.print type of statement. That means that the message is coming from your program based upon condition in your code - code which you have not shared.

For all we know, it could be that the SD Card is not correctly formatted. Or maybe it is full (i.e. 0% free space) or some other type of problem.

Let me try to turn the question around - I am thinking of a number. You get 3 guesses. What is the number I am thinking of? Other than a "yes" or "no", these are the only clues I give you. This is the question you are asking if you do not follow the Asking for help quick guide and Rule 2 - be descriptive.

1

u/Cosplay_Pappy 21d ago

Sorry! I’m away from my laptop right now, but I’ll post my code in the morning.

1

u/gm310509 21d ago

It may also help if you explain why a hardware issue caused a mismatched braces (curly bracket) compiler issue.

The reason I ask is because the compiler is not affected by incorrect hardware. Indeed you don't even need an Arduino to be connected to your PC to compile your code. And compiling is the step in the upload process that will report syntax errors like mismatched braces.

So my thinking is that there is a lot more going on here than what you have shared so far if you really believe that a hardware error caused the mismatch braces error. Because that definitely doesn't sound like two related issues. It sounds like you might have had two unrelated issues and happen to have resolved both at the same time (a very common scenario) and possibly conflated them into a single issue.

1

u/Cosplay_Pappy 18d ago

Well, the hardware wasn't actually causing the issue, but regardless of the issue, the board wouldn't have been able to do what I needed it to do. So I scrapped that version, and went back to my initial version, which I will paste below. Are there any libraries that I can delete?:

#include <AudioFileSource.h>
#include <AudioFileSourceBuffer.h>
#include <AudioFileSourceFATFS.h>
#include <AudioFileSourceFS.h>
#include <AudioFileSourceFunction.h>
#include <AudioFileSourceHTTPStream.h>
#include <AudioFileSourceICYStream.h>
#include <AudioFileSourceID3.h>
#include <AudioFileSourceLittleFS.h>
#include <AudioFileSourcePROGMEM.h>
#include <AudioFileSourceSD.h>
#include <AudioFileSourceSPIFFS.h>
#include <AudioFileSourceSPIRAMBuffer.h>
#include <AudioFileSourceSTDIO.h>
#include <AudioFileStream.h>
#include <AudioGenerator.h>
#include <AudioGeneratorAAC.h>
#include <AudioGeneratorFLAC.h>
#include <AudioGeneratorMIDI.h>
#include <AudioGeneratorMOD.h>
#include <AudioGeneratorMP3.h>
#include <AudioGeneratorMP3a.h>
#include <AudioGeneratorOpus.h>
#include <AudioGeneratorRTTTL.h>
#include <AudioGeneratorTalkie.h>
#include <AudioGeneratorWAV.h>
#include <AudioLogger.h>
#include <AudioOutput.h>
#include <AudioOutputBuffer.h>
#include <AudioOutputFilterBiquad.h>
#include <AudioOutputFilterDecimate.h>
#include <AudioOutputI2S.h>
#include <AudioOutputI2SNoDAC.h>
#include <AudioOutputInternalDAC.h>
#include <AudioOutputMixer.h>
#include <AudioOutputNull.h>
#include <AudioOutputPDM.h>
#include <AudioOutputPWM.h>
#include <AudioOutputSPDIF.h>
#include <AudioOutputSPIFFSWAV.h>
#include <AudioOutputSTDIO.h>
#include <AudioOutputSerialWAV.h>
#include <AudioOutputULP.h>
#include <AudioStatus.h>
//#include <ESP8266Audio.h>
//#include <ESP8266AudioVer.h>
#include <spiram-fast.h>


//#include <I2S.h>
#include "SPI.h"
#include <SD.h>
#include <sd_defines.h>
#include <sd_diskio.h>


//#include <Ps3Controller.h>


//#include <ESP32ServoController.h>
#include <ps5Controller.h>
#include <ESP32Servo.h>
//#include <Servo.h>
//#include <Bluepad32.h>
#include <driver/i2s_std.h>
#include <dummy.h>


#include <FS.h>
//#include <FSImpl.h>
//#include <vfs_api.h>


#include <ESP_I2S.h>
#include <wav_header.h>
#include <Arduino.h>
#include <Audio.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
#define I2S_NUM     0


#define NUM_BYTES_TO_READ_FROM_FILE 1024    // How many bytes to read from wav file at a time


//int player = 1;
//int battery = 0;


/*File WavFile;
static const i2s_port_t i2s_num = I2S_NUM_0;
uint32_t BytesRead=0;
*/
//servos
Servo myServoY;
Servo myServoO;
Servo myServoP;
Servo myServoB;
const int servosCount =  4;
static const int servosPins[servosCount] = {12, 13, 14, 15, };


Servo servo[servosCount];


void setServos(int degrees){
  for(int i=0; i< servosCount; ++i) {
    servo[i].write((degrees + (35*i))%180);
  }
}


//Create Audio Object
Audio audio;


void notify()
{
  /*char messageString[200];
  sprintf(messageString, "%4d, %4d, %4d, %4d, %3d, %3d, %3d, %3d, %3d, %3d, %3d, %3d, %3d, %3d, %3d, %3d, %3d, %3d, %3d, %3d, %3d, %3d, %3d, %3d",*/
  ps5.LStickX(),
  ps5.LStickY(),
  ps5.RStickX(),
  ps5.RStickY(),
  ps5.Left(),
  ps5.Right(),
  ps5.Down(),
  ps5.Up(),
  ps5.Square(),
  ps5.Cross(),
  ps5.Circle(),
  ps5.Triangle(),
  ps5.L1(),
  ps5.R1(),
  ps5.L2(),
  ps5.R2(),
  ps5.Share(),
  ps5.Options(),
  ps5.PSButton(),
  ps5.Touchpad(),
  ps5.Charging(),
  ps5.Audio(),
  ps5.Mic(),
  ps5.Battery(); 
}
  
  //Only needed to print the message properly on serial monitor. Else we dont need it.
  /*if (millis() - lastTimeStamp > 50)
  {
    Serial.println(messageString);
    lastTimeStamp = millis();
  }
} */


void onConnect()
{
  Serial.println("Connected!.");
}


void onDisConnect()
{
  Serial.println("Disconnected!.");    
}



const int TOTAL_TRACKS = 41; 


void playRandomTrack() {
    // 1. Get a true random number using ESP32's hardware RNG
    // esp_random() returns a 32-bit unsigned int (0 to 4,294,967,295)
    uint32_t rng_val = esp_random();
    
    // 2. Map the RNG value to your track range (e.g., 1 to TOTAL_TRACKS)
    int track_index = (rng_val % TOTAL_TRACKS) + 1;
    
    // 3. Construct the filename (e.g., "/track_1.mp3")
    String filename = "/track_" + String(track_index) + ".WAV";
    
    Serial.print("RNG Value: "); Serial.println(rng_val);
    Serial.print("Playing: "); Serial.println(filename);
    
    // 4. Play the file
    audio.connecttoFS(SD, filename.c_str());
}


void setup() {
  //Attach servos
  myServoY.attach(12);
  myServoO.attach(13);
  myServoP.attach(14);
  myServoB.attach(15);


  myServoY.write(90);
  myServoO.write(90);
  myServoP.write(90);
  myServoB.write(90);


  myServoY.setPeriodHertz(50);      // Standard 50hz servo
  myServoO.setPeriodHertz(50);      // Standard 50hz servo
  myServoP.setPeriodHertz(330);      // Standard 50hz servo
  myServoB.setPeriodHertz(200);      // Standard 50hz servo
  


  //Set PS3 controller
  /*Ps3.attach(notify);
  Ps3.attachOnConnect(onConnect);
  Ps3.begin("a0:5a:5b:3f:3f:dc");


  BP32.setup(&onConnectedController, &onDisconnectedController);
  */


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


  //Initialize SPI bus for microSD Card;
  
  //Start Serial Port
  Serial.begin(115200);
  /*SDCardInit();
    i2s_driver_install(i2s_num, &i2s_config, 0, NULL);
    i2s_set_pin(i2s_num, &pin_config);
    //Get the wav file from the SD card
    WavFile = SD.open("/wavfile.wav");
    if(WavFile==false)
      Serial.println("Could not open 'wavfile,wav'");
    else
    {
     WavFile.read((byte *) &WavHeader,44);


     DumpWAVHeader(&WavHeader);
     if(ValidWavData(&WavHeader))
     {
        i2s_set_sample_rates(i2s_num, WavHeader.SampleRate);
     }
    }
    */
  SPI.begin(SPI_SCK, SPI_MISO, SPI_MOSI);
  if(!SD.begin(SD_CS))
  {
    Serial.println("SD Card Mount Failed!");
    return;
  }
  Serial.println("SD Card Mounted");


  ps5.attach(notify);
  ps5.attachOnConnect(onConnect);
  ps5.attachOnDisconnect(onDisConnect);
  ps5.begin("4c:b9:9b:f1:00:ef");  //your PS5 controller mac address 
  while (ps5.isConnected() == false) 
  { 
    Serial.println("PS5 controller not found");
    delay(300);
  }
  Serial.println("Ready.");


  //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(21);


  //Open Audio file;
  //audio.connecttoFS(SD,"")


}




void loop() {
  // put your main code here, to run repeatedly:


  /*if(Ps3.isConnected()){


        if( Ps3.data.button.cross ){
            Serial.println("Pressing the cross button");
        }


        if( Ps3.data.button.square ){
            Serial.println("Pressing the square button");
        }


        if( Ps3.data.button.triangle ){
            Serial.println("Pressing the triangle button");
        }


        if( Ps3.data.button.circle ){
            Serial.println("Pressing the circle button"); */
   while (ps5.isConnected() == true) {
    if(ps5.Cross())
    {
      /*Serial.println(esp_random(1,42));
      int myRandomNumber = (esp_random() % 41) + 1;
      audio.connecttoFS(SD,"myRandomNumber.WAV");
      delay(500); */
      playRandomTrack();
    }
    if(ps5.Square())
    {
      audio.connecttoFS(SD, "40.WAV");
      delay(500);
    }
    if(ps5.Circle())
    {
      audio.connecttoFS(SD, "41.WAV");
      delay(500);
    }
    if(ps5.Triangle())
    {
      myServoY.write(90);
      myServoO.write(90);
      myServoP.write(90);
      myServoB.write(90);
    }
   /* val = analogRead(ps5.LStickX());
    val = map(val, 0, ADC_Max, 0, 180);
    myServoY.write(val);


    val = analogRead(ps5.LStickY());
    val = map(val, 0, ADC_Max, 0, 180);
    myServoO.write(val);


    val = analogRead(ps5.RStickX());
    val = (map(val, 0, ADC_Max, 0, 180);
    myServoP.write(val);


    val = analogRead(ps5.RStickY());
    val = map(val, 0, ADC_Max, 0, 180);
    myServoB.write(val); */
    int xValue1 = ps5.LStickX();
    int angle1 = map(xValue1, -128, 127, 0, 180);
    myServoY.write(angle1);
    delay(15);
    int yValue1 = ps5.LStickY();
    int angle2 = map(yValue1, -128, 127, 0, 180);
    myServoO.write(angle2);
    delay(15);
    int xValue2 = ps5.RStickX();
    int angle3 = map(xValue2, -128, 127, 0, 180);
    myServoP.write(angle3);
    delay(15);
    int yValue2 = ps5.RStickY();
    int angle4 = map(yValue2, -128, 127, 0, 180);
    myServoB.write(angle4);
    delay(15);


   }
    
    
      
}

1

u/gm310509 18d ago

Unfortunately I am not going to research each of those libraries to find out what they do (assuming I even could find the exact same ones that you are using) and try to figure out what your program is doing....

.... But I will hazard a guess that the answer is most of them.

You need to work out what libraries you actually need and include just those headers files that pertain to that library. Usually there is just one or two and they will include th le needed dependencies.

By listing that many, all you are probably doing is just slowing down the compilation process because the compiler has to examine all of that, including any files that the ones you have listed include and figure out what it relevant and what is not.

But assuming everything else is correct, the compiler will likely be able to manage that process and produce the "correct" result. Note that "correct" means a program that does what you told it to do - which is absolutely definitely not necessarily the same as what you want it to do, unless your instructions are aligned with what you want.

To use an analogy you have given someone a very large stack of paper and told them to find the page with the heading that says "XYZ". You know that that page is right in the middle, but you don't tell them that, you just give them the whole gigantic stack and expect them to figure it out. That is what you are doing by listing all of those include files. The job can still be done, it is just requires more effort.

1

u/Cosplay_Pappy 18d ago

You don’t need to be rude. I’m new to this, and thought I’d ask for help. Most of these popped up when I tried to include ONE library and it brought its buddies along with it. I don’t know how many of them are actually needed.

I know I forgot to mention what it’s supposed to do, and for that, I am sorry. It’s supposed to connect with a ps5 controller, and use its chosen inputs to control four servos, and play a randomly selected sound or a preselected sound from an SD card.

1

u/gm310509 18d ago

I'm sorry that you feel I am being rude. Also I don't understand why you would feel that way.

Perhaps if you could clarify where you feel I am being rude I can explain that part more clearly.

But for now, you have provided some code. I don't know what it does and I don't have spare time to read through it to figure it out. I did note that there are a lot of includes and that that is unusual, and likely unnecessary. As a result the answer to your question is that you could probably remove most of them.

I also went on to explain how the compiler works and tried to use an analogy as to share why all those includes just creates overheads.

I'm sorry that you feel I was being rude. That was not my intent.

But since you do feel that way, hopefully someone else will help you.

1

u/Cosplay_Pappy 17d ago

The last paragraph in your previous comment came off as a bit condescending to me. I apologize since you didn’t mean it that way. I clearly misread the tone.

I did add what the code does in my previous comment, but I’ll restate it here with a bit more detail. The code is for a regular esp32 to connect with a ps5 controller over Bluetooth. It then takes specific inputs from the controller (cross, square, and circle buttons and analog sticks) and plays either a random audio from a list on a connected SD card (cross button) or a preselected audio (square and circle buttons). The analog stick inputs control four servos that are controlling what is essentially a robot arm with no grip.

I hope this helps, and I’m sorry again for misunderstanding your tone. Thank you!

1

u/gm310509 16d ago

No worries, sometimes it is difficult to communicate effectively in a forum like this. Everybody is different and has different experience levels and current state of mind and interpret things differently.

With that in mind, the following is about trying to share with you the magnitude of the task you are requesting - while it might come across badly, it is not intended that way it is intended to share with you the effort required to pick up somebody elses code, understand it (beyond you are doing some PS5 stuff) and make suggestions.

I spent about 10 minutes skimming through your code, I noticed one thing - which i mention below. To check what I am about to say, I had to extract your code (thanks for posting it as text BTW, it made it much easier - many people just post screen shots and it is much harder to do the following). All of this took the 10 minutes - and does not include the time to report just this one thing back to you.

So, the one thing is, I noted you do a sprintf into messageString at line 131 in the notify function. But, I didn't see that you are doing anything with it (i.e. not printing it).

I further noticed that you commented out the declaration of messageString in the notify function and thought, "Oh, maybe you are declaring it as a global variable and using it somewhere else". This is when I needed to copy the code out into a proper editor so I could check for all the occurrences of messageString. As I suspected, you are using it at line 161 in a "improperly declared partial function" in a Serial.println().

Upon further investigation, it appears that your commenting out of the messageString also commented out the first line of the sprintf, but left the remaining parameters as executeable code starting with the ps5.LStickX(), line - which presumably is meant to be the first value to be passed to the sprintf control string (which is commented out).

Following the sprintf is a closing brace which ends the notify function.

But following the closing brace, there is a commented out if statement (containing the Serial.println). If uncommented, this block of code would be outside of any function declaration and thus not valid (it would likely cause a mismatched brace error if it was uncommented.

So as a result what you are trying to do with just this one line of code seems very confusing to me. The fact that you are doing some PS/5 stuff doesn't help clarify whatever it is that you are intending to do with the partially commented out sprintf and the following commented out print statement that is outside of a valid function declaration.

So, all of that time to try to follow what is going on with that one variable, working out what is commented out and what isn't, identifying that there is a partial set of executable code following the sprintf that looks like it should be part of the sprintf and not still executebale takes a lot of effort.

A single include file could contain and references hundreds or even thousands of lines of code. Plus without knowing exactly which library you are using, I might not even be looking at the same one you have (the names of files in a library can be reused - and often are - in different versions of similar libraries and thus have different code).

So, to go through it all in any detail, as I mentioned is a huge ask and the one thing that I did comment on (and remember the 10 minutes I spent trying to figure out what was going on with just that one variable) did not include the time it took to write this reply.

As to your original question, you need to work out why you felt the need to include the individual files. If you are unsure, try starting out with a minimal version of your code and work out the absolute minimum number of files to include - as I mentioned there is likely one or two "top level" files you need to include.

By way of example, if you have the IRRemote library installed on your PC (I gave the github link in case you don't have it) you will see that it has lots of includeable files. But you don't include them all - you just include one of the one top level ones as described in the usage section. That file determines what other stuff (if anything) needs to be included.

Reading the documentation of the libraries you are trying to use is important as is refering to the examples.

Maybe, just maybe, you do actually need all of those files, but I suspect that you can remove most of them but you need to identify the main ones.

All thebest with it.

1

u/Cosplay_Pappy 16d ago

Thank you so much for your time! I was finally able to get the SD card to mount, but I’m not sure what I did to fix it. I’ve been fixing/ altering code all day today. Most of what is commented out can be deleted, but I held onto it so I could see my process. I looked at the libraries again, and the massive chunk of them at the top weren’t needed as they were for a different board (esp8266?). I have gotten it to compile and upload, but now my controller won’t connect, so I’m working on that. I’m using Google’s AI to get an idea of what to do with mixed, but mostly positive, results. It doesn’t have my entire code, though.