Hello
I'm having problems programming since I'm sort of in the basics.
I have read the examples and as much as I could I pseudo programmed the code bellow, but need guidance on activating the motor with micro stepping and for as long as each button is pressed.
Must also have variable motor speed and variable retraction speed.
I semi programmed a code from another library that is poorly documented but has to do with drivers
I have already done and designed the mechanical part 3d Printed and I'm willing to share the project with the community when finished.
The idea is to use a nema motor for dispensing the fluid but use as less possible mechanical parts like couplings or threaded rods.
Many projects are based on the hobby 28BYJ-48 motor and the ULN2003A driver
I want to do mine with a display, and a nema and either A4988 or DRV8825 driver with Microstepping since at full steps the motor heats a lot and yes I have calibrated the current of the driver for the motor.
So far I have programmed this:
/*
* SOLDER PASTE DISPENSER WITH VARIABLE SPEED AND RETRACTIONS
* MOTOR USED NEMA14
* DRIVER USED DRV8825 AND MUST BE ABLE TO USE MICROSTEPPING
* USER CAN BE ABLE TO SELECT THE SPEED OF THE MOTOR AND EXTRUDE PASTE BASED ON THHAT VALUE
* ALSO MUST BE ABLE TO READ THE RECTRACTION SPEED AND MOVE THE MOTOR BACKWARDS BASED ON THE RETRACTION SPEED
* IF THE PROCESS OF EXTRUDE AND RETRACT IS INVERTED MUST BE ABLE TO USE AS A PICK AND PLACE
* ALL DISPLAY ON AN LCD 16*2
* FAST SPEED TO LOAD OR UNLOAD THE PLUNGER
* SLOW SPEEDS TO EXTRUDE PASTE
* RETRACTION TO AVOID SPILLS
*
*/
#include <LiquidCrystal_I2C.h> // Libreria que controla el I2C
#include<Wire.h>
LiquidCrystal_I2C lcd(0x27,16,2); //Direccion del I2c del LCD si no funciona este codigo usar un i2c Scanner
//Conexiones:
//5V I2C al 5V Arduino
//GND I2C al GND Arduino
//SDA I2C al A4 Arduino
//SCL I2C al A5 del Arduino
#include <AccelStepper.h>
AccelStepper stepper (1, 3, 2); // pin 3 = step, pin 2 = direction
byte dirPin = 2;
byte stepPin = 3;
byte CW_Button = 8;
byte CCW_Button = 9;
byte Emergency_Button = 10;
int SPEED_PIN = A3;
int R_SPEED_PIN = A0;
#define MAX_SPEED 1000
#define MIN_SPEED 0.1
boolean buttonpressed = false;
unsigned long curMillis;
unsigned long prevStepMillis = 0;
void setup() {
Serial.begin(9600);
lcd.init();
lcd.backlight();
lcd.clear();
lcd.setCursor(2,0);
lcd.print("Starting...."); // Initial msg
delay(3000);
pinMode(dirPin, OUTPUT);
pinMode(stepPin, OUTPUT);
pinMode(CW_Button, INPUT_PULLUP);
pinMode(CCW_Button, INPUT_PULLUP);
pinMode(Emergency_Button, INPUT_PULLUP);
}
void loop() {
curMillis = millis();
readButtons();
readMotorSpeed();
readRetractSpeed();
movestepper();
}
void readButtons() {
if (digitalRead(CW_Button) == 0) {
// Here need to know the code for the motor to continuosly move FOWARD based if the button is pressed, with a speed
// read from the read speed function
// when the motor is released must retract based on the reading of the retract speed function
// I tryed to understand the library but I do not know how previously I used StepperDriver lib with some degree
// of success with microstepping since full steps heats my motor pretty much and yes the current already calibrated
stepper.setSpeed(50);
int SpeedValue = map(analogRead(SPEED_PIN), 0, 1023, 0, 1000);
Serial.println(SpeedValue);
stepper.setSpeed(SpeedValue);
int a =0;
a=SpeedValue;
stepper.setSpeed(a);
}
if (digitalRead(CCW_Button) == 0) {
// Here need to know the code for the motor to continuosly move Backwards based if the button is pressed, with a speed
// read from the read speed function
// when the motor is released must retract based on the reading of the retract speed function
}
if ((digitalRead(CW_Button) == 0) || (digitalRead(CCW_Button) == 0) && (digitalRead(Emergency_Button) == 0) ){
// Here if either supply or retract button is pressed and the emergency button is pressed, stop the motor
digitalWrite(stepPin, LOW);
}
}
void readMotorSpeed() {
int SpeedValue = map(analogRead(SPEED_PIN), 0, 1023, 0, 1000);
Serial.println(SpeedValue);
stepper.setSpeed(SpeedValue);
int a =0;
a=SpeedValue;
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Speed ");
lcd.setCursor(7,0);
lcd.print(a);
delay(100);
}
void readRetractSpeed() {
int retractValue = map(analogRead(R_SPEED_PIN), 0, 1023, 0, 1);
Serial.println(retractValue);
stepper.setSpeed(retractValue);
float b =0;
b=retractValue;
lcd.clear();
lcd.setCursor(0,1);
lcd.print("RSpeed ");
lcd.setCursor(8,1);
lcd.print(b,3);
delay(100);
}
Thank you for your help