Totally new to this. I'm trying to upload a very simple sketch to my arduino and I keep getting an error. It says "redefinition of void setup". I have a more detailed project in mind but I cant seem to get past this error. Hoping somebody can point me in the right direction.
Each Arduino sketch can only have one setup() and one loop() function. If you try to copy two Arduino programs into a single sketch, without merging the programs you will get this error. If you do a Google search for "merge arduino sketch", you'll get a ton of information on how to do this.
If that doesn't solve the problem for you (there are other potential causes of this error), then please post your full sketch in a reply here and we'll take a look.
Thank you for the reply. Ive been following along through youtube videos trying to learn how to set up to operate a relay module. All good until I tried uploading. Here's what Ive got.
/*
-- New project --
This source code of graphical user interface
has been generated automatically by RemoteXY editor.
To compile this code using RemoteXY library 2.4.3 or later version
download by link RemoteXY library download page
To connect using RemoteXY mobile app by link Mobile App
- for ANDROID 4.5.1 or later version;
- for iOS 1.4.1 or later version;
This source code is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
*/
//////////////////////////////////////////////
// RemoteXY include library //
//////////////////////////////////////////////
// RemoteXY select connection mode and include library
#define REMOTEXY_MODE__ESP8266_HARDSERIAL_POINT
#include <RemoteXY.h>
// RemoteXY connection settings
#define REMOTEXY_SERIAL Serial
#define REMOTEXY_SERIAL_SPEED 115200
#define REMOTEXY_WIFI_SSID "RemoteXY"
#define REMOTEXY_WIFI_PASSWORD "shreddie"
#define REMOTEXY_SERVER_PORT 6377
// RemoteXY configurate
#pragma pack(push, 1)
uint8_t RemoteXY_CONF[] =
{ 255,1,0,0,0,20,0,10,13,0,
2,0,1,1,22,11,2,26,31,31,
79,78,0,79,70,70,0 };
// this structure defines all the variables and events of your control interface
struct {
// input variables
uint8_t switch_1; // =1 if switch ON and =0 if OFF
// other variable
uint8_t connect_flag; // =1 if wire connected, else =0
} RemoteXY;
#pragma pack(pop)
/////////////////////////////////////////////
// END RemoteXY include //
/////////////////////////////////////////////
#define PIN_SWITCH_1 13
void setup()
{
RemoteXY_Init ();
pinMode (PIN_SWITCH_1, OUTPUT);
// TODO you setup code
}
void loop()
{
RemoteXY_Handler ();
digitalWrite(PIN_SWITCH_1, (RemoteXY.switch_1==0)?LOW:HIGH);
// TODO you loop code
// use the RemoteXY structure for data transfer
// do not call delay()
}
Please do this:
- When you encounter an error, you'll see a button on the right side of the orange bar "Copy error messages" in the Arduino IDE (or the icon that looks like two pieces of paper at the top right corner of the black console window in the Arduino Web Editor). Click that button..
- In a forum reply here, click on the reply field.
- Click the </> button on the forum toolbar. This will add the forum's code tags markup to your reply.
- Press "Ctrl + V". This will paste the error between the code tags.
- Move the cursor outside of the code tags before you add any additional text to your reply.
If the text exceeds the forum's 9000 character limit, save it to a .txt file and post it as an attachment. If you click the "Reply" button here, you will see an "Attachments and other settings" link that will allow you to make the attachment.
Arduino: 1.8.12 (Windows 10), Board: "Arduino Uno"
C:\Users\Evan Spencer\Documents\Arduino\sketch_jun06a\sketch_jun06c\sketch_jun06c\sketch_jun06c\sketch_jun06c\sketch_jun06c.ino: In function 'void setup()':
sketch_jun06c:64:6: error: redefinition of 'void setup()'
void setup()
^~~~~
C:\Users\Evan Spencer\Documents\Arduino\sketch_jun06a\sketch_jun06c\sketch_jun06c\sketch_jun06c\sketch_jun06c\sketch_jun06c.ino:1:6: note: 'void setup()' previously defined here
void setup() {
^~~~~
C:\Users\Evan Spencer\Documents\Arduino\sketch_jun06a\sketch_jun06c\sketch_jun06c\sketch_jun06c\sketch_jun06c\sketch_jun06c.ino: In function 'void loop()':
sketch_jun06c:87:6: error: redefinition of 'void loop()'
void loop() {
^~~~
C:\Users\Evan Spencer\Documents\Arduino\sketch_jun06a\sketch_jun06c\sketch_jun06c\sketch_jun06c\sketch_jun06c\sketch_jun06c.ino:74:6: note: 'void loop()' previously defined here
void loop()
^~~~
exit status 1
redefinition of 'void setup()'
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
The error message you posted indicates that the code you posted in your previous reply is not the same as the code you're compiling in the Arduino IDE.
Please do this:
- (in the Arduino IDE) Open your sketch.
- Edit > Copy for Forum
- In a forum reply here, click on the reply field.
- Press "Ctrl + V". This will paste the sketch that was open in the Arduino IDE.
void setup() {
// put your setup code here, to run once:
}/*
-- New project --
This source code of graphical user interface
has been generated automatically by RemoteXY editor.
To compile this code using RemoteXY library 2.4.3 or later version
download by link http://remotexy.com/en/library/
To connect using RemoteXY mobile app by link http://remotexy.com/en/download/
- for ANDROID 4.5.1 or later version;
- for iOS 1.4.1 or later version;
This source code is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
*/
//////////////////////////////////////////////
// RemoteXY include library //
//////////////////////////////////////////////
// RemoteXY select connection mode and include library
#define REMOTEXY_MODE__ESP8266_HARDSERIAL_POINT
#include <RemoteXY.h>
// RemoteXY connection settings
#define REMOTEXY_SERIAL Serial
#define REMOTEXY_SERIAL_SPEED 115200
#define REMOTEXY_WIFI_SSID "RemoteXY"
#define REMOTEXY_WIFI_PASSWORD "shreddie"
#define REMOTEXY_SERVER_PORT 6377
// RemoteXY configurate
#pragma pack(push, 1)
uint8_t RemoteXY_CONF[] =
{ 255,1,0,0,0,20,0,10,13,0,
2,0,1,1,22,11,2,26,31,31,
79,78,0,79,70,70,0 };
// this structure defines all the variables and events of your control interface
struct {
// input variables
uint8_t switch_1; // =1 if switch ON and =0 if OFF
// other variable
uint8_t connect_flag; // =1 if wire connected, else =0
} RemoteXY;
#pragma pack(pop)
/////////////////////////////////////////////
// END RemoteXY include //
/////////////////////////////////////////////
#define PIN_SWITCH_1 13
void setup()
{
RemoteXY_Init ();
pinMode (PIN_SWITCH_1, OUTPUT);
// TODO you setup code
}
void loop()
{
RemoteXY_Handler ();
digitalWrite(PIN_SWITCH_1, (RemoteXY.switch_1==0)?LOW:HIGH);
// TODO you loop code
// use the RemoteXY structure for data transfer
// do not call delay()
}
void loop() {
// put your main code here, to run repeatedly:
}
As I suspected. You have an extra definition of the setup() function at the top of your sketch. Change these lines:
void setup() {
// put your setup code here, to run once:
}/*
-- New project --
to:
/*
-- New project --
Problem solved!! Thanks so much for your help.
You're welcome. I'm glad to hear it's working now. Enjoy!
Per
C:\Users\Evan Spencer\Documents\Arduino\sketch_jun06a\
sketch_jun06c\sketch_jun06c\sketch_jun06c\sketch_jun06c\
sketch_jun06c.ino: In function 'void setup()':
You seem to have four extra layers of subdirectory in your sketch directory.