guys my name is bruce and i have been working in a project where i have a slider with a belt and a nema 17 motor. i got it to work with no problem but as i start addig weight to the slider the motor starts jumping i think. im not sure but i think it needs more torque.
how can i do that . ?
im going to pase my sketch here please can someone quide me in how to control this better . thank you.
#define SMOOTHSTEP(x) ((x) * (x) * (3 - 2 * (x)))
#include <Wire.h>
#include <stepperUNO.h>
stepMOTOR motor1;
#include <Pushbutton.h>
Pushbutton button1(6);
Pushbutton button2(10);
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
uint8_t backslash[8] = {
0b00000,
0b10000,
0b01000,
0b00100,
0b00010,
0b00001,
0b00000,
0b00000
};
char spinningTop[] = {'/', '-', 0, '|'};
uint8_t k;
float v = 0.0;
float X = 0.0;
float travel = 9000.0;
float ramp = 300.0;
float motorSpeed = 1500;
int motorSpeedMin = 1500;
int motorSpeedDef = 285; // control the speed of the motor
int motorSpeedMax = 200;
int motorRamp=550;
int spraySpeed=3;
String output = "";
int waitTime = 60;
int lcd_key = 0;
int adc_key_in = 0;
#define btnRIGHT 0
#define btnUP 1
#define btnDOWN 2
#define btnLEFT 3
#define btnSELECT 4
#define btnNONE 5
int read_LCD_buttons(){
adc_key_in = analogRead(0);
if (adc_key_in > 1000) return btnNONE;
if (adc_key_in < 50) return btnRIGHT;
if (adc_key_in < 250) return btnUP;
if (adc_key_in < 450) return btnDOWN;
if (adc_key_in < 650) return btnLEFT;
if (adc_key_in < 850) return btnSELECT;
return btnNONE;
}
const int stepPin = 13;
const int dirPin = 12;
const int enablePin = 11;
void setup() {
motor1.begin(0x4);
motor1.enable();
int waitSelect = 0;
Serial.begin(9600);
pinMode(enablePin, OUTPUT);
k = 0;
pinMode(stepPin,OUTPUT);
pinMode(dirPin,OUTPUT);
lcd.begin(16,2);
lcd.createChar(0, backslash);
lcd.setCursor(0,0);
lcd.print("welcome");
delay(1000);
lcd.setCursor(0,1);
lcd.print("Ready :3");
digitalWrite(enablePin,HIGH);
while(waitSelect==0) {
lcd_key = read_LCD_buttons();
switch (lcd_key){
case btnRIGHT:{
if (spraySpeed < 8) {
spraySpeed = spraySpeed + 1;
motorSpeedMax = motorSpeedMax + 200;
}
delay(100);
break;
}
case btnLEFT:{
if (spraySpeed > 3) {
spraySpeed = spraySpeed - 1;
motorSpeedMax = motorSpeedMax - 200;
}
delay(100);
break;
}
case btnUP:{
waitTime = waitTime + 1;
delay(100);
break;
}
case btnDOWN:{
waitTime = waitTime - 1;
delay(100);
break;
}
case btnSELECT:{
waitSelect = 1;
break;
}
case btnNONE:{
break;
}
}
lcd.setCursor(8,1);
lcd.print(String(spraySpeed));
lcd.setCursor(11,1);
lcd.print(":"+ String(waitTime));
lcd.setCursor(5,1);
lcd.write(spinningTop[k%4]);
k = (k+1) & 0b11;
delay(100);
}
lcd.setCursor(0,1);
lcd.write(" ");
digitalWrite(enablePin,LOW);
}
void loop() {
int waits[300];
for(int x = 0; x < ramp; x++) {
v = x / ramp;
v = SMOOTHSTEP(v);
X = (motorSpeedDef * v) + (motorSpeedMin * (1.0 - v));
waits[x]=X;
}
//digitalWrite(dirPin,HIGH);
motorSpeed = motorSpeedDef;
int countdown = waitTime;
for(int x = 0; x < 300; x++) {
motor1.setDirection(true);
motor1.step();
delayMicroseconds(waits[x]);
}
for(int x = 0; x < travel-600; x++) {
motor1.step();
delayMicroseconds(motorSpeedDef);
}
for(int x = 299; x >= 0; x--) {
motor1.step();
delayMicroseconds(waits[x]);
}
while(countdown>0) {
countdown -= 1;
lcd.setCursor(11,1);
output = String(countdown);
if (output.length()<2) {
output = "0"+output;
}
lcd.print(":"+ output);
if (countdown > 0) {
delay(1000);
}
}
motor1.setDirection(false);
motorSpeed=motorSpeedDef;
for(int x = 0; x < 300; x++) {
motor1.step();
delayMicroseconds(waits[x]);
}
for(int x = 0; x < travel-600; x++) {
motor1.step();
delayMicroseconds(motorSpeedMax);
}
for(int x = 299; x >= 0; x--) {
motor1.step();
delayMicroseconds(waits[x]);
}
delay(1000);
setup();
}
slider.txt (4.47 KB)