Hello everyone. Has anyone used mobatools to send a stepper to home on boot up? If so could you please share your code. I have used accelstepoer and the while loop before but having trouble with mobatools. Thank you.
You're into a niche there. Is there a mobatools forum?
If you expect a preprogrammed function reference() this does not exist.
The basic principle is
drive steppermotor towards reference-switch and check permanently if refswitch changes
setSpeed(slowerSpeed)
Then
You can use either the function rotate(1)
Or function doSteps(maxPossibleSteps)
and then execute a while loop that checks the reference-switch
or a while loop that does a single step then check ref-switch
Best regards Stefan
Can you please post your attempt? And did you look at the examples? There is an example with referencing the stepper.
or an online simulation
where the limit switches are simulated by the actual position - that's where you would integrate your digitalRead()
void simLimitSwitches(void){
limitHigh = myStepper.currentPosition() > 150 ? LOW : HIGH ;
limitLow = myStepper.currentPosition() < 50 ? LOW : HIGH ;
digitalWrite(LED_LOW,limitLow == LOW ? HIGH : LOW ); // my version to respect types
digitalWrite(LED_HIGH,limitHigh == LOW ? HIGH : LOW ); // my version to respect types
}
Hello again, thank you all for the help. Using the example that you sent the link for I was able to integrate the homeing of my plateStepper. I have attached my full code. Next question, when I start up my project, about half way through the bootup, my plate stepper moves on its own. It was doing this before the home code was added and that is the reason i added the home code. What could be going on? Any ideas on how to stop this?
#include <MultiStepper.h>
#include <MCUFRIEND_kbv.h>
#include <Elegoo_GFX.h> // Core graphics library
#include <Elegoo_TFTLCD.h> // Hardware-specific library
#include <TouchScreen.h> // Touch Support
#include <AccelStepper.h>
#include <Adafruit_GFX.h>
#include <MobaTools.h>
#include <Stepper.h>
// Number of steps per output rotation
const int stepsPerRevolution5 = 800;
// Create Instance of Stepper library
Stepper myStepper5(stepsPerRevolution5, 17, 18, 19, 20);
//const int Relay = 4;
const int ENB_PIN = 18; // the Arduino pin connected to the EN1 pin L298N
const int IN3_PIN = 19; // the Arduino pin connected to the IN1 pin L298N
const int IN4_PIN = 20; // the Arduino pin connected to the IN2 pin L298N
const byte motorInterfaceType = 1;
const byte dirPin = A9; //Head
const byte stepPin = A10;
const byte dirPin1 = 48; //Thickness
const byte stepPin1 = 49;
const byte dirPin2 = 12; //Blade
const byte stepPin2 = 13;
const byte LimitPin = 22;
const byte refPin = 47; // Input für Referenzpunktschalter
const byte atRefpoint = HIGH;
uint16_t identifier; //Store Screen Identifier
const int led1 = 21;
const int led2 = 23;
int oldSpeed = 0;
int steps = 0;
int pos = 0;
int stepsPerRevolution = 11000; //HEAD
int stepsPerRevolution2 = 500; //THICK
int stepsPerRevolution3 = 900; //MEDIUM
int stepsPerRevolution4 = 1300; //THIN
int Distance = 0;
int count = 0;
MoToStepper plateStepper(200, STEPDIR);
MoToStepper cutterStepper(600, STEPDIR); // Don't know steps/rev for this stepper
MoToStepper thicknessStepper(400, STEPDIR);
AccelStepper stepper1 = AccelStepper(motorInterfaceType, stepPin1, dirPin1); //Attaches A4988 driver to Accel Library
#define TS_MINX 920
#define TS_MINY 120
#define TS_MAXX 150
#define TS_MAXY 940
#define YP A3 // must be an analog pin, use "An" notation!
#define XM A2 // must be an analog pin, use "An" notation!
#define YM 9 // can be a digital pin
#define XP 8 // can be a digital pin
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
Elegoo_GFX_Button buttons; //Button object declaration
#define BLUEBAR_MINX 180
#define BAR_MINY 30
#define BAR_HEIGHT 250
#define BAR_WIDTH 30
#define BLACK 0x0000 // macros for color (16 bit)
#define NAVY 0x000F
#define DARKGREEN 0x03E0
#define DARKCYAN 0x03EF
#define MAROON 0x7800
#define PURPLE 0x780F
#define OLIVE 0x7BE0
#define LIGHTGREY 0xC618
#define DARKGREY 0x7BEF
#define BLUE 0x001F
#define GREEN 0x07E0
#define CYAN 0x07FF
#define RED 0xF800
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#define ORANGE 0xFD20
#define GREENYELLOW 0xAFE5
#define PINK 0xF81F
#define LCD_CS A3 // Chip Select goes to Analog 3
#define LCD_CD A2 // Command/Data goes to Analog 2
#define LCD_WR A1 // LCD Write goes to Analog 1
#define LCD_RD A0 // LCD Read goes to Analog 0
#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin
Elegoo_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
void setup() {
// set the speed at 60 rpm:
myStepper5.setSpeed(100);
// initialize the serial port:
Serial.begin(9600);
tft.begin(0x9341); // Initialise LCD
uint16_t ID = tft.readID();
tft.setRotation(2);
tft.begin(tft.readID());
tft.setRotation(2);
tft.fillScreen(BLACK);
tft.setTextSize(3);
tft.setTextColor(WHITE);
tft.setCursor(10, 10);
tft.println("Thermo-Slice");
tft.setCursor(50, 50);
tft.println("Deluxe");
tft.setCursor(40, 100);
tft.setTextSize(2);
tft.println("Invented By:");
tft.setCursor(30, 120);
tft.println("Richard Potter");
tft.setTextSize(1);
tft.setCursor(40, 200);
tft.println("Provisional Patented 2023");
tft.drawRect(0, 260, 244, 68, YELLOW);
tft.fillRect(0, 256, 240, 64, BLUE);
tft.setCursor(10, 270);
tft.setTextSize(3);
tft.println("Loading.....");
delay(4000); //End of Boot up screen.
for (int i; i < 250; i++) {
tft.fillRect(BAR_MINY - 0, BLUEBAR_MINX, i, 20, GREEN);
delay(0.000000000000000000000000000000000000000000000000001);
}
tft.setRotation(2);
tft.fillRect(0, 0, 240, 64, WHITE); // First WHITE Rectange
tft.fillRect(0, 64, 240, 64, BLUE); // Second YELLOW Rectangle
tft.fillRect(0, 128, 240, 64, ORANGE); // Third RED Rectangle
tft.fillRect(0, 192, 120, 64, GREEN); // Fourth MAGENTA Rectangle
tft.fillRect(120, 192, 120, 64, YELLOW); // Fourth MAGENTA Rectangle
tft.fillRect(0, 256, 240, 64, PINK); // Fith ORANGE Rectangle
//tft.fillRect(0,240, 240, 130, YELLOW);
tft.drawRect(0, 0, 240, 64, BLACK); // Black borders to the rectangles
tft.drawRect(0, 64, 240, 64, BLACK); // Black borders to the rectangles
tft.drawRect(0, 128, 240, 64, BLACK); // Black borders to the rectangles
tft.drawRect(0, 192, 120, 64, BLACK); // Black borders to the rectangles
tft.drawRect(120, 192, 120, 64, BLACK); // Black borders to the rectangles
tft.drawRect(0, 256, 240, 64, BLACK); // Black borders to the rectangles
tft.setTextColor(BLACK); // Set Text Proporties
tft.setTextSize(2);
tft.setCursor(55, 90);
tft.println("Medium Slice"); // Write Text on LCD
tft.setTextSize(2);
tft.setCursor(55, 150);
tft.println("Thick Slice ");
tft.setTextSize(2);
tft.setCursor(10, 215);
tft.println(" SAUSAGE ");
tft.setCursor(130, 215);
tft.println(" CHEESE ");
tft.setTextSize(2);
tft.setCursor(30, 280);
tft.println("Cheese & Sausage");
tft.setTextColor(BLACK);
tft.setTextSize(2);
tft.setCursor(70, 20);
tft.println("Thin Slice ");
tft.setTextColor(BLACK);
tft.setTextSize(3);
tft.setCursor(45, 35);
while (digitalRead(LimitPin)) {
digitalWrite(dirPin1, LOW);
digitalWrite(stepPin1, HIGH);
delayMicroseconds(500);
digitalWrite(stepPin1, LOW);
delayMicroseconds(500);
}
while (!digitalRead(LimitPin)) {
digitalWrite(dirPin1, HIGH);
digitalWrite(stepPin1, LOW);
delayMicroseconds(500);
digitalWrite(stepPin1, HIGH);
delayMicroseconds(500);
}
plateStepper.attach(stepPin, dirPin); //HEAD
cutterStepper.attach(stepPin2, dirPin2); //Blade
thicknessStepper.attach(stepPin1, dirPin1); //Thickness
pinMode(LimitPin, INPUT);
pinMode(refPin, INPUT);
plateStepper.setSpeedSteps(20000); // = 12500 steps/sec
plateStepper.setRampLen(250); // acceleration: steps until full speed is reached
cutterStepper.setSpeedSteps(20000); // adjust for your needs
cutterStepper.setRampLen(50); // acceleration: steps until full speed is reached
thicknessStepper.setSpeedSteps(15000);
thicknessStepper.setRampLen(50);
Serial.begin(9600);
digitalRead(LimitPin);
//digitalRead(refPin);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(ENB_PIN, INPUT);
pinMode(IN3_PIN, OUTPUT);
pinMode(IN4_PIN, OUTPUT);
toRefPoint();
}
void toRefPoint() {
if (digitalRead(refPin) != atRefpoint) {
plateStepper.setSpeedSteps(20000, 1000);
plateStepper.rotate(-1);
while (digitalRead(refPin) != atRefpoint)
;
}
digitalWrite(LED_BUILTIN, digitalRead(refPin));
plateStepper.rotate(0);
while (plateStepper.moving())
;
plateStepper.setSpeedSteps(20000);
plateStepper.setRampLen(0);
plateStepper.rotate(1);
while (digitalRead(refPin) == atRefpoint)
;
digitalWrite(LED_BUILTIN, digitalRead(refPin));
plateStepper.rotate(0);
while (plateStepper.moving())
;
plateStepper.setZero();
plateStepper.setSpeed(10000);
plateStepper.setRampLen(250); // Rampenlänge 100 Steps bei 20U/min
oldSpeed = 0; // Damit Speedwert vom Poti wieder übernommen wird
}
void loop() {
TSPoint p = ts.getPoint();
if (p.z > 10 && p.z < 1000) { // Pressure setting
p.x = map(p.x, TS_MINX, TS_MAXX, tft.width(), 0);
p.y = map(p.y, TS_MINY, TS_MAXY, tft.height(), 0);
if ((p.x > 0 && p.x < 240) && (p.y > 0 && p.y < 142)) { //Cheese and Sausage
//for (int i = 0; i < 5; i++)
digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
// step one revolution in one direction:
Serial.println("clockwise");
myStepper5.step(-stepsPerRevolution5 * 1.8);
delay(1000);
// step one revolution in the other direction:
Serial.println("counterclockwise");
myStepper5.step(stepsPerRevolution5 * 1.8);
delay(1000);
plateStepper.writeSteps(-stepsPerRevolution); // Do one turn
cutterStepper.rotate(1); // rotate until stopped
while (plateStepper.moving())
; // wait until one turn is done
cutterStepper.rotate(0); // stop cutterStepper
delay(500);
if (plateStepper.readSteps() == -stepsPerRevolution)
; //{
plateStepper.writeSteps(0); // Back one turn to starting position
cutterStepper.rotate(1); // rotate until stopped
while (plateStepper.moving())
; // wait until one turn is done
cutterStepper.rotate(0); // stop cutterStepper
digitalWrite(led2, LOW);
digitalWrite(led1, HIGH);
}
if ((p.x > 120 && p.x < 240) && (p.y > 142 && p.y < 187)) { //Sausage
digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
// step one revolution in one direction:
Serial.println("clockwise");
myStepper5.step(-stepsPerRevolution5 * 2);
delay(1000);
// step one revolution in the other direction:
Serial.println("counterclockwise");
myStepper5.step(stepsPerRevolution5 * 2);
delay(1000);
TSPoint p = ts.getPoint();
plateStepper.writeSteps(-stepsPerRevolution + 4500); // Do one turn
cutterStepper.rotate(1); // rotate until stopped
while (plateStepper.moving())
; // wait until one turn is done
cutterStepper.rotate(0); // stop cutterStepper
delay(500);
if (plateStepper.readSteps() == -stepsPerRevolution + 175)
;
plateStepper.writeSteps(0); // Back one turn to starting position
cutterStepper.rotate(1); // rotate until stopped
while (plateStepper.moving())
; // wait until one turn is done
cutterStepper.rotate(0); // stop cutterStepper
digitalWrite(led2, LOW);
digitalWrite(led1, HIGH);
}
if ((p.x > 0 && p.x < 120) && (p.y > 142 && p.y < 187)) { //Cheese or Fourth Rect
digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
TSPoint p = ts.getPoint();
plateStepper.writeSteps(-stepsPerRevolution); // Do one turn
cutterStepper.rotate(1); // rotate until stopped
while (plateStepper.moving())
; // wait until one turn is done
cutterStepper.rotate(0); // stop cutterStepper
delay(500);
if (plateStepper.readSteps() == -stepsPerRevolution)
;
plateStepper.writeSteps(0); // Back one turn to starting position
cutterStepper.rotate(1); // rotate until stopped
while (plateStepper.moving())
; // wait until one turn is done
cutterStepper.rotate(0); // stop cutterStepper
digitalWrite(led2, LOW);
digitalWrite(led1, HIGH);
}
if (p.y > 187 && p.y < 230) { //Third Rect
TSPoint p = ts.getPoint();
while (digitalRead(LimitPin)) { // Do this until the switch is activated
digitalWrite(dirPin1, LOW);
digitalWrite(stepPin1, HIGH);
delayMicroseconds(500);
digitalWrite(stepPin1, LOW);
delayMicroseconds(500);
}
while (!digitalRead(LimitPin)) { // Do this until the switch is not activated
digitalWrite(dirPin1, HIGH);
digitalWrite(stepPin1, LOW);
delayMicroseconds(500);
digitalWrite(stepPin1, HIGH);
delayMicroseconds(500);
}
for (int x = 0; x < stepsPerRevolution2; x++) {
digitalWrite(dirPin1, HIGH);
digitalWrite(stepPin1, HIGH);
delayMicroseconds(500);
digitalWrite(stepPin1, LOW);
delayMicroseconds(500);
}
}
if (p.y > 231 && p.y < 276) { //Second Rec
TSPoint p = ts.getPoint();
while (digitalRead(LimitPin)) { // Do this until the switch is activated
digitalWrite(dirPin1, LOW);
digitalWrite(stepPin1, HIGH);
delayMicroseconds(500);
digitalWrite(stepPin1, LOW);
delayMicroseconds(500);
}
while (!digitalRead(LimitPin)) { // Do this until the switch is not activated
digitalWrite(dirPin1, HIGH);
digitalWrite(stepPin1, LOW);
delayMicroseconds(500);
digitalWrite(stepPin1, HIGH);
delayMicroseconds(500);
}
for (int x = 0; x < stepsPerRevolution3; x++) {
digitalWrite(dirPin1, HIGH);
digitalWrite(stepPin1, HIGH);
delayMicroseconds(500);
digitalWrite(stepPin1, LOW);
delayMicroseconds(500);
}
}
if (p.y > 276 && p.y < 320) { // First Rect
TSPoint p = ts.getPoint();
while (digitalRead(LimitPin)) { // Do this until the switch is activated
digitalWrite(dirPin1, LOW);
digitalWrite(stepPin1, HIGH);
delayMicroseconds(500);
digitalWrite(stepPin1, LOW);
delayMicroseconds(500);
}
while (!digitalRead(LimitPin)) { // Do this until the switch is not activated
digitalWrite(dirPin1, HIGH);
digitalWrite(stepPin1, LOW);
delayMicroseconds(500);
digitalWrite(stepPin1, HIGH);
delayMicroseconds(500);
}
for (int x = 0; x < stepsPerRevolution4; x++) {
digitalWrite(dirPin1, HIGH);
digitalWrite(stepPin1, HIGH);
delayMicroseconds(500);
digitalWrite(stepPin1, LOW);
delayMicroseconds(500);
}
}
}
}Use code tags to format code for the forum
Please do us a favor and include your code in code-tags.
Your sketch is very confusing. You include 3 different stepper libraries and at some place you even create your steps directly in the sketch. What is the reason? You should stay with one library.
I know I should have however, this has evolved over time and I am still new at this so I have been using revamped and help from you all. I would love to re -write this with one library but not sure if I have the skills. I will try. Thanks again.
Richard Potter
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.