Plotter XY and Arduino


#1

Hello,
I’m a French student in High School, and I have some problems with the libraries of Makeblock.
I need to make the plotter table move in two axis X and Y.
So I used the example of the "SerialControlStepper"
This is the code :
#include <AccelStepper.h>

#include <Makeblock.h>
#include <SoftwareSerial.h>
#include <Wire.h>

int dirPin = mePort[PORT_1].s1;//the direction pin connect to Base Board PORT1 SLOT1
int stpPin = mePort[PORT_1].s2;//the Step pin connect to Base Board PORT1 SLOT2
AccelStepper stepper(AccelStepper::DRIVER,stpPin,dirPin);
int dirPin2 = mePort[PORT_2].s1;//the direction pin connect to Base Board PORT1 SLOT1
int stpPin2 = mePort[PORT_2].s2;//the Step pin connect to Base Board PORT1 SLOT2
AccelStepper stepper2(AccelStepper::DRIVER,stpPin2,dirPin2);

void setup()
{
Serial.begin(9600);
// Change these to suit your stepper if you want
stepper.setMaxSpeed(100000);
stepper.setAcceleration(200000);
stepper2.setMaxSpeed(100000);
stepper2.setAcceleration(200000);

}

void loop()
{
if(Serial.available())
{
char a = Serial.read();
switch(a)
{
case ‘0’:
stepper.moveTo(0);
break;
case ‘1’:
stepper.moveTo(12500);
break;
case ‘2’:
stepper.move(12500);
break;
case ‘3’:
stepper2.move(12500);
break;
case ‘4’:
stepper.move(-12500);
break;
case ‘5’:
stepper.move(-12500);
break;
case ‘6’:
stepper2.move(12500);
break;
case ‘7’:
stepper.move(12500);
break;
case ‘8’:
stepper.move(12500);
break;
case ‘10’:
stepper.move(-25000);
stepper2.move(-24500);
break;
case ‘9’:
stepper.moveTo(12500);
delay(100);
stepper.move(12500);
delay(100);
stepper2.move(12500);
delay(100);
stepper.move(-12500);
delay(100);
stepper.move(-12500);
delay(100);
stepper2.move(12500);
delay(100);
stepper.move(12500);
delay(500);
stepper.move(-25000);
stepper2.move(-24500);
break;
}
}
stepper.run();
stepper2.run();

}
I want to understand more…:wink:
I want to mix the two exemples to make the table move and when the limit switch is touched, the table must to stopped.
And I want the table will do the path automatically without using the “case”. Just start the program and it will do the scanning in the work area of the table.
If you want some informations to my part of my project or of my program ask it.
I need some informations and some help to your part if it’s possible.

Thanks,

Yasmina


#2

You should probably set up the end switch to generate an interrupt and then in that interrupt routine stop the motor.
If you want to home the motors, find the switch, you should move quite slow, so you don’t overrun the switch.
You might want to have a look how to make the motors run outside of the loop() function, so you just set some variable to where you want the motor to go. Then you can let the motors run parallell, at same time.

This is just suggestions, and you could probably make that work in some other way.


#3

Thank you so much for your reply.
You know , I found this program and I was thinking if I add some lines of this program in the main program the principal.
I want to test it.
#include <Makeblock.h>
#include <SoftwareSerial.h>
#include <Wire.h>

//Me_LimitSwitch module can only be connected to PORT_3, PORT_4, PORT_6,PORT_7,PORT_8 of base shield or from PORT_3 to PORT_8 of baseboard.
MeLimitSwitch limitSwitchXgauche(PORT_6 s1);
MeLimitSwitch limitSwitchXdroite(PORT_6 s2);
MeLimitSwitch limitSwitchYgauche(PORT_3 slot1);
MeLimitSwitch limitSwitchYdroite(PORT_3 slot2);
void setup()
{
Serial.begin(9600);
Serial.println(“Start.”);
}
void loop()
{
if(limitSwitch.touched()) //If the limit switch is touched, the return value is true.
{
Serial.println(“Etat: BAS.”);
delay(1);
while(limitSwitch.touched()); //Repeat check the switch state, until released.
delay(2);
}
if(!limitSwitch.touched())
{
Serial.println(“Etat: HAUT.”);
delay(1);
while(!limitSwitch.touched());
delay(2);
}
}
{
if(limitSwitchX.touched()) //If the limit switch is touched, the return value is true.
{
Serial.println(“Etat: BAS.”);
delay(1);
while(limitSwitchX.touched()); //Repeat check the switch state, until released.
delay(2);
}
if(!limitSwitchX.touched())
{
Serial.println(“Etat: HAUT.”);
delay(1);
while(!limitSwitchX.touched());
delay(2);
}
}
And for the move of the motors. I find on the forum that the motors make 16* microstep. The axe work 174,978 mm.
So they do 3 200 step/rev. So 3200/175 = 18,28mm/rev. I’m stupid but I have difficult to code this…


#4