Sketch will compile, upload and run using UNO but will not compile using Nano 33 BLE Sense

Hello all, first off, I apologize if this topic is already out there, I could not find one discussing a similar issue.

I'm a new Arduino tinkerer and enjoy it a ton, but my knowledge level is extremely low. A big thank you to all of the wonderful people out there who upload their sketches and allow us to tweak them as we see fit! I'd be absolutely lost without you.

I have a sketch that runs great when using UNO but when I try to compile and upload the same sketch onto Nano 33 BLE Sense, I get the following error - invalid conversion from 'const char' to 'int' [-fpermissive] inBuffer = "";*

Here is the code (I'm sure it can be improved upon a lot) :

#include <AccelStepper.h>

AccelStepper stepperX(1, 2, 3);  //Sets up the pins for stepper X
AccelStepper stepperY(1, 4, 5);  //Sets up the pins for stepper Y

// Define the Pins used
#define home_switchX 9  // Pin 9 connected to Home Switch (MicroSwitch)
#define home_switchY 10 // Pin 10 connected to Home Switch (MicroSwitch)

// Stepper Travel Variables
long TravelX;               // Used to store the X value entered in the Serial Monitor
int move_finishedX = 1;     // Used to check if move is completed
long initial_homingX = -1;  // Used to Home Stepper at startup
long TravelY;
int move_finishedY = 1;
long initial_homingY = -1;

int inBuffer = 0;
int start_var = 0;

  // Target X & Y coordinates
int movementX = 0;
int movementY = 0;
int movement1X = 3000;
int movement1Y = 2000;
int movement2X = 2500;
int movement2Y = 1500;
int movement3X = 2000;
int movement3Y = 1300;
int movement4X = 1800;
int movement4Y = 1200;
int movement5X = 1500;
int movement5Y = 900;
int movement6X = 1300;
int movement6Y = 500;
int movement7X = 1000;
int movement7Y = 400;
int movement8X = 900;
int movement8Y = 300;
int movement9X = 800;
int movement9Y = 200;


long newStepperXPos = 0;  // varialbe for the new stepper position for variable 1
long newStepperYPos = 0;  // variable for the new stepper position for variable 2

void setup() {
  Serial.begin(9600);  // Start the Serial monitor with speed of 9600 Bauds

  pinMode(home_switchX, INPUT_PULLUP);
  pinMode(home_switchY, INPUT_PULLUP);

  delay(5);  // Wait for EasyDriver wake up

  //  Set Max Speed and Acceleration of each Steppers at startup for homing
  stepperX.setMaxSpeed(400.0);      // Set Max Speed of Stepper (Slower to get better accuracy)
  stepperX.setAcceleration(400.0);  // Set Acceleration of Stepper
  stepperY.setMaxSpeed(400.0);
  stepperY.setAcceleration(400.0);


  // Start Homing procedure of Stepper Motor at startup

  Serial.print("Steppers are Homing . . . . . . . . . . . ");

  while (digitalRead(home_switchX)){  // Make the Stepper move CCW until the switch is activated

    while (digitalRead(home_switchY)){
        stepperY.moveTo(initial_homingY);  // Set the position to move to
        initial_homingY--;                 // Decrease by 1 for next move if needed
        stepperY.run();                    // Start moving the stepper
        delay(5);
    }
      
        stepperX.moveTo(initial_homingX);  // Set the position to move to
        initial_homingX--;                 // Decrease by 1 for next move if needed
        stepperX.run();                    // Start moving the stepper
        delay(5);      
      
  }

  stepperX.setCurrentPosition(0);   // Set the current position as zero for now
  stepperX.setMaxSpeed(100.0);      // Set Max Speed of Stepper (Slower to get better accuracy)
  stepperX.setAcceleration(100.0);  // Set Acceleration of Stepper
  initial_homingX = 1;


  stepperY.setCurrentPosition(0);   // Set the current position as zero for now
  stepperY.setMaxSpeed(100.0);      // Set Max Speed of Stepper (Slower to get better accuracy)
  stepperY.setAcceleration(100.0);  // Set Acceleration of Stepper
  initial_homingY = 1;

  while (!digitalRead(home_switchX)) {  // Make the Stepper move CW until the switch is deactivated
    stepperX.moveTo(initial_homingX);
    stepperX.run();
    initial_homingX++;
    delay(5);
  }

  while (!digitalRead(home_switchY)) {  // Make the Stepper move CW until the switch is deactivated
    stepperY.moveTo(initial_homingY);
    stepperY.run();
    initial_homingY++;
    delay(5);
  }

  stepperX.setCurrentPosition(0);
  stepperY.setCurrentPosition(0);
  Serial.println("Homing Completed");
  Serial.println("");
  stepperX.setMaxSpeed(2000.0);     // Set Max Speed of Stepper (Faster for regular movements)
  stepperX.setAcceleration(600.0);  // Set Acceleration of Stepper
  stepperY.setMaxSpeed(2000.0);
  stepperY.setAcceleration(600.0);

  // Print out Instructions on the Serial Monitor at Start
  Serial.println("Select Target ");
}
void loop()
{
     
    if(Serial.available()>0) // If any information is avaiable coming from the serial monitor
    {
        inBuffer = Serial.read(); // Puts the information coming from the serial monitor in the input buffer
    }

    if (inBuffer == '0') // If the command sent is an '0'
    {
        Serial.println("Home "); //Serial print for Home
        
     
        if (stepperX.distanceToGo() == 0) {
            if (stepperX.currentPosition() == 0) {
                stepperX.moveTo(0);
            }
            else {
                stepperX.moveTo(0);
            }
        }
    
        if (stepperY.distanceToGo() == 0) {
            if (stepperY.currentPosition() == 0) {
                stepperY.moveTo(0);
            }
            else {
                stepperY.moveTo(0);
            }
        }
        inBuffer = ""; // clear this immediately the '0' has been used
        
    }
        
    if (inBuffer == '1') // If the command sent is an '1'
    {
        Serial.println("Target 1 ... 0 to 9 to Home"); //Serial print for Target 1
        
     
        if (stepperX.distanceToGo() == 0) {
            if (stepperX.currentPosition() == 0) {
                stepperX.moveTo(movement1X);
            }
            else {
                stepperX.moveTo(0);
            }
        }
    
        if (stepperY.distanceToGo() == 0) {
            if (stepperY.currentPosition() == 0) {
                stepperY.moveTo(movement1Y);
            }
            else {
                stepperY.moveTo(0);
            }
        }
        inBuffer = ""; // clear this immediately the '1' has been used

    }

    if (inBuffer == '2')
    {
        Serial.println("Target 2 ... 0 to 9 to Home");
        
     
        if (stepperX.distanceToGo() == 0) {
            if (stepperX.currentPosition() == 0) {
                stepperX.moveTo(movement2X);
            }
            else {
                stepperX.moveTo(0);
            }
        }
    
        if (stepperY.distanceToGo() == 0) {
            if (stepperY.currentPosition() == 0) {
                stepperY.moveTo(movement2Y);
            }
            else {
                stepperY.moveTo(0);
            }
        }
        inBuffer = "";

    }

    if (inBuffer == '3')
    {
        Serial.println("Target 3 ... 0 to 9 to Home");
        
     
        if (stepperX.distanceToGo() == 0) {
            if (stepperX.currentPosition() == 0) {
                stepperX.moveTo(movement3X);
            }
            else {
                stepperX.moveTo(0);
            }
        }
    
        if (stepperY.distanceToGo() == 0) {
            if (stepperY.currentPosition() == 0) {
                stepperY.moveTo(movement3Y);
            }
            else {
                stepperY.moveTo(0);
            }
        }
        inBuffer = "";

    }

    if (inBuffer == '4')
    {
        Serial.println("Target 4 ... 0 to 9 to Home");
        
     
        if (stepperX.distanceToGo() == 0) {
            if (stepperX.currentPosition() == 0) {
                stepperX.moveTo(movement4X);
            }
            else {
                stepperX.moveTo(0);
            }
        }
    
        if (stepperY.distanceToGo() == 0) {
            if (stepperY.currentPosition() == 0) {
                stepperY.moveTo(movement4Y);
            }
            else {
                stepperY.moveTo(0);
            }
        }
        inBuffer = "";

    }

    if (inBuffer == '5')
    {
        Serial.println("Target 5 ... 0 to 9 to Home");
        
     
        if (stepperX.distanceToGo() == 0) {
            if (stepperX.currentPosition() == 0) {
                stepperX.moveTo(movement5X);
            }
            else {
                stepperX.moveTo(0);
            }
        }
    
        if (stepperY.distanceToGo() == 0) {
            if (stepperY.currentPosition() == 0) {
                stepperY.moveTo(movement5Y);
            }
            else {
                stepperY.moveTo(0);
            }
        }
        inBuffer = "";

    }

    if (inBuffer == '6')
    {
        Serial.println("Target 6");
        
     
        if (stepperX.distanceToGo() == 0) {
            if (stepperX.currentPosition() == 0) {
                stepperX.moveTo(movement6X);
            }
            else {
                stepperX.moveTo(0);
            }
        }
    
        if (stepperY.distanceToGo() == 0) {
            if (stepperY.currentPosition() == 0) {
                stepperY.moveTo(movement6Y);
            }
            else {
                stepperY.moveTo(0);
            }
        }
        inBuffer = "";

    }

    if (inBuffer == '7')
    {
        Serial.println("Target 7 ... 0 to 9 to Home");
        
     
        if (stepperX.distanceToGo() == 0) {
            if (stepperX.currentPosition() == 0) {
                stepperX.moveTo(movement7X);
            }
            else {
                stepperX.moveTo(0);
            }
        }
    
        if (stepperY.distanceToGo() == 0) {
            if (stepperY.currentPosition() == 0) {
                stepperY.moveTo(movement7Y);
            }
            else {
                stepperY.moveTo(0);
            }
        }
        inBuffer = "";

    }

    if (inBuffer == '8')
    {
        Serial.println("Target 8 ... 0 to 9 to Home");
        
     
        if (stepperX.distanceToGo() == 0) {
            if (stepperX.currentPosition() == 0) {
                stepperX.moveTo(movement8X);
            }
            else {
                stepperX.moveTo(0);
            }
        }
    
        if (stepperY.distanceToGo() == 0) {
            if (stepperY.currentPosition() == 0) {
                stepperY.moveTo(movement8Y);
            }
            else {
                stepperY.moveTo(0);
            }
        }
        inBuffer = "";

    }

    if (inBuffer == '9')
    {
        Serial.println("Target 9 ... 0 to 9 to Home");
        
     
        if (stepperX.distanceToGo() == 0) {
            if (stepperX.currentPosition() == 0) {
                stepperX.moveTo(movement9X);
            }
            else {
                stepperX.moveTo(0);
            }
        }
    
        if (stepperY.distanceToGo() == 0) {
            if (stepperY.currentPosition() == 0) {
                stepperY.moveTo(movement9Y);
            }
            else {
                stepperY.moveTo(0);
            }
        }
        inBuffer = "";

    }

    stepperX.run();
    stepperY.run();

}

I'm sure there are better methods that will achieve what this code does, maybe one day I'll figure that out.

Is there something that must be converted to be able to run this on NANO 33 BLE Sense?

Any help would be great!

Welcome to the forum

Please post the full error message copied from the IDE using the "Copy error message" button and post it here in code tags

1 Like

Thanks, try this again.

C:\Users\cwikman\Documents\Arduino\LineupR2\LineupR2.ino: In function 'void loop()':
C:\Users\cwikman\Documents\Arduino\LineupR2\LineupR2.ino:149:20: error: invalid conversion from 'const char*' to 'int' [-fpermissive]
         inBuffer = ""; // clear this immediately the '0' has been used
                    ^~
C:\Users\cwikman\Documents\Arduino\LineupR2\LineupR2.ino:175:20: error: invalid conversion from 'const char*' to 'int' [-fpermissive]
         inBuffer = ""; // clear this immediately the '1' has been used
                    ^~
C:\Users\cwikman\Documents\Arduino\LineupR2\LineupR2.ino:201:20: error: invalid conversion from 'const char*' to 'int' [-fpermissive]
         inBuffer = "";
                    ^~
C:\Users\cwikman\Documents\Arduino\LineupR2\LineupR2.ino:227:20: error: invalid conversion from 'const char*' to 'int' [-fpermissive]
         inBuffer = "";
                    ^~
C:\Users\cwikman\Documents\Arduino\LineupR2\LineupR2.ino:253:20: error: invalid conversion from 'const char*' to 'int' [-fpermissive]
         inBuffer = "";
                    ^~
C:\Users\cwikman\Documents\Arduino\LineupR2\LineupR2.ino:279:20: error: invalid conversion from 'const char*' to 'int' [-fpermissive]
         inBuffer = "";
                    ^~
C:\Users\cwikman\Documents\Arduino\LineupR2\LineupR2.ino:305:20: error: invalid conversion from 'const char*' to 'int' [-fpermissive]
         inBuffer = "";
                    ^~
C:\Users\cwikman\Documents\Arduino\LineupR2\LineupR2.ino:331:20: error: invalid conversion from 'const char*' to 'int' [-fpermissive]
         inBuffer = "";
                    ^~
C:\Users\cwikman\Documents\Arduino\LineupR2\LineupR2.ino:357:20: error: invalid conversion from 'const char*' to 'int' [-fpermissive]
         inBuffer = "";
                    ^~
C:\Users\cwikman\Documents\Arduino\LineupR2\LineupR2.ino:383:20: error: invalid conversion from 'const char*' to 'int' [-fpermissive]
         inBuffer = "";
                    ^~

exit status 1

Compilation error: invalid conversion from 'const char*' to 'int' [-fpermissive]

This doesn't really make sense:

What do you think this code should be doing?

You have defined inBuffer to be an int - so assigning a string literal to it really makes no sense!

It looks like the AVR compiler let you get away with it, but the ARM compiler won't have it.

As the message says, you can't just convert a thing of type const char* (which is what a string literal is) to an int (which is what your inBuffer is).

awneil, I am just using code that I found in an online tutorial that I have tweaked and expanded. That line is part of that original code. As I understand it, that line (lines) clears the buffer for the next run of the loop. Probably other ways of doing that but I am trying to learn as I go. My knowledge is not much better than zero...

As a complete noob, I came to this forum for help with what I assumed was an UNO - Nano compatibility issue not thinking it was just a code issue. Now I have a direction I can take.

Thanks awneil.

1 Like

Sadly, there is a lot of bad code out there - and this is some of it! :frowning_face:

Yes, that looks like the intent - but that's not the way to do it!

Probably should be

inBuffer = 0; // clear the buffer

Perhaps you could feed back to the author of the tutorial?

Something so simple...
Perhaps the author of that tutorial was hopeful their students/audience would figure out the proper way on their own.

Thanks again.

1 Like

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