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!