I'm new to using C++ but I'm trying to tinker with a esp32 cam using a sample code.
I'm pretty sure having UART driver problems aswell but also I'm getting the following compile errors from the sample code.
exit status 1
Compilation error: redefinition of 'void setup()'
The void setup code looks blank then outside the void setup looks like what should be setup code. Am I wrong?
here is the code I'm trying to compile.
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
#include "esp_camera.h"
#include <WiFi.h>
// Replace with your network credentials
const char* ssid = "NetComm 2297 5G";
const char* password = "XnYwfWBSB38Jq69Y";
// Select the camera model
#define CAMERA_MODEL_AI_THINKER
// Camera pin definitions
#if defined(CAMERA_MODEL_AI_THINKER)
#define PWDN_GPIO_NUM -1
#define RESET_GPIO_NUM -1
#define XCLK_GPIO_NUM 0
#define SIOD_GPIO_NUM 26
#define SIOC_GPIO_NUM 27
#define Y9_GPIO_NUM 35
#define Y8_GPIO_NUM 34
#define Y7_GPIO_NUM 39
#define Y6_GPIO_NUM 36
#define Y5_GPIO_NUM 21
#define Y4_GPIO_NUM 19
#define Y3_GPIO_NUM 18
#define Y2_GPIO_NUM 5
#define VSYNC_GPIO_NUM 25
#define HREF_GPIO_NUM 23
#define PCLK_GPIO_NUM 22
#endif
void startCameraServer();
void setup() {
Serial.begin(115200);
Serial.setDebugOutput(true);
Serial.println();
// Connect to Wi-Fi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
// Print the IP address
Serial.println(WiFi.localIP());
// Configure camera settings
camera_config_t config;
config.ledc_channel = LEDC_CHANNEL_0;
config.ledc_timer = LEDC_TIMER_0;
config.pin_d0 = Y2_GPIO_NUM;
config.pin_d1 = Y3_GPIO_NUM;
config.pin_d2 = Y4_GPIO_NUM;
config.pin_d3 = Y5_GPIO_NUM;
config.pin_d4 = Y6_GPIO_NUM;
config.pin_d5 = Y7_GPIO_NUM;
config.pin_d6 = Y8_GPIO_NUM;
config.pin_d7 = Y9_GPIO_NUM;
config.pin_xclk = XCLK_GPIO_NUM;
config.pin_pclk = PCLK_GPIO_NUM;
config.pin_vsync = VSYNC_GPIO_NUM;
config.pin_href = HREF_GPIO_NUM;
config.pin_sscb_sda = SIOD_GPIO_NUM;
config.pin_sscb_scl = SIOC_GPIO_NUM;
config.pin_pwdn = PWDN_GPIO_NUM;
config.pin_reset = RESET_GPIO_NUM;
config.xclk_freq_hz = 20000000;
config.pixel_format = PIXFORMAT_JPEG;
// Initialize camera
if (psramFound()) {
config.frame_size = FRAMESIZE_UXGA;
config.jpeg_quality = 10;
config.fb_count = 2;
} else {
config.frame_size = FRAMESIZE_SVGA;
config.jpeg_quality = 12;
config.fb_count = 1;
}
// Camera init
esp_err_t err = esp_camera_init(&config);
if (err != ESP_OK) {
Serial.printf("Camera init failed with error 0x%x", err);
return;
}
// Start the camera server
startCameraServer();
Serial.println("Camera ready! Use 'http://' + IP_ADDRESS + '/stream' to view the stream.");
}
void loop() {
delay(1);
}
Welcome to the forums! +1 for using code tags with your code. You are ahead of the curve.
You can not have two functions called setup() and void()
It appears you opened a blank sketch that contains just setup() and void() and then pasted a new sketch (that you found on the internet?) after that? Get rid if those two functions at the top of the sketch.
Y I thought that might be a problem so I got rid of stuff off the top but now I'm getting other problems that I should try a fix myself before asking the community again thanks.
You likely have some non-matching {}. Maybe an autoformat ctrl-T would help identify the mismatch. But we can't tell since you didn't post the new code.
I think it might be looking for these program files
#include "esp_camera.h"
#include <WiFi.h>
I'm getting this now
c:/users/lotso/appdata/local/arduino15/packages/esp32/tools/s3-gcc/2021r2-p5/bin/../lib/gcc/xtensa-esp32s3-elf/8.4.0/../../../../xtensa-esp32s3-elf/bin/ld.exe: C:\Users\lotso\AppData\Local\arduino\sketches\E69EBF1440CD359F0442D43D409545F7\sketch\esp32_camera_code.ino.cpp.o: in function `setup()':
C:\Users\lotso\OneDrive\Documents\Arduino\esp32_camera_code/esp32_camera_code.ino:81: undefined reference to `startCameraServer()'
collect2.exe: error: ld returned 1 exit status
exit status 1
Compilation error: exit status 1
c:/users/lotso/appdata/local/arduino15/packages/esp32/tools/s3-gcc/2021r2-p5/bin/../lib/gcc/xtensa-esp32s3-elf/8.4.0/../../../../xtensa-esp32s3-elf/bin/ld.exe: C:\Users\lotso\AppData\Local\arduino\sketches\E69EBF1440CD359F0442D43D409545F7\sketch\esp32_camera_code.ino.cpp.o:(.literal._Z5setupv+0x2c): undefined reference to `startCameraServer()'
c:/users/lotso/appdata/local/arduino15/packages/esp32/tools/s3-gcc/2021r2-p5/bin/../lib/gcc/xtensa-esp32s3-elf/8.4.0/../../../../xtensa-esp32s3-elf/bin/ld.exe: C:\Users\lotso\AppData\Local\arduino\sketches\E69EBF1440CD359F0442D43D409545F7\sketch\esp32_camera_code.ino.cpp.o: in function `setup()':
C:\Users\lotso\OneDrive\Documents\Arduino\esp32_camera_code/esp32_camera_code.ino:81: undefined reference to `startCameraServer()'
collect2.exe: error: ld returned 1 exit status
exit status 1
Compilation error: exit status 1
Are the two include lines looking for file in my library?
I can't find these files in the manage libraries
Can my_function() be defined by code in an additional library?
Is these include lines library files that need to be added to a directory?
I ran a search in the IDE and it never came up in the results.
It is in a separate file within the library's example, so if you were trying to use it, it would need to be within a separate file in your sketch.
Your code has this template line so the compilation doesn't fail when processing this particular file, but the linker expects that the function is actually defined somewhere in the code you supply.
I had this same problem recently with the 'CameraWebServer' example project (C:\Users\Frank\Documents\Arduino\Libraries\arduino-esp32-master\libraries\ESP32\examples\Camera\CameraWebServer). The problem arises if the 'app_httpd.cpp' source file that contains the definition for 'startCameraServer()' and 'setupLedFlash(int pin)' isn't in the compile/link set for the project. I use MS Visual Studio 2022 with Visual Micro for my Arduino projects, so for me the solution was to simply add app_httpd.cpp to the project (right click on project name in Solution Explorer ->Add -> Existing Item -> app_httpd.cpp). After doing that everything compiled and ran fine