Code compiles in old IDE but not the new one

The code that follows compiles just fine on the old IDE, but on the new IDE 2.32, it gets the following error. It doesn't seem to recognize the delayMicroseconds command.

This is the error:
C:\Users\Mike\Desktop\T4DualStep\stepClass.cpp: In member function 'void StepperClass::enable()':
C:\Users\Mike\Desktop\T4DualStep\stepClass.cpp:21:1: error: 'delayMicros' was not declared in this scope; did you mean 'elapsedMicros'?

exit status 1

Compilation error: exit status 1

I downloaded the new IDE2.3.2 but that didn't help.
Why would it compile under the old IDE but not the new one?

This is the T4DualStep.ino file:

#include "arduino.h"

const int ENABLE1 = 8;
const int DIRECTION1 = 5;
const int STEP1 = 2;
const int ENABLE2 = 8;
const int DIRECTION2 = 6;
const int STEP2 = 3;

const int MAX_SPEED = 1000;         // maximum requested motor speed control
const int MAX_ACCELERATION = 5000;  // acceleratiom of the motor speed
const int TESTSPEED = 50;

float targetSpeed = 0;    // target motor speed
float adjustedSpeed = 0;  // adjusted motor speed
float actualSpeed = 0;    // actual real time speed of motor
float timerPeriod;
unsigned long loopNow, loopLast;        // loop time
unsigned long reverseNow, reverseLast;  // direction reverse time
volatile int8_t motorDirection1 = 1;    // direction of stepper motor 1 = CW, -1 = CCW, 0 = stopped
volatile int8_t motorDirection2 = 1;    // direction of stepper motor 1 = CW, -1 = CCW, 0 = stopped
int spd = TESTSPEED;

IntervalTimer pulseTimer;  // create a motor pulse timer

/**************************************************************************************************************/
void setup() {
  Serial.begin(115200);  // start the Serial communications
  delay(500);
  Serial.println("Hi");
  // set up the A4988 carrier pins

  pinMode(ENABLE1, OUTPUT);     // Arduino digital pin (Active LOW)
  pinMode(STEP1, OUTPUT);       // Arduino digital pin
  pinMode(DIRECTION1, OUTPUT);  // Arduino digital pin
  pinMode(ENABLE2, OUTPUT);     // Arduino digital pin (Active LOW)
  pinMode(STEP2, OUTPUT);       // Arduino digital pin
  pinMode(DIRECTION2, OUTPUT);  // Arduino digital pin

  digitalWrite(ENABLE1, HIGH);  // disable the stepper
  digitalWrite(STEP1, HIGH);
  digitalWrite(DIRECTION1, HIGH);
  digitalWrite(ENABLE2, HIGH);  // disable the stepper
  digitalWrite(STEP2, HIGH);
  digitalWrite(DIRECTION2, HIGH);
  pulseTimer.priority(0);

  motorDirection1 = 1;         // motor direction = CW
  motorDirection2 = 1;         // motor direction = CW
  digitalWrite(ENABLE1, LOW);  // Enable the stepper
  digitalWrite(ENABLE2, LOW);  // Enable the stepper
  loopLast = millis();
  reverseLast = millis();
}

/**************************************************************************************************************/
void loop() {
  loopNow = millis();

  if (loopNow - loopLast >= 5)  // 5ms loop
  {
  //  SetMotorSpeed1(spd);
    //   SetMotorSpeed2(spd);
    loopLast = loopNow;
  }

  reverseNow = millis();
  if (reverseNow - reverseLast >= 1000)  // 1000ms loop
  {
    reverseLast = reverseNow;
    if (spd == TESTSPEED)
      spd = -TESTSPEED;
    else
      spd = TESTSPEED;
    // Serial.println(spd);
  }
}

This is the stepperClass.h file:

#ifndef __StepperClass_H__
#define __StepperClass_H__

class StepperClass {
private:
  int _enable;
  int _step;
  int _direction;
  int _speed;
  int _position;
  int _target;

public:
  StepperClass(int enable, int step, int direction, int stepsPerRev);  // constructor
  void changeDirection();                                           // reverse the current dorection (any mode)
  void enable();                                                    // enable the stepper
  void disable();                                                   // disable the stepper
  int getPosition();                                                // get the stepper's current position (async or sync mode)
  int getTarget();                                                  // get the stepper's target location (async or sync mode)
  int getSpeed();                                                   // get the current speed (any mode)
  void moveToTarget();                                              // does the actual move (async or sync mode)
  void step();                                                      // step the stepper one step
  void setAsyncMode();                                              // steppers arrive independently
  void setContinuousMode();                                         // setSpeed causes a continuoue move in selected direction
  void setForward();                                                // move the stepper forward (any mode)
  void setPosition();                                               // set the stepper's current position (async or sync mode)
  void setReverse();                                                // move the stepper reverse (any mode)
  void setSpeed();                                                  // set the desired speed of movement (any mode))
  void setSyncMode();                                               // steppers arrive at the same time regardless of distance moved
  void setTarget();                                                 // set the stepper's target location (async or sync mode)
};


#endif

Here is the stepperClass.cpp file:

#include "arduino.h"
#include "stepperClass.h"

/**************************************************************************************************************/
StepperClass::StepperClass(int enable, int step, int direction, int stepsPerRev) {  // constructor
  _enable = enable;
  _step = step;
  _direction = direction;
  _speed = 0;
  _position = 0;
  _target = 0;
}
/**************************************************************************************************************/
void StepperClass::changeDirection() {
  digitalWrite(_direction, !digitalRead(_direction));  // reverse the current direction (any mode)
}

