Issues when controlling stepper motor by MegaPi


#1

I have encountered the following problems with the following code, which is adapted from the sample code in makeblock library.

  1. The For loop does not work: motor only ran once.
  2. The following code was not executed:
    stepper_x.move(7000);
    stepper_x.run();

#include “MeMegaPi.h”
#include <SoftwareSerial.h>

MeStepperOnBoard stepper_x(SLOT_4);

void setup()
{
Serial.begin(9600);
// Change these to suit your stepper if you want
stepper_x.setMaxSpeed(500);
stepper_x.setAcceleration(20000);
stepper_x.setMicroStep(16);
stepper_x.enableOutputs();
}

void loop()
{
if(Serial.available())
{
char a = Serial.read();
switch(a)
{
case ‘0’:
for (int i=0; i <= 5; i++){
stepper_x.move(7000);
stepper_x.run();
stepper_x.move(-7000);
stepper_x.run();
}
break;
}
}
stepper_x.run();
}


#2