r/esp32projects • • 19d ago

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

4 comments sorted by

1

u/Boulder_Tech 19d ago

Without seeing the code file, there is no way to help.

What do you expect ??

1

u/Cosplay_Pappy 19d 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/Particular_Simple560 19d ago

Are you loading anything into psram?

1

u/Cosplay_Pappy 16d ago

I think so. I activated it within the code. I had to scrap the code, though, as it would not have worked with my ps5 controller. I'm working on my original, semi-working code. I'll post that code here, as I'm sure the amount of libraries isn't helping with the lack of space on the chip. It says that it lacks the space to read the SD card.

#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);


   }
    
    
      
}