2010-12-28

Stepper Motors library ported from Arduino to Pinguino


This library was ported from Stepper library from Arduino project,
Same samples works with minimum changes!
http://arduino.cc/en/Reference/Stepper

You need add a 1µF or 10µF capacitor between GND and VCC on pinguino board.
Tested with a PM35-048 stepper and ULN2003a / ULN2803a drivers.

DOWNLOAD


INSTALL
1- Copy Stepper.lib/stepper.c and Stepper.lib/stepper.h to pinguino/tools/share/sdcc/include/pic16/
2- Copy Stepper.lib/stepper.pdl to pinguino/lib

Sample:

/*
 * Based on MotorKnob Stepper Library from Arduino Project
 *
 * A stepper motor follows the turns of a potentiometer
 * (or other sensor) on analog input 0.
 *
 * http://www.arduino.cc/en/Reference/Stepper
 * 
 * Pinguino port by Anunakin 
 * For use this sample on Pinguino boards, 
 * you need add a 10uF or less capacitor 
 * between GND and VCC on pinguino board.
 */
#define PIC18F4550
#define LED 4
#define POT 13
// change this to the number of steps on your motor
// PM35S-048
#define STEPS 48
// specify the number of steps of the motor and the pins it's
// attached to
// the previous reading from the analog input
int previous = 0;
void setup()
{
  stepper(STEPS, 0, 1, 2, 3);
  //stepper(STEPS, 0, 1);
  // set the speed of the motor to 30 RPMs
  stepper.setSpeed(100);
  
  pinMode(POT,INPUT);
  pinMode(LED,OUTPUT);
}
void loop()
{
   // get the sensor value
  int val = analogRead(POT);
  val = (int)(val*1/16);
  
  // move a number of steps equal to the change in the
  // sensor reading
  if (val != previous){    
    stepper.step(val - previous);
  }
    
    digitalWrite(LED,HIGH);
    delay(50 + val);
  //}
  digitalWrite(LED,LOW);
  delay(50);
  
  //remember the previous value of the sensor
  previous = val;
}

Postar um comentário