Arduino shows errors on a sketch, but not on another identical sketch

I have had this a few times, where I have two identical sketches - checked with the Notepad++ compare feature.

One gives an error (redfinition of ****) and the other compiles fine

Here are the two files, the 'erroneous' one first

#include <Wire.h>
#include <LiquidCrystal_PCF8574.h>
#define DCSBIOS_IRQ_SERIAL

#include <DcsBios.h>

LiquidCrystal_PCF8574 lcd0(0x27);  // set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_PCF8574 lcd1(0x26);
LiquidCrystal_PCF8574 lcd2(0x25);
int show;



void onCmscTxtJmrChange(char* newValue) {
lcd0.setCursor(0, 0);
lcd0.print(newValue);
}
DcsBios::StringBuffer<8> cmscTxtJmrBuffer(0x1096, onCmscTxtJmrChange);

void onCmscTxtChaffFlareChange(char* newValue) {
lcd1.setCursor(0, 0);
lcd1.print(newValue);
}
DcsBios::StringBuffer<8> cmscTxtChaffFlareBuffer(0x108e, onCmscTxtChaffFlareChange);

void onCmscTxtMwsChange(char* newValue) {
lcd2.setCursor(0, 0);
lcd2.print(newValue);
}
DcsBios::StringBuffer<8> cmscTxtMwsBuffer(0x12b0, onCmscTxtMwsChange);

void setup() {
  lcd0.begin(16, 2);
  lcd1.begin(16, 2);
  lcd2.begin(16, 2);
  DcsBios::setup();
  
}

void loop() {
  DcsBios::loop();
 lcd0.setBacklight(5);
 lcd1.setBacklight(5);
 lcd2.setBacklight(5);
}

and the working one

#include <Wire.h>
#include <LiquidCrystal_PCF8574.h>
#define DCSBIOS_IRQ_SERIAL

#include <DcsBios.h>

LiquidCrystal_PCF8574 lcd0(0x27);  // set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_PCF8574 lcd1(0x26);
LiquidCrystal_PCF8574 lcd2(0x25);
int show;



void onCmscTxtJmrChange(char* newValue) {
lcd0.setCursor(0, 0);
lcd0.print(newValue);
}
DcsBios::StringBuffer<8> cmscTxtJmrBuffer(0x1096, onCmscTxtJmrChange);

void onCmscTxtChaffFlareChange(char* newValue) {
lcd1.setCursor(0, 0);
lcd1.print(newValue);
}
DcsBios::StringBuffer<8> cmscTxtChaffFlareBuffer(0x108e, onCmscTxtChaffFlareChange);

void onCmscTxtMwsChange(char* newValue) {
lcd2.setCursor(0, 0);
lcd2.print(newValue);
}
DcsBios::StringBuffer<8> cmscTxtMwsBuffer(0x12b0, onCmscTxtMwsChange);

void setup() {
  lcd0.begin(16, 2);
  lcd1.begin(16, 2);
  lcd2.begin(16, 2);
  DcsBios::setup();
  
}

void loop() {
  DcsBios::loop();
 lcd0.setBacklight(5);
 lcd1.setBacklight(5);
 lcd2.setBacklight(5);
}

Here is the error code

F:\Users\LES\Documents\Arduino\CF8574_CMSC_3_LCD_plus_switches_encoders_LEDs_mstr_caution\Slave_PCF8574_CMSC_multiple_LCD.ino:7:27: error: redefinition of 'LiquidCrystal_PCF8574 lcd0'
 LiquidCrystal_PCF8574 lcd0(0x27);  // set the LCD address to 0x27 for a 16 chars and 2 line display
                           ^
F:\Users\LES\Documents\Arduino\CF8574_CMSC_3_LCD_plus_switches_encoders_LEDs_mstr_caution\CF8574_CMSC_3_LCD_plus_switches_encoders_LEDs_mstr_caution.ino:12:23: note: 'LiquidCrystal_PCF8574 lcd0' previously declared here
 LiquidCrystal_PCF8574 lcd0(0x27);  // set the LCD address to 0x27 for a 16 chars and 2 line display
                       ^~~~
F:\Users\LES\Documents\Arduino\CF8574_CMSC_3_LCD_plus_switches_encoders_LEDs_mstr_caution\Slave_PCF8574_CMSC_multiple_LCD.ino:8:27: error: redefinition of 'LiquidCrystal_PCF8574 lcd1'
 LiquidCrystal_PCF8574 lcd1(0x26);
                           ^
