Saturday, February 25, 2012

simple linear drive test

I used an Arduino Uno r3 with a Arduino Motor Shield r3, with belt and pulley from motionco.co.uk ( parts pl032, cpmxl025, bmxl025OL ).

I broke the "VIn Connect"  jumper at the back of the motor shield board.

I used a 12V 1.5A power supply from an old scanner.

I achieved 300mm per second.









arduino code:

// stepper motor control using http://arduino.cc/en/Main/ArduinoMotorShieldR3

#define ADIR 12
#define BDIR 13
#define APOWER 3
#define BPOWER 11

void setup() {
    pinMode(3, OUTPUT);
    pinMode(11, OUTPUT);
    pinMode(12, OUTPUT);
    pinMode(13, OUTPUT);
    pinMode(9, OUTPUT);
    pinMode(8, OUTPUT);
    pinMode(0, INPUT);
    pinMode(1, INPUT);
}

int stage = 0;

void set_stage(int i)
{
  switch(i)
  {
  case 0:
    digitalWrite(ADIR, 0);
    analogWrite(APOWER, 255);
    digitalWrite(BDIR, 1);
    analogWrite(BPOWER, 255);
    break;
  case 1:
    digitalWrite(ADIR, 1);
    analogWrite(APOWER, 255);
    digitalWrite(BDIR, 1);
    analogWrite(BPOWER, 255);
    break;
  case 2:
    digitalWrite(ADIR, 1);
    analogWrite(APOWER, 255);
    digitalWrite(BDIR, 0);
    analogWrite(BPOWER, 255);
    break;
  case 3:
    digitalWrite(ADIR, 0);
    analogWrite(APOWER, 255);
    digitalWrite(BDIR, 0);
    analogWrite(BPOWER, 255);
    break;
  }
 
}

void ddelay(float d)
{
  for(float t = 0.0; t < d; t += 0.01)
  {
    int h = 4;
    h = h + 5;
    h = 3*h;
    h--;
  }
}

void sstep(int forward)
{
  if(forward)
  {
    stage++;
    if(stage > 3)stage = 0;
  } 
  else
  {
    stage--;
    if(stage<0)stage = 3;
  }
  set_stage(stage);
}

void loop() {
  // set brake pins to 0
  digitalWrite(9, 0);
  digitalWrite(8, 0);
 
  // set motor pins
  stage = 1;
  set_stage(stage);
 
    float d = 2;
 
  while(1)
  {
    ddelay(d);
    sstep(1);
    d = d * 0.99975;
    if(d<0.85)d = 0.85;
  }
}