Error with the EEROM library

Hey guys,

I am relatively new at programming Arduinos. I am trying to use the EEPROM library, but I am getting this error that I cannot resolve. I haven't even used any of the functions in the library.

Arduino: 1.8.19 (Windows 10), Board: "Arduino Uno"

In file included from C:\Users\Name\Documents\Arduino\libraries\stackAccess\stackAccess.c:1:0:

C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM\src/EEPROM.h:38:5: error: expected specifier-qualifier-list before 'EERef'

 EERef( const int index )

 ^~~~~

C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM\src/EEPROM.h:89:5: error: expected specifier-qualifier-list before 'EEPtr'

 EEPtr( const int index )

 ^~~~~

C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM\src/EEPROM.h:119:5: error: unknown type name 'EERef'

 EERef operator[]( const int idx )    { return idx; }

 ^~~~~

C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM\src/EEPROM.h:119:42: error: expected ':', ',', ';', '}' or 'attribute' before '{' token

 EERef operator[]( const int idx )    { return idx; }

                                      ^

In file included from C:\Users\Prarthin\Documents\Arduino\libraries\stackAccess\stackAccess.c:1:0:

C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM\src/EEPROM.h:145:8: error: unknown type name 'EEPROMClass'

static EEPROMClass EEPROM;

    ^~~~~~~~~~~

exit status 1

Error compiling for board Arduino Uno.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Any help would be greatly appreciated.

Thanks

And your code is? Just in case, please pay attention how to post code (using code tags) in How to get the best out of this forum.

And where do we find \stackAccess\stackAccess.c?

Hey,

Sorry pretty new to this forum. The code is quite long so I didn't post it here. Essentially, I am using timers to control a stepper motor.

This is the directory for stackAccess.c

C:\Users\Name\Documents\Arduino\libraries\stackAccess

Thanks,

That's where it is at on your computer. Since I'm not a black hat hacker who can break into your system, it doesn't do me any good.

Please tell us where you got this library from.

If you installed it using the Arduino Library Manager (Sketch > Include Library > Manage Libraries in the Arduino IDE or Libraries > Library Manager in the Arduino Web Editor) then say so and state the full name of the library.

If you downloaded it from a website, then please post a link to that website.

No that is a custom library I am making for the code.

:smiley:

Have you considered that we have no idea what is going on in your stuff. Please post your code, all of it.

Does your library use the EEPROM library?

Sorry guys, as you can tell, I know embarrassingly little about this.

Following is the main function

#include <stackAccess.h>

const int N_AXIS = 3;
const int X_AXIS = 0;
const int Y_AXIS = 1;
const int Z_AXIS = 2;

const int X_STEP = 2;
const int Y_STEP = 3;
const int Z_STEP = 4;
const int X_DIR = 5;
const int Y_DIR = 6;
const int Z_DIR = 7;

const uint16_t t_load = 0;
uint16_t t1_comp= 4000;
volatile uint16_t steps[3];
volatile uint16_t sys_Positions[3];
volatile uint16_t slope;
int x = 0;
uint16_t len = 50000;
uint16_t ind = 0;

typedef struct {
  uint32_t currPos[N_AXIS];
  uint32_t finPos[N_AXIS];
  volatile int32_t dx = finPos[X_AXIS] - currPos[X_AXIS];
  volatile int32_t dy = finPos[Y_AXIS] - currPos[Y_AXIS];
  volatile int32_t dz = finPos[Z_AXIS] - currPos[Z_AXIS];
  int32_t slope;
  int8_t inc_x;
  int8_t inc_y;
  int8_t inc_z;
  volatile uint8_t ex_status;
  volatile uint8_t xy_flag;
  volatile uint8_t z_flag;
} path;
static path st;


typedef struct {
  uint8_t reset_value = 200;
} settings;
static settings set;

void moveXY(uint32_t, uint32_t);
void moveZ(uint32_t);

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(X_STEP, OUTPUT);
  pinMode(X_DIR, OUTPUT);
  pinMode(Y_STEP, OUTPUT);
  pinMode(Y_DIR, OUTPUT);
  pinMode(Z_STEP, OUTPUT);
  pinMode(Z_DIR, OUTPUT);

  sys_Positions[X_AXIS] = 0;
  sys_Positions[Y_AXIS] = 0;
  sys_Positions[Z_AXIS] = 0;

  //SETTING UP TIMER 1
  TCCR1A = 0;
  
  //Setting up the CTC
  TCCR1B &= ~(1 << WGM13);
  TCCR1B |= (1 << WGM12);

  //Set the prescalar value
  TCCR1B &= ~(1 << CS12);
  TCCR1B &= ~(1 << CS11);
  TCCR1B |= (1 << CS10);

  //Reset the timer and set compare value
  TCNT1 = t_load;
  OCR1A = t1_comp;

  //Enable Timer1 compare interrupt
  TIMSK1 = (1 << OCIE1A);

  //Setting up the reset timer: TIMER0
  TIMSK0 &= ~((1<<OCIE0B) | (1<<OCIE0A) | (1<<TOIE0));

  TCCR0A = (1<<WGM01);
  TCCR0B = 0;

  TIMSK0 |= (1<<OCIE0A);
}

void loop() {
  // put your main code here, to run repeatedly:
  while(!x){
    x = 1;
  }
}

