But did you get the motor running how you wanted it to run? The last post I read about the motor is that it does something weird at startup. I would get the motor solved before adding the encoder.
yea the nema17 does do what I expect when I upload code
Ok good.
Does your encoder have a datasheet? You can definitely use the breadboard to distribute power as mentioned in post 18.
But, if your components have datasheets, get in the habit of checking them, including the power source. In post 18, your picture shows using the UNO as a power source. Be careful that your components don't overload it as well.
Your topic is not specific to the Uno R3 and does not indicate a problem with the Uno R3. For that reason it has been moved to a more suitable location on the forum.
my motor makes loud noises and kinda rotates randomly
I suggest you first make it work without the encoder. If you can't the encoder won't help.
I think you are right, so my project is a inverted pendulum, here is my assembly
I ran some tests with moving the motor without the encoder with the accelstepper library. here is my code below.
I tried this code just to move the cart back and forth and basically when I enter a value in the serial monitor or the cart runs outside the safety range (I'm using the motors step count to keep track of linear position of cart) motor stops. I wanted to test how fast I could run the motor, at low speeds it works, but when I increase the speed variable to make it go faster, the motor behaves weirdly such as stalling or cart moving in the opposite direction.
My Vref for my 1A nema17 and a498 driver with r100 should be 0.8, I have my driver right now at 0.62, and I'm using a 12 volt 5 amp power supply. I'm considering using a 24 volt power and increasing the Vref from 0.62 to 0.8 to see if that works but any additional advice is always appreciated
#include <AccelStepper.h>
const int step_pin = 4;
const int dir_pin = 5;
const int ms1 = 8;
const int ms2 = 7;
const int ms3 = 6;
AccelStepper stepper(1,step_pin,dir_pin);
const float conversion = 0.2; //steps to arc length (mm)
const float safe_range = 300.0; //mm
bool run = true; //flag variable to turn off
float xmax = 150.0;
float xmin = 0.0;
int maxspeed = 3000;
int speed = 1000;
void setup()
{
Serial.begin(9600);
//setup microstepping
pinMode(ms1,OUTPUT);
pinMode(ms2,OUTPUT);
pinMode(ms3,OUTPUT);
digitalWrite(ms1,LOW);
digitalWrite(ms2,LOW);
digitalWrite(ms3,LOW);
//setup speed + acceleration
stepper.setMaxSpeed(maxspeed);
stepper.setSpeed(speed);
delay(2000);
}
void loop()
{
float step = stepper.currentPosition();
float s = step*conversion;
if ((Serial.available() > 0) || (absolute_value(s) >= safe_range))
{
run = false;
}
if (run == true)
{
stepper.runSpeed();
float step = stepper.currentPosition();
float s = step\*conversion;
if (s >= xmax)
{
stepper.setSpeed(-speed);
}
else if (s <= xmin)
{
stepper.setSpeed(speed);
}
}
}
float absolute_value(float value)
{
if (value < 0.0)
{
value = -value;
}
return value;
}
