Does this void setup look right?

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.

1 Like

setup() and loop()

1 Like

Here:

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

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.

Please post the current code giving the error.

I will do thanks but later i will try clean it up the code a bit and see what problems persists first.

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

The startCameraServer() function is missing from the code.

This is the new code

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

This error comes up when I try to compile

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

It is one thing to declare a function and another to define it.
The startCameraServer() function is declared but not defined.

void my_function();

declares the function (It tells the compiler that my_function() exists but that it is defined further down in the code).

void my_function() { 
//statements to do something inside the function
}

defines the function

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.

#include "esp_camera.h"
#include <WiFi.h>

first of all you should always post your most actual and complete sketch.

Then adjust the arduino-IDE to get verbose compiler-log output

If the verbose compiler-log exceeds 120000 characters paste the log into a textfile and attach the textfile to a posting.

It is very likely that you have to install the libraries with the library manager of the arduino-IDE

did you install them?
the IDE doesn't install with every available library

1 Like

Googling around a bit I found this:

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.

Where did you get the code you are using?

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

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