void moveXY(uint32_t x, uint32_t y){
  //Clear the executing flag
  st.ex_status = 1;
  st.xy_flag = 1;
  
  //Defining the current position and the final position
  st.currPos[X_AXIS] = sys_Positions[X_AXIS];
  st.currPos[Y_AXIS] = sys_Positions[Y_AXIS];

  st.finPos[X_AXIS] = x;
  st.finPos[Y_AXIS] = y;

  //Bresenham's Line Algorithm
  st.dx = st.finPos[X_AXIS] - st.currPos[X_AXIS];
  st.dy = st.finPos[Y_AXIS] - st.currPos[Y_AXIS];
  if(st.dx < 0){
    digitalWrite(X_DIR, LOW);
    st.inc_x = -1;
    st.dx = -1*st.dx;
  } else {
    digitalWrite(X_DIR, HIGH);
    st.inc_x = 1;
  }
  if(st.dy < 0){
    digitalWrite(Y_DIR, LOW);
    st.inc_y = -1;
    st.dy = -1*st.dy;
  } else {
    digitalWrite(Y_DIR, HIGH);
    st.inc_y = 1;
  }
  if(st.dx > st.dy){
    st.slope = 2*st.dy - st.dx;
  } else {
    st.slope = 2*st.dx - st.dy;
  }
//  Serial.print("dx: ");
//  Serial.println(st.dx);
//  Serial.print("dy: ");
//  Serial.println(st.dy);
//  Serial.print("2*dy: ");
//  Serial.println(2*st.dy);
//  Serial.print("2*dy - dx = ");
//  Serial.println(st.slope);
  

  //Allow interrupts
  sei();

  while(st.ex_status == 1);
  Serial.println("Position placement complete!");

  st.xy_flag = 0;
  cli();
}

void moveZ(uint32_t z){
  //Resetting te ex_status flag  
  st.ex_status = 1;
  st.z_flag = 1;

  //Transferring the sys position into current position
  st.currPos[Z_AXIS] = sys_Positions[Z_AXIS];

  //Setting the final position to the z position value suppied
  st.finPos[Z_AXIS] = z;

  if((st.finPos[Z_AXIS] - st.currPos[Z_AXIS]) < 0){
    digitalWrite(Z_DIR, LOW);
    st.inc_z = -1;
  } else {
    digitalWrite(Z_DIR, HIGH);
    st.inc_z = 1;
  }

  sei();

  while(st.ex_status == 1);

  st.z_flag = 0;
  cli();
}

ISR(TIMER1_COMPA_vect) {
  if(st.xy_flag == 1){
    if(sys_Positions[X_AXIS] == st.finPos[X_AXIS] && sys_Positions[Y_AXIS] == st.finPos[Y_AXIS]){
      st.ex_status = 0;
    } else {
      //Technically, this would be the plotting section. Should be replaced with pulsing the signal
  //    Serial.print("X position: ");
  //    Serial.print(sys_Positions[X_AXIS]);
  //    Serial.print(", Y Position: ");
  //    Serial.println(sys_Positions[Y_AXIS]);
  //    Serial.print(" with D = ");
  //    Serial.println(st.slope);
  
      //Enabling the reset counter
      OCR0A = set.reset_value;
      TCCR0B |= (1<<CS01);
  
      if(st.dx > st.dy){
        //Incrementing in the x-axis
        digitalWrite(X_STEP, HIGH);
        sys_Positions[X_AXIS] += st.inc_x;
        
        if(st.slope < 0){
          st.slope = st.slope + 2*st.dy;
        } else {
          digitalWrite(Y_STEP, HIGH);
          st.slope = st.slope + 2*st.dy - 2*st.dx;
          sys_Positions[Y_AXIS] += st.inc_y;
        }
      } else {
        digitalWrite(Y_STEP, HIGH);
        sys_Positions[Y_AXIS] += st.inc_y;
  
        if(st.slope < 0){
          st.slope = st.slope + 2*st.dx;
        } else {
          digitalWrite(X_STEP, HIGH);
          st.slope = st.slope + 2*st.dx - 2*st.dy;
          sys_Positions[X_AXIS] += st.inc_x;
        }
      }
    }
  } else {
    if(sys_Positions[Z_AXIS] == st.finPos[Z_AXIS]){
      st.ex_status = 0;
    } else {
      OCR0A = set.reset_value;
      TCCR0B |= (1<<CS01);
      Serial.print("Z Position: ");
      Serial.println(sys_Positions[Z_AXIS]);
      digitalWrite(Z_STEP, HIGH);
      sys_Positions[Z_AXIS] += st.inc_z;
    }
  }
}

ISR(TIMER0_COMPA_vect){
//  Serial.println("The outputs should be reset here");
  digitalWrite(X_STEP, LOW);
  digitalWrite(Y_STEP, LOW);
  digitalWrite(Z_STEP, LOW);
  TCCR0B = 0;
}

This is the header file:

#include <EEPROM.h>

uint16_t initStack();

And this is the c file

typedef struct {
  uint32_t x_cor;
  uint32_t y_cor;
  uint32_t z_cor;
} cors;

uint16_t initStack(){
  //return EEPROM.length();
}

I think you left something out:

That error message tells me that you have an #include directive for EEPROM.h in stackAccess.c, whether direct or transitively via #include "stackAccess.h".

EEPROM is a C++ library and uses C++-specific language features. When you use a .c file extension on your library file stackAccess.c, that causes the library code to be compiled as C code, which means that you can't use any C++-specific language features in the library source code.

The easy fix is to rename stackAccess.c to stackAccess.cpp, which will cause it to be compiled as C++.

In file EEPROM.h included from libraries\stackAccess\stackAccess.c:1:0:

You can't use C++ objects like EEPROM in a C source like stackAccess.c. Rename stackAccess.c to stackAccess.cpp if you want to use EEPROM in it.

That is working. Thanks guys!

You are welcome. I'm glad it is working now. Enjoy!

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