Arduino Nano 33 BLE & TMC2209 - Unable to compile - While working on Arduino UNO

Dear all,

This is my first post, I hope I’m not doing too many mistakes :slight_smile:

I have an Arduino Nano 33 BLE and I want to control (among many other things) a Trinamic TMC2209 Stepper Driver Board. I am trying to make one of the examples coming with the TMCStepper library called “Simple”.

After fighting against several compilations errors due to Serial specificities of the Nano 33 BLE board, I finaly made it to the (hopefully) last error. It’s the following :

In file included from C:\Users\XXX\AppData\Local\Arduino15\packages\arduino\hardware\mbed\1.3.2\cores\arduino/Arduino.h:90:0,
                 from sketch\TMC2209-working.ish.ino.cpp:1:
C:\Users\XXX\AppData\Local\Arduino15\packages\arduino\hardware\mbed\1.3.2\variants\ARDUINO_NANO33BLE/pins_arduino.h:82:14: error: expected unqualified-id before numeric constant
 #define D1   1
              ^
C:\Users\XXX\Documents\Arduino\libraries\TMCStepper-master\src/TMCStepper.h:608:12: note: in expansion of macro 'D1'
   uint16_t D1();
            ^
C:\Users\XXX\AppData\Local\Arduino15\packages\arduino\hardware\mbed\1.3.2\variants\ARDUINO_NANO33BLE/pins_arduino.h:82:14: error: expected unqualified-id before numeric constant
 #define D1   1
              ^
C:\Users\XXX\Documents\Arduino\libraries\TMCStepper-master\src/TMCStepper.h:609:8: note: in expansion of macro 'D1'
   void D1(uint16_t input);
        ^
exit status 1
Error compiling for board Arduino Nano 33 BLE.

I am coming to you because, to my surprise (well not so much of a surprise after roaming the web for answers) **my code compiles just fine and executes on an Arduino UNO! **To the exception to this adaptation:

#define SERIAL_PORT Serial1 // for Nano 33 BLE
changed to :
#define SERIAL_PORT Serial  // for UNO

Here is my code : (again working just fine on the Arduino UNO and not compiling on the Nano 33 BLE)

#include <TMCStepper.h>

#define EN_PIN           6 // Enable
#define DIR_PIN          2 // Direction
#define STEP_PIN         3 // Step
#define SERIAL_PORT Serial1 // TMC2208/TMC2224 HardwareSerial port
#define DRIVER_ADDRESS 0b00 // TMC2209 Driver address according to MS1 and MS2

#define R_SENSE 0.11f // Match to your driver
                      // SilentStepStick series use 0.11

// Select your stepper driver type
TMC2209Stepper driver(&SERIAL_PORT, R_SENSE, DRIVER_ADDRESS);       // Hardware Serial

void setup() {
  pinMode(EN_PIN, OUTPUT);
  pinMode(STEP_PIN, OUTPUT);
  pinMode(DIR_PIN, OUTPUT);
  digitalWrite(EN_PIN, LOW);      // Enable driver in hardware

                                  // Enable one according to your setup
//SPI.begin();                    // SPI drivers
  SERIAL_PORT.begin(115200);      // HW UART drivers
//driver.beginSerial(115200);     // SW UART drivers

  driver.begin();                 //  SPI: Init CS pins and possible SW SPI pins
                                  // UART: Init SW UART (if selected) with default 115200 baudrate
  driver.toff(5);                 // Enables driver in software
  driver.rms_current(600);        // Set motor RMS current
  driver.microsteps(16);          // Set microsteps to 1/16th

//driver.en_spreadCycle(false);   // Toggle spreadCycle on TMC2208/2209/2224
  driver.pwm_autoscale(true);     // Needed for stealthChop
}

bool shaft = false;

void loop() {
  // Run 5000 steps and switch direction in software
  for (uint16_t i = 5000; i>0; i--) {
    digitalWrite(STEP_PIN, HIGH);
    delayMicroseconds(160);
    digitalWrite(STEP_PIN, LOW);
    delayMicroseconds(160);
  }
  shaft = !shaft;
  driver.shaft(shaft);
}

I have been stuck with this error for over a week now, and I can’t move on. Feels to me like some incompatibility between said TMCStepper.h library and the Nano 33 BLE pins_arduino.h library …

Hopefully you can help!

Thanks in advance :slight_smile:

Raztou3D

The problem is that there is a name collision between the core library of the Nano 33 BLE and the TMCStepper library. Here you can see a macro named “D1” was defined in the core library:

raztou3d:

C:\Users\XXX\AppData\Local\Arduino15\packages\arduino\hardware\mbed\1.3.2\variants\ARDUINO_NANO33BLE/pins_arduino.h:82:14: error: expected unqualified-id before numeric constant

#define D1  1
              ^

And here you can see a function named “D1” was declared in the TMCStepper library:

raztou3d:

C:\Users\XXX\Documents\Arduino\libraries\TMCStepper-master\src/TMCStepper.h:608:12: note: in expansion of macro 'D1'

uint16_t D1();
            ^

Unfortunately, the only way to fix the conflict is by editing the library, but it’s easy enough:

Open C:\Users\XXX\Documents\Arduino\libraries\TMCStepper-master\src/TMCStepper.h in a text editor.

Add the following at line 18:

#undef D1

Save the file.

Now try compiling your sketch again.

It’s safe to undefine this macro because it was only added as a convenience for users who might see the “D1”, etc. written on the silkscreen of their Nano BLE board and try to use that in the code instead of just the integer pin number 1.

It seems like this was not a very good choice of name by the TMCStepper library author, especially considering a similar D1 macro is also defined for some of the popular ESP8266 boards.

Hi pert,

THANK YOU !

As I expected, there was an incompatibility between the library and my Arduino board, but I would have never figured how to solve it without your help, so again, THANK YOU !

I have put a comment on their GitHub to make them aware of this issue and your solution.

Best,

Raztou3D

1 Like

You’re welcome. I’m glad if I was able to be of assistance. Enjoy!
Per

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