Redefinition of init error when compiling verify

Hi! I'm having trouble compiling my sketch using a simple code to upload into a ESP32+TFT 240 x 240 display.

I splitted the gif frames into 3 parts (wpl1, wpl2 and wpl3) in order to reduce the file size.
Error redefinition of 'int frames' just pops up when verify it. I have no much coding experience and any help and hints are much appreciated.
Please see below my code:

#include <SPI.h>
#include <TFT_eSPI.h> // Hardware-specific library
TFT_eSPI tft = TFT_eSPI();
#include "wpl1.h"
#include "wpl2.h"
#include "wpl3.h"

void setup() {
  // put your setup code here, to run once:
  tft.init();
  tft.setRotation(0);

  tft.setSwapBytes(true);
  tft.fillScreen(TFT_WHITE);

}

void loop() {
  // put your main code here, to run repeatedly:
  //for (int i = 0; i < frames; i++)

  {
    delay(2000);
    tft.pushImage(0, 0, 230, 173, wpl1[i]);
    tft.pushImage(0, 0, 230, 173, wpl2[1]);
    tft.pushImage(0, 0, 230, 173, wpl3[1]);
  }

} 

Below the error:

In file included from C:\Users\eduardo.santacruz\OneDrive - Marel\Documents\Arduino\WPL9000\WPL9000\WPL9000.ino:9:0:

wpl2.h:1:5: error: redefinition of 'int frames'

 int frames=4;

     ^

In file included from C:\Users\eduardo.santacruz\OneDrive - Marel\Documents\Arduino\WPL9000\WPL9000\WPL9000.ino:8:0:

sketch\wpl1.h:1:5: note: 'int frames' previously defined here

 int frames=4;

     ^

In file included from C:\Users\eduardo.santacruz\OneDrive - Marel\Documents\Arduino\WPL9000\WPL9000\WPL9000.ino:9:0:

wpl2.h:2:5: error: redefinition of 'int animation_width'

 int animation_width=230;

     ^

In file included from C:\Users\eduardo.santacruz\OneDrive - Marel\Documents\Arduino\WPL9000\WPL9000\WPL9000.ino:8:0:

sketch\wpl1.h:2:5: note: 'int animation_width' previously defined here

 int animation_width=230;

     ^

In file included from C:\Users\eduardo.santacruz\OneDrive - Marel\Documents\Arduino\WPL9000\WPL9000\WPL9000.ino:9:0:

wpl2.h:3:5: error: redefinition of 'int animation_height'

 int animation_height=173;

     ^

In file included from C:\Users\eduardo.santacruz\OneDrive - Marel\Documents\Arduino\WPL9000\WPL9000\WPL9000.ino:8:0:

sketch\wpl1.h:3:5: note: 'int animation_height' previously defined here

 int animation_height=173;

     ^

In file included from C:\Users\eduardo.santacruz\OneDrive - Marel\Documents\Arduino\WPL9000\WPL9000\WPL9000.ino:10:0:

wpl3.h:1:5: error: redefinition of 'int frames'

 int frames=4;

     ^

In file included from C:\Users\eduardo.santacruz\OneDrive - Marel\Documents\Arduino\WPL9000\WPL9000\WPL9000.ino:8:0:

sketch\wpl1.h:1:5: note: 'int frames' previously defined here

 int frames=4;

     ^

In file included from C:\Users\eduardo.santacruz\OneDrive - Marel\Documents\Arduino\WPL9000\WPL9000\WPL9000.ino:10:0:

wpl3.h:2:5: error: redefinition of 'int animation_width'

 int animation_width=230;

     ^

In file included from C:\Users\eduardo.santacruz\OneDrive - Marel\Documents\Arduino\WPL9000\WPL9000\WPL9000.ino:8:0:

sketch\wpl1.h:2:5: note: 'int animation_width' previously defined here

 int animation_width=230;

     ^

In file included from C:\Users\eduardo.santacruz\OneDrive - Marel\Documents\Arduino\WPL9000\WPL9000\WPL9000.ino:10:0:

wpl3.h:3:5: error: redefinition of 'int animation_height'

 int animation_height=173;

     ^

In file included from C:\Users\eduardo.santacruz\OneDrive - Marel\Documents\Arduino\WPL9000\WPL9000\WPL9000.ino:8:0:

sketch\wpl1.h:3:5: note: 'int animation_height' previously defined here

 int animation_height=173;

     ^

C:\Users\eduardo.santacruz\OneDrive - Marel\Documents\Arduino\WPL9000\WPL9000\WPL9000.ino: In function 'void loop()':

WPL9000:28:40: error: 'i' was not declared in this scope

     tft.pushImage(0, 0, 230, 173, wpl1[i]);

                                        ^

exit status 1

redefinition of 'int frames'

Welcome to the forum

Your topic was MOVED to its current forum category which is more appropriate than the original as it has nothing to do with Installation and Troubleshooting of the IDE

1 Like

Please post what is in the .h files that you have #included in your sketch. Do they by any chance each have int frames=4; as part of their code ?

Hi mate!
Thanks for moving the post to the correct forum category...
Yes, I can confirm each have int frames=4; as part of their code...
I have 12 frames (jpg) in total and I splitted into 4 parts. Then, I used a program to convert jpg to .h
Seems that new users cannot upload attachments...

That is what is causing the problem

Don't attach the code in the files, post their contents in a new reply

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use [color = red]code tags[/color] (the </> icon above the compose window) to make it easier to read and copy for examination

I'm very happy to following the guidelines and rules! I appreciate good practices...

Ok! So the problem is the int frames=4
In order to fix this, should I rename it? How the int frames should ordered?
In case I need to redo the frames, what is the procedure to split it correctly?

What happened when you tried?

If you post the contents of what is in the .h files then we can give more advice

The first observation I have is that splitting the code into parts and then #including it will not reduce the file size

Hi Shannon..
Not tried yet...

Ah, ok! Interesting...makes sense...
I will try to use only one code (.h) and see what happens...I am just concern if my ESP32 can handle about 3.4MB .h file...

Are you surprised that four variables with the same name cannot be used in the same sketch?

Moving part of the code to a .h file does not change anything in this rule. The #include "wpl1.h" directive simply pastes the contents of the wpl1.h file at the location in the sketch where the directive itself is located - just as if you had simply copied the contents of the file and pasted it into the main code.

The easiest thing you can do for solving the issue - is to choose unique names for your frames variables, for example frames1 in wpl1.h, frames2 for wpl2.h.... etc

You still have not shown us what is lurking in there mysterious .h files

If it is mostly an array holding image data then have you considered putting it on an SD card and reading it from there or in a LittleFS file or files and reading it from there ? If it is an array then are you using the most efficient data type for it ?

Hi! Sorry take longer to reply, as Christmas did not give me a chance for it!!
Nothing mysterious on my .h files..Lol..they are just a .gif splitted into .jpg frames..
I was able to resolved the problem just making only one .h file instead 3. Verified and Uploaded with no error at all.
Thanks all for your inputs on this matter!

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