F:\Users\LES\Documents\Arduino\CF8574_CMSC_3_LCD_plus_switches_encoders_LEDs_mstr_caution\CF8574_CMSC_3_LCD_plus_switches_encoders_LEDs_mstr_caution.ino:13:23: note: 'LiquidCrystal_PCF8574 lcd1' previously declared here
 LiquidCrystal_PCF8574 lcd1(0x23);
                       ^~~~
F:\Users\LES\Documents\Arduino\CF8574_CMSC_3_LCD_plus_switches_encoders_LEDs_mstr_caution\Slave_PCF8574_CMSC_multiple_LCD.ino:9:27: error: redefinition of 'LiquidCrystal_PCF8574 lcd2'
 LiquidCrystal_PCF8574 lcd2(0x25);
                           ^
F:\Users\LES\Documents\Arduino\CF8574_CMSC_3_LCD_plus_switches_encoders_LEDs_mstr_caution\CF8574_CMSC_3_LCD_plus_switches_encoders_LEDs_mstr_caution.ino:14:23: note: 'LiquidCrystal_PCF8574 lcd2' previously declared here
 LiquidCrystal_PCF8574 lcd2(0x25);
                       ^~~~
F:\Users\LES\Documents\Arduino\CF8574_CMSC_3_LCD_plus_switches_encoders_LEDs_mstr_caution\Slave_PCF8574_CMSC_multiple_LCD.ino:10:5: error: redefinition of 'int show'
 int show;
     ^~~~
F:\Users\LES\Documents\Arduino\CF8574_CMSC_3_LCD_plus_switches_encoders_LEDs_mstr_caution\CF8574_CMSC_3_LCD_plus_switches_encoders_LEDs_mstr_caution.ino:15:5: note: 'int show' previously declared here
 int show;
     ^~~~
