hello i am new to this form but pretty expired with Arduino., but i can not solve the flowing problem. i am ting to make an rc sub with a stepper motor and an Arduino reading pwm signals but the values that i read are jitering +-2 or 3 and so the stepper starts to jiter and over heats. can any one help me make the values more stable?here is the code.
#include <Stepper.h>
#define RCPin 2
Stepper myStepper(200, 12, 11, 10, 9);
int ServoAngle;
volatile long StartTime = 0;
volatile long CurrentTime = 0;
volatile long Pulses = 0;
int PulseWidth = 0;
int oldPulseWidth;
int StepperPos;//where the stepper currently is
int preStepperPosn;//where the stepper should go to
void setup() {
myStepper.setSpeed(150);
Serial.begin(9600);
pinMode(RCPin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(RCPin), PulseTimer, CHANGE);
attachInterrupt(digitalPinToInterrupt(RCPin), PulseTimer, CHANGE);
}
void loop() {
if (Pulses < 2000) {
PulseWidth = Pulses;
}
PulseWidth = constrain(PulseWidth, 564, 1976);
// add some deadband
if (PulseWidth < (oldPulseWidth - 1) || PulseWidth > (oldPulseWidth + 1)) {
oldPulseWidth = PulseWidth;
StepperPos = map (oldPulseWidth, 564, 1976, 0, 102);
if (StepperPos != 102) {
Serial.print("stepper position");
Serial.print(StepperPos);
Serial.println(":)");
preStepperPosn = StepperPos;
}
}
}
void PulseTimer() {
CurrentTime = micros();
if (CurrentTime > StartTime) {
Pulses = CurrentTime - StartTime;
StartTime = CurrentTime;
}
}
i dont have the stepper cod yet
from ChatGPT?
Steppers don't overheat due to running what so ever. They overheat due to the driver using too high current.
Please post links to the datasheet for the steppers, the driver and schematics.
the motor controller is a regular l298n, and the stepper is a KP35FM2-035
no made it myself
how you can write it better?