I recently go interested in Arduino and decided to make an ambitious project considering how new I am to all of it. The whole project is to measure the weight of an object from a robot arm using torque equilibrium, and output its mass on an lcd, something like a manual scale to measure your weight. The structural is all complete.
The first problem I had was with the lcd, (it's still a problem but ive encounter another bigger one) it didn't display any characters... But that is for its own discussion and will not be brought up here.
The bigger problem I had was with the stepper motors. I have extracted a part of my bigger and ongoing code (I'm not 100% finished, due to this problem) and tried to run that piece individually.
As soon as I turn the power,
1st: I hear a crackling sound.
2nd: the motor seems to be moving back and forth (maybe a dozen or more of steps) at the same time as the crackling sound.
3rd: when I press the button "up" (in the code below), nothing apparent happens, as if it's ignoring the input.
I doubt the problem is in the wiring of the controller because i triple check it with a multimeter. I also rebuilt the board that holds the A4988 drivers, from a cnc milled PCB to prototyping perf board. I tried disconnecting pins RESET and SLEEP, but when I do, nothing happens. As in the motor doesn't move at all.
I tested one example from the AccelStepper library, and it worked fine (the one that sets random values).
After that, I figured that the problem might be the code.
The board I'm using is a mega 2560 (not Arduino brand).
My questions are:
Is there any wrong with my code?
What might be a solution?
Any help is appreciated.
Here is the code:
#include <AccelStepper.h>
#include <MultiStepper.h>
#define stepY 42
#define dirY 44
#define up 50
int upState;
AccelStepper stepper(1, stepY, dirY);
void setup() {
pinMode(up, INPUT);
stepper.setMaxSpeed(1000);
stepper.setAcceleration(1000);
}
void loop() {
upState = digitalRead(up);
if (upState==HIGH){
for (int q = 0; q < 1000 && q > 0; q += 50){
stepper.moveTo(q);
}
}
stepper.run();
}