ESP32 upload error

Hi, new to this forum so I hope the topic(s) are correct.
Brief history.
I am using an ESP32 epsy WROOM devkit and the Arduino Cloud based CLI.
The project has tree ".ino' files that appear to 'chain load' when uploading !
A week ago, I had struggled but successfully uploaded this code and got the project to function correctly - ie ALL three '.ino files were uploaded correctly.
I now would like to change some of the upload code but it would not load !
I then went back to the original code to attempt an upload.
This failed badly with LOTS of errors, that were not there a week ago.
I cannot even verify the original '.ino' file
I then attempted to upload an example that was offered in the template area.
This then failed as well - I could upload some of the error if needed.
Has something change with the cloud process, or am I doing something wrong.
Thanks for any help,
Dennis

Ok, more info.
Even though the example was listed under ESP32, it shows a layout file showing an Arduino UNO !
Is this the cause of the error ?

Hi @wizardgm.

Because many Arduino sketches consist of only a single .ino file, it is easy to get the impression that the .ino file is the sketch. However, this is not the case. It is the folder that is the sketch. All .ino files in the folder are part of the same program. They are concatenated before being compiled as C++ code.

Please post the full and exact text of the errors in a reply here on this forum thread.

Thanks for the quick reply, I think this is what I considered as 'Chaining'

Attached here are the beginning of the code and the errors.
Code,

#include <WebServer.h>

// Pins used
// Controller value analog pin (potentiometer)
const int iControllerPin = 34;
const int iBrakePin = 35;

// Pins used to control the motor output
const int iFwdPowerPin = 32;
const int iPowerOnPin = 33;

// Values read in from controls
int iControllerValue = 0;  // value read from the controller pot
int iLastControllerValue = 0;
int iControllerReadValue = 0;

// Values used in code
bool bWebServerRunning = false;  // If webserver is running
int iLoopIterations = 0;         // Count times we have looped

// Webserver if used
WebServer server(80);

const int iPWMChannel = 0;
const int iPWMResolution = 8;

