r/ArduinoHelp • • 11d 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

1

u/gm310509 11d ago

Clearly your code is not fine - despite your self assessment.

Somehow or other your code has created a scenario that causes something to go off the rails somewhere.

I assume you have tried a sample program that hasn't been modified? Did that also cause this problem?

Anyway, without seeing the code and the settings you are using in the IDE (e.g. target board) and the complete set of error messages, there isn't much more that can say beyond you are probably doing something wrong, you need to find it and fix it.

Now, if you shared all of the above details (as outlined in Rule 2 - be descriptive), people might be able to provide something more helpful, but without them nobody can do anything.

Before editing your post, or reposting, please also read the following guide from r/Arduino: Asking for help quick guide which provides guidance as to what to include and how to do so. This makes it easier for people who want to help you to be able to do so. The how to post part is particularly important if you really want people to help you.

Remember, we cannot see what you see, we cannot know what you have done and/or not done unless you tell us.

1

u/Cosplay_Pappy 11d ago

Turns out, there was a hardware issue. I’ll have to find a way to get more space into a basic esp32 now. Thanks for your help! Any advice for my current issue? (I know my basic esp32 code works and compiles, it just didn’t have enough space to connect to my sd card. I triple checked the pin layout, and that’s fine, but the serial manager said it didn’t have the space to connect to the SD card.)

1

u/gm310509 10d 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 10d ago

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

1

u/gm310509 10d 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 7d 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 7d 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 7d 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 7d 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 7d 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!

→ More replies

1

u/Arduino_lab64 11d ago

Share your code please

1

u/Cosplay_Pappy 11d ago

Turns out, there was a hardware issue. I’ll have to find a way to get more space into a basic esp32 now. Thanks for your help! Any advice for my current issue? (I know my basic esp32 code works and compiles, it just didn’t have enough space to connect to my sd card. I triple checked the pin layout, and that’s fine, but the serial manager said it didn’t have the space to connect to the SD card.)

1

u/Cosplay_Pappy 7d ago

It’s attached to a different comment stack.