Hello,
While I have successfully used AccelStepper library to move 3 stepper motors, when I use it on Arduino Cloud it seems that the motors move very slow and the speed given from the slider I am using, is not set to the motors the command stepperX.setMaxSpeed(speedX); fails to set the desired speed.
I am attaching the code I use. Any ideas ?
#include <WiFiNINA.h>
#include <AccelStepper.h>
/*
Sketch generated by the Arduino IoT Cloud Thing "Untitled"
https://create.arduino.cc/cloud/things/069dba6c-43b5-42cc-afd0-e62bf37878a1
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
int speedX;
int stepsX;
int stepsY;
bool moveX;
bool moveY;
Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
which are called when their values are changed from the Dashboard.
These functions are generated with the Thing and added at the end of this sketch.
*/
#include "thingProperties.h"
#include <EEPROM.h>
#include <Bounce2.h>
#define dirPinX 8
#define stepPinX 9
#define dirPinY 7
#define stepPinY 6
#define dirPinZ 4
#define stepPinZ 5
// Define the steppers and pins that are used
AccelStepper stepperX(1, stepPinX, dirPinX);
AccelStepper stepperY(1, stepPinY, dirPinY);
AccelStepper stepperZ(1, stepPinZ, dirPinZ);
int x;
// Timing variables
unsigned long lastUpdateX = 0, lastUpdateY = 0, lastUpdateZ = 0;
const unsigned long updateInterval = 50; // 50ms for smooth updates
void setup() {
// Initialize serial and wait for port to open:
Serial.begin(9600);
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
delay(1500);
// Defined in thingProperties.h
initProperties();
pinMode(LED_BUILTIN, OUTPUT);
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
ArduinoCloud.printDebugInfo();
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
pinMode(stepPinX,OUTPUT);
pinMode(dirPinX,OUTPUT);
pinMode(stepPinY,OUTPUT);
pinMode(dirPinY,OUTPUT);
stepperX.setMaxSpeed(10000);
stepperY.setMaxSpeed(10000);
stepperZ.setMaxSpeed(10000);
stepperX.setAcceleration(8000);
stepperY.setAcceleration(8000);
stepperZ.setAcceleration(8000);
stepperX.disableOutputs();
stepperY.disableOutputs();
stepperZ.disableOutputs();
}
void loop() {
ArduinoCloud.update();
setDebugMessageLevel(2);
if (moveX){
stepperX.run();
}
if(moveY){
stepperY.run();
}
stepperZ.run();
}
/*
Since PushbuttonX is READ_WRITE variable, onPushbuttonXChange() is
executed every time a new value is received from IoT Cloud.
*/
void onPushbuttonXChange() {
int x;
}
void onRunXChange() {
// Add your code here to act upon RunX change
}
/*
Since StepsX is READ_WRITE variable, onStepsXChange() is
executed every time a new value is received from IoT Cloud.
*/
void onStepsXChange() {
Serial.println(stepsX);
}
/*
Since StepsY is READ_WRITE variable, onStepsYChange() is
executed every time a new value is received from IoT Cloud.
*/
void onStepsYChange() {
// Add your code here to act upon StepsY change
}
void onMoveXChange() {
if(moveX){
unsigned long currentMillis = millis();
ArduinoCloud.update();
digitalWrite(LED_BUILTIN, HIGH);
stepperX.enableOutputs();
stepperX.setMaxSpeed(speedX);
Serial.println(speedX);
//stepperX.setSpeed(10000);
stepperX.move(stepsX);
} else {
stepperX.stop();
stepperX.disableOutputs();
digitalWrite(LED_BUILTIN, LOW);
}
}
void onMoveYChange() {
if(moveY) {
unsigned long currentMillis = millis();
ArduinoCloud.update();
digitalWrite(LED_BUILTIN, HIGH);
stepperY.enableOutputs();
stepperY.setMaxSpeed(5000);
//stepperY.setSpeed(1000);
stepperY.move(stepsY);
} else {
stepperY.stop();
stepperY.disableOutputs();
digitalWrite(LED_BUILTIN, LOW);
}
}
void onSpeedXChange() {
Serial.println(speedX);
}