// the setup routine runs once when you press reset:
void setup() {
#if defined(__DEBUG__) || defined(__DEBUG_VALUES__)
  Serial.begin(115200);
#endif

  // Read the preferences
  void getPreferences();
    Preferences controllerPrefs;

  controllerPrefs.begin("controlPrefs", true);
  iPWMFrequency = controllerPrefs.getInt("sPWMFreq", __DEF_PWM_FREQUENCY__);
  iBrakeSetting = controllerPrefs.getInt("sBrake", __DEF_BRAKE_SETTING__);
  iThrottleSetting = controllerPrefs.getInt("sThrottle", __DEF_THROTTLE_SETTING__);
  iTCSSetting = controllerPrefs.getInt("sTCS", __DEF_TCS_SETTING__);
  iTCSStartSetting = controllerPrefs.getInt("sTCSStart", __DEF_TCS_START_SETTING__);
  iTCSStopSetting = controllerPrefs.getInt("sTCSStop", __DEF_TCS_STOP_SETTING__);
  iCoastSetting = controllerPrefs.getInt("sCoast", __DEF_COAST_SETTING__);
  fCurveVal = controllerPrefs.getFloat("sCurveVal", __DEF_CURVEVAL__);

  controllerPrefs.end();

errors from console window:

/usr/local/bin/arduino-cli compile --fqbn esp32:esp32:uPesy_wroom:UploadSpeed=921600,CPUFreq=240,FlashFreq=80,FlashMode=qio,PartitionScheme=default,DebugLevel=none,EraseFlash=none --build-cache-path /tmp --output-dir /tmp/3611491496/build --build-path /tmp/arduino-build-44C91B867A3EA40E2A730B87FAAA3472  /tmp/3611491496/slot-controllerV3

/tmp/3611491496/slot-controllerV3/slot-controllerV3.ino: In function 'void setup()':
/tmp/3611491496/slot-controllerV3/slot-controllerV3.ino:68:5: error: 'Preferences' was not declared in this scope
     Preferences controllerPrefs;
     ^~~~~~~~~~~
/tmp/3611491496/slot-controllerV3/slot-controllerV3.ino:68:5: note: suggested alternative: 'getPreferences'
     Preferences controllerPrefs;
     ^~~~~~~~~~~
     getPreferences
/tmp/3611491496/slot-controllerV3/slot-controllerV3.ino:70:3: error: 'controllerPrefs' was not declared in this scope
   controllerPrefs.begin("controlPrefs", true);
   ^~~~~~~~~~~~~~~
/tmp/3611491496/slot-controllerV3/slot-controllerV3.ino:70:3: note: suggested alternative: 'iControllerPin'
   controllerPrefs.begin("controlPrefs", true);
   ^~~~~~~~~~~~~~~
   iControllerPin
Multiple libraries were found for "WiFi.h"
  Used: /home/builder/.arduino15/packages/esp32/hardware/esp32/2.0.17/libraries/WiFi
  Not used: /home/builder/opt/libraries/vega_wifinina_1_0_1
  Not used: /home/builder/opt/libraries/wifinina_1_8_14
  Not used: /home/builder/opt/libraries/wifi_1_2_7
  Not used: /home/builder/opt/libraries/seeed_arduino_rpcwifi_1_1_0
  Not used: /home/builder/opt/libraries/wifiespat_1_4_4
  Not used: /home/builder/opt/libraries/indhilib_3_0_5
  Not used: /home/builder/opt/libraries/da16200_wi_fi_library_for_arduino_1_1_0
  Not used: /home/builder/opt/libraries/nina_wi_fi_1_0_1
  Not used: /home/builder/opt/libraries/betterwifinina_1_3_0
Multiple libraries were found for "Preferences.h"
  Used: /home/builder/.arduino15/packages/esp32/hardware/esp32/2.0.17/libraries/Preferences
  Not used: /home/builder/opt/libraries/preferences_2_1_0
Multiple libraries were found for "WebServer.h"
  Used: /home/builder/.arduino15/packages/esp32/hardware/esp32/2.0.17/libraries/WebServer
  Not used: /home/builder/opt/libraries/seeed_arduino_rpcwifi_1_1_0
Error during build: exit status 1

This was after I deleted the sketch and created it anew as I was thinking the files may have been corrupt.

This code is for an electronic slot car controller, which I have working but would like to now modify.

Once again, thanks for your time to look at this.

Dennis

The cause of the problem is that you don't have an #include directive for the Preferences.h header file before you reference the Preferences class that is declared in that header.

So you should be able to fix the error by adding this line at the top of the sketch file:

#include <Preferences.h>

From this part of the output:

I can see that you do have an #include directive for Preferences.h somewhere in your sketch code. My guess is it is present in one of the other .ino file of the sketch.

When a sketch contains multiple .ino files, they are concatenated together into a single file by the sketch preprocessor, in this order:

  1. The file with name matching the sketch folder.
  2. Each additional file in alphabetical order.

It might be that the problem began after you renamed the sketch files and thus caused the concatenation order to change. For example, let's say I had this sketch:

Foo/
├── Bar.ino
└── Foo.ino

Bar.ino

Preferences controllerPrefs;
void setup() {}
void loop() {}

Foo.ino

#include <Preferences.h>

This sketch will be concatenated into the following source file (with the contents of Foo.ino coming first because it matches the sketch folder name Foo):

#include <Preferences.h>
Preferences controllerPrefs;
void setup() {}
void loop() {}

It will compile fine because the #include directive comes before the Preferences reference in the code.

But then if you changed the sketch folder name from Foo to Bar:

Bar/
├── Bar.ino
└── Foo.ino

the code will now be concatenated like this:

Preferences controllerPrefs;
void setup() {}
void loop() {}
#include <Preferences.h>

Compilation will now fail with a "'Preferences' was not declared in this scope" error because now the #include directive comes after the reference to Preferences in the code.

Thanks for the reply and the way you explained the error.
I have now deleted the sketch and recreated it along the lines of how you suggested and it now verifies without any error.
Thanks again.
Dennis
Consider this topic closed.

You are welcome. I'm glad it is working now.

Regards,
Per

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.