/**************************************************************************************************************/
void StepperClass::enable() {  // enable the stepper
  digitalWrite(_step, LOW);
  delayMicroseconds(1);
  digitalWrite(_step, HIGH);
}

/**************************************************************************************************************/
void StepperClass::disable() {  // disable the stepper
}

/**************************************************************************************************************/
int StepperClass::getPosition() {  // get the stepper's current position (async or sync mode)
  return _position;
}

/**************************************************************************************************************/
int StepperClass::getTarget() {  // get the stepper's target location (async or sync mode)
  return _target;
}

/**************************************************************************************************************/
int StepperClass::getSpeed() {  // get the current speed (any mode)
  return _speed;
}

/**************************************************************************************************************/
void StepperClass::moveToTarget() {  // does the actual move (async or sync mode)
}

/**************************************************************************************************************/
void StepperClass::step() {  // step the stepper one step
}

/**************************************************************************************************************/
void StepperClass::setAsyncMode() {  // steppers arrive independently
}

/**************************************************************************************************************/
void StepperClass::setContinuousMode() {  // setSpeed causes a continuoue move in selected direction
}

/**************************************************************************************************************/
void setForward() {  // move the stepper forward (any mode)
}

/**************************************************************************************************************/
void StepperClass::setPosition() {  // set the stepper's current position (async or sync mode)
}

/**************************************************************************************************************/
void StepperClass::setReverse() {  // move the stepper reverse (any mode)
}

/**************************************************************************************************************/
void StepperClass::setSpeed() {  // set the desired speed of movement (any mode))
}

/**************************************************************************************************************/
void StepperClass::setSyncMode() {  // steppers arrive at the same time regardless of distance moved
}

/**************************************************************************************************************/
void StepperClass::setTarget() {  // set the stepper's target location (async or sync mode)
}

Perhaps?
#include "Arduino.h"

1 Like

The IDE has nothing to do with that, the IDE is just a fancy shell that drives the command line compiler. What probably happened is you used different library levels. Maybe you were very back leveled and installing the new IDE caught you up.
You could try to find the old code, but the name says it all, just replace the failing line with delayMicroseconds(1);

You could try to find the old code, but the name says it all, just replace the failing line with delayMicroseconds(1);

But the failing line already says "delayMicroseconds(1);", it is only the error that says 'delayMicros' was not found.

Am I missing something?

That user created function is superceded by the arduino built in function delayMicroseconds

I replaced #include arduino.h with #include "Arduino.h" and that does not change the symptoms.

I am already using delayMicroseconds. It is only the error that says delayMicros.

The error message says delayMicros, NOT delayMicroseconds. The error is on line 21 of the file stepClass.cpp, you have not shown that file, the file called stepperClass.cpp is NOT the same file. You are confused.

3 Likes

Nice catch.

I built a 50 year career on being able to read, you would be shocked at what I have seen.

The only place the file stepClass.cpp exists is in C:\Users\Mike\AppData\Local\Temp\arduino\sketches\088215E2A20E0A9FD0566B69A1061829\sketch\stepClass.cpp

There is no reference to it anywhere in my code.

Still, I deleted it and sure enough, it compiles okay now.

One has to wonder why a non-referenced file was used instead of the explicitly referenced file, but only in the new IDE.

Here is what I think happened. Originally, the files were stepClass.h and stepClass.cpp. The #include in the stepClass.cpp file was #include "stepClass.h"

At some point, I decided to change all 3 of those names to stepperClass. Apparently, that's when the problems started.

It seems that the stepClass.cpp file was still in the temp folder "C:\Users\Mike\AppData\Local\Temp\arduino\sketches\088215E2A20E0A9FD0566B69A1061829\sketch" and somehow it was still being referenced despite the name changes.

There's something fishy with that.

AH, that sounds like a bug I shot earlier. Do you have autosave on or off?

It has been reported to Arduino as a bug by the person who I helped.

Yes, Auto Save is on.

Maybe two related bugs then, his was off and I was able to reproduce. Now I would say that the compiler has an issue where it is not cleaning out temp files. I am old and don't remember, but it seems to me there is a way of opening a file so that it automatically is deleted once it is closed or, more likely, the process is terminated. Seems like some part of thatmechansm is broken. I am too old and tired to report it, is there a way to flag Arduino to check into this?

I guess the obvious workaround is to delete the temp files when a file name change occurs, at least until this is addressed.

Thanks for catching that!

I would not recommend that for a couple reasons. Did you by any chance have two IDE instances open so that the temp file couldn't auto-delete yet? They need to add process-ID to the temp name to prevent that. I think in Win it's a process-ID directory in fact.

Yes there were 2 instances open. one for the sketch in question and another for a different sketch so I could copy code back and forth.

Here is a bit more information that allows me to duplicate this at will.

  • I have only one instance open and the code compiles just fine.
  • I made a single change by restoring the deleted stepClass.cpp file. No other change was made. With that, the compile throws the very same error.
  • I rename the offending file and the code compiles okay again.

So even though the file was deleted/renamed in the temp folder, the IDE is still referencing it somehow, and it prefers to use that one when it is restored.

Another question is, if the IDE is trying to load that file, why doesn't it generate an error when I delete or rename the offending file?

Anyway, I hope that helps with determining what is happening.

You should raise that as an issue (bug) with Arduino. If you need help to do that maybe just flag your post so the admins will see it. Otherwise, there must be a reporting mechanism somewhere in the Arduino.cc site.

The Arduino developers are tracking this bug here:

If you have a GitHub account, you can subscribe to that thread to get notifications of any new developments related to this subject:

screenshot of Subscribe button


:exclamation: Please only comment on the GitHub issue thread if you have new technical information that will assist with the resolution. General discussion and support requests are always welcome here on the Arduino Forum.