F:\Users\LES\Documents\Arduino\CF8574_CMSC_3_LCD_plus_switches_encoders_LEDs_mstr_caution\Slave_PCF8574_CMSC_multiple_LCD.ino: In function 'void onCmscTxtJmrChange(char*)':
F:\Users\LES\Documents\Arduino\CF8574_CMSC_3_LCD_plus_switches_encoders_LEDs_mstr_caution\Slave_PCF8574_CMSC_multiple_LCD.ino:14:6: error: redefinition of 'void onCmscTxtJmrChange(char*)'
 void onCmscTxtJmrChange(char* newValue) {
      ^~~~~~~~~~~~~~~~~~
F:\Users\LES\Documents\Arduino\CF8574_CMSC_3_LCD_plus_switches_encoders_LEDs_mstr_caution\CF8574_CMSC_3_LCD_plus_switches_encoders_LEDs_mstr_caution.ino:19:6: note: 'void onCmscTxtJmrChange(char*)' previously defined here
 void onCmscTxtJmrChange(char* newValue) {
      ^~~~~~~~~~~~~~~~~~
F:\Users\LES\Documents\Arduino\CF8574_CMSC_3_LCD_plus_switches_encoders_LEDs_mstr_caution\Slave_PCF8574_CMSC_multiple_LCD.ino: At global scope:
F:\Users\LES\Documents\Arduino\CF8574_CMSC_3_LCD_plus_switches_encoders_LEDs_mstr_caution\Slave_PCF8574_CMSC_multiple_LCD.ino:18:42: error: redefinition of 'DcsBios::StringBuffer<8> cmscTxtJmrBuffer'
 DcsBios::StringBuffer<8> cmscTxtJmrBuffer(0x1096, onCmscTxtJmrChange);
                                          ^
F:\Users\LES\Documents\Arduino\CF8574_CMSC_3_LCD_plus_switches_encoders_LEDs_mstr_caution\CF8574_CMSC_3_LCD_plus_switches_encoders_LEDs_mstr_caution.ino:23:26: note: 'DcsBios::StringBuffer<8> cmscTxtJmrBuffer' previously declared here
 DcsBios::StringBuffer<8> cmscTxtJmrBuffer(0x1096, onCmscTxtJmrChange);
                          ^~~~~~~~~~~~~~~~
F:\Users\LES\Documents\Arduino\CF8574_CMSC_3_LCD_plus_switches_encoders_LEDs_mstr_caution\Slave_PCF8574_CMSC_multiple_LCD.ino: In function 'void onCmscTxtChaffFlareChange(char*)':
F:\Users\LES\Documents\Arduino\CF8574_CMSC_3_LCD_plus_switches_encoders_LEDs_mstr_caution\Slave_PCF8574_CMSC_multiple_LCD.ino:20:6: error: redefinition of 'void onCmscTxtChaffFlareChange(char*)'
 void onCmscTxtChaffFlareChange(char* newValue) {
      ^~~~~~~~~~~~~~~~~~~~~~~~~
F:\Users\LES\Documents\Arduino\CF8574_CMSC_3_LCD_plus_switches_encoders_LEDs_mstr_caution\CF8574_CMSC_3_LCD_plus_switches_encoders_LEDs_mstr_caution.ino:25:6: note: 'void onCmscTxtChaffFlareChange(char*)' previously defined here
 void onCmscTxtChaffFlareChange(char* newValue) {
      ^~~~~~~~~~~~~~~~~~~~~~~~~
F:\Users\LES\Documents\Arduino\CF8574_CMSC_3_LCD_plus_switches_encoders_LEDs_mstr_caution\Slave_PCF8574_CMSC_multiple_LCD.ino: At global scope:
F:\Users\LES\Documents\Arduino\CF8574_CMSC_3_LCD_plus_switches_encoders_LEDs_mstr_caution\Slave_PCF8574_CMSC_multiple_LCD.ino:24:49: error: redefinition of 'DcsBios::StringBuffer<8> cmscTxtChaffFlareBuffer'
 DcsBios::StringBuffer<8> cmscTxtChaffFlareBuffer(0x108e, onCmscTxtChaffFlareChange);
                                                 ^
F:\Users\LES\Documents\Arduino\CF8574_CMSC_3_LCD_plus_switches_encoders_LEDs_mstr_caution\CF8574_CMSC_3_LCD_plus_switches_encoders_LEDs_mstr_caution.ino:29:26: note: 'DcsBios::StringBuffer<8> cmscTxtChaffFlareBuffer' previously declared here
 DcsBios::StringBuffer<8> cmscTxtChaffFlareBuffer(0x108e, onCmscTxtChaffFlareChange);
                          ^~~~~~~~~~~~~~~~~~~~~~~
F:\Users\LES\Documents\Arduino\CF8574_CMSC_3_LCD_plus_switches_encoders_LEDs_mstr_caution\Slave_PCF8574_CMSC_multiple_LCD.ino: In function 'void onCmscTxtMwsChange(char*)':
F:\Users\LES\Documents\Arduino\CF8574_CMSC_3_LCD_plus_switches_encoders_LEDs_mstr_caution\Slave_PCF8574_CMSC_multiple_LCD.ino:26:6: error: redefinition of 'void onCmscTxtMwsChange(char*)'
 void onCmscTxtMwsChange(char* newValue) {
      ^~~~~~~~~~~~~~~~~~
F:\Users\LES\Documents\Arduino\CF8574_CMSC_3_LCD_plus_switches_encoders_LEDs_mstr_caution\CF8574_CMSC_3_LCD_plus_switches_encoders_LEDs_mstr_caution.ino:31:6: note: 'void onCmscTxtMwsChange(char*)' previously defined here
 void onCmscTxtMwsChange(char* newValue) {
      ^~~~~~~~~~~~~~~~~~
F:\Users\LES\Documents\Arduino\CF8574_CMSC_3_LCD_plus_switches_encoders_LEDs_mstr_caution\Slave_PCF8574_CMSC_multiple_LCD.ino: At global scope:
F:\Users\LES\Documents\Arduino\CF8574_CMSC_3_LCD_plus_switches_encoders_LEDs_mstr_caution\Slave_PCF8574_CMSC_multiple_LCD.ino:30:42: error: redefinition of 'DcsBios::StringBuffer<8> cmscTxtMwsBuffer'
 DcsBios::StringBuffer<8> cmscTxtMwsBuffer(0x12b0, onCmscTxtMwsChange);
                                          ^
F:\Users\LES\Documents\Arduino\CF8574_CMSC_3_LCD_plus_switches_encoders_LEDs_mstr_caution\CF8574_CMSC_3_LCD_plus_switches_encoders_LEDs_mstr_caution.ino:35:26: note: 'DcsBios::StringBuffer<8> cmscTxtMwsBuffer' previously declared here
 DcsBios::StringBuffer<8> cmscTxtMwsBuffer(0x12b0, onCmscTxtMwsChange);
                          ^~~~~~~~~~~~~~~~
F:\Users\LES\Documents\Arduino\CF8574_CMSC_3_LCD_plus_switches_encoders_LEDs_mstr_caution\Slave_PCF8574_CMSC_multiple_LCD.ino: In function 'void setup()':
F:\Users\LES\Documents\Arduino\CF8574_CMSC_3_LCD_plus_switches_encoders_LEDs_mstr_caution\Slave_PCF8574_CMSC_multiple_LCD.ino:32:6: error: redefinition of 'void setup()'
 void setup() {
      ^~~~~
F:\Users\LES\Documents\Arduino\CF8574_CMSC_3_LCD_plus_switches_encoders_LEDs_mstr_caution\CF8574_CMSC_3_LCD_plus_switches_encoders_LEDs_mstr_caution.ino:50:6: note: 'void setup()' previously defined here
 void setup() {
      ^~~~~
F:\Users\LES\Documents\Arduino\CF8574_CMSC_3_LCD_plus_switches_encoders_LEDs_mstr_caution\Slave_PCF8574_CMSC_multiple_LCD.ino: In function 'void loop()':
F:\Users\LES\Documents\Arduino\CF8574_CMSC_3_LCD_plus_switches_encoders_LEDs_mstr_caution\Slave_PCF8574_CMSC_multiple_LCD.ino:40:6: error: redefinition of 'void loop()'
 void loop() {
      ^~~~
F:\Users\LES\Documents\Arduino\CF8574_CMSC_3_LCD_plus_switches_encoders_LEDs_mstr_caution\CF8574_CMSC_3_LCD_plus_switches_encoders_LEDs_mstr_caution.ino:59:6: note: 'void loop()' previously defined here
 void loop() {
      ^~~~
Multiple libraries were found for "LiquidCrystal_PCF8574.h"
  Used: F:\Users\LES\Documents\Arduino\libraries\LiquidCrystal_PCF8574
  Not used: F:\Users\LES\Documents\Arduino\libraries\LiquidCrystal_PCF8574-master
exit status 1

Compilation error: redefinition of 'LiquidCrystal_PCF8574 lcd0'

Any idea what could be going on?

Cheers

Les

Hi @Lesthegringo

Because they frequently only contain a single .ino file, it is easy to get the impression that Arduino sketches are the .ino file. However, this is not so. An Arduino sketch is a folder. That folder may contain several source files. All the source files in that folder are compiled into a single program.

The compiler errors indicate that you have a sketch at this path:

F:\Users\LES\Documents\Arduino\CF8574_CMSC_3_LCD_plus_switches_encoders_LEDs_mstr_caution

This sketch contains multiple .ino files:

  • Slave_PCF8574_CMSC_multiple_LCD.ino
  • CF8574_CMSC_3_LCD_plus_switches_encoders_LEDs_mstr_caution.ino

You should see them as tabs in Arduino IDE. If you open each of those tabs, you should see the duplicate definitions mentioned in the error.


Now the question comes of how to go about resolving the problem. In order to help you with that, we need to know why you put the two files in the same sketch:

Did you intend for these two be two separate programs?

Or did you intend the two files to be parts of a single program?

1 Like

Your topic has been moved to a more suitable location on the forum.

Although it might be confusing, the IDE2 x category is for problems with the IDE itself, not for programming problems.

Ok, thanks for the clarification - this was one where it fell foul of the filename issue previously reported, where there were spaces in the filename. I assumed (wrongly) that it overwrote the original file, so now I can see that there are indeed two sketches in the same folder

Now I know what to look for I can prevent similar errors

Cheers

Les

You are welcome. I'm glad if I was able to be of assistance.

If these are intended to be two separate programs, then simply move the file Slave_PCF8574_CMSC_multiple_LCD.ino to a separate folder named Slave_PCF8574_CMSC_multiple_LCD. You can then open that "Slave_PCF8574_CMSC_multiple_LCD" sketch in a separate Arduino IDE window and compile or upload it from that window.

Or if one of the two files is no longer of value, you can simply delete it.

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