Adafruit motor shield v2. Permite controlar:
2 motores paso a paso
4 motores de continua de hasta 1.2 A
2 servos de 5V
Con una 1 sola librería
Además, se pueden apilar varias unidades sobre un solo Arduino.
Alimentación:
Con el jumper colocado toma la alimentación del USB o la pila de Arduino. Solo va bien si usamos paso a paso: los otros motores consumen mucho y necesitan alimentación externa: junto al jumper hay dos conectores marcados con + y - para la alimenteción externa de hasta 12 voltios.
Control de motores de continua: ampliando el ancho de los pulsos PWN.
Conexión del motor de continua:
/*
This is a test sketch for the Adafruit assembled Motor Shield for Arduino v2
It won't work with v1.x motor shields! Only for the v2's with built in PWM
control
For use with the Adafruit Motor Shield v2
----> http://www.adafruit.com/products/1438
*/
#include <Adafruit_MotorShield.h>
// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
// Or, create it with a different I2C address (say for stacking)
// Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x61);
// Select which 'port' M1, M2, M3 or M4. In this case, M1
Adafruit_DCMotor *myMotor = AFMS.getMotor(1);
// You can also make another motor on port M2
//Adafruit_DCMotor *myOtherMotor = AFMS.getMotor(2);
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("Adafruit Motorshield v2 - DC Motor test!");
if (!AFMS.begin()) { // create with the default frequency 1.6KHz
// if (!AFMS.begin(1000)) { // OR with a different frequency, say 1KHz
Serial.println("Could not find Motor Shield. Check wiring.");
while (1);
}
Serial.println("Motor Shield found.");
// Set the speed to start, from 0 (off) to 255 (max speed)
myMotor->setSpeed(150);
myMotor->run(FORWARD);
// turn on motor
myMotor->run(RELEASE);
}
void loop() {
uint8_t i;
Serial.print("tick");
myMotor->run(FORWARD);
for (i=50; i<100; i++) {
myMotor->setSpeed(i);
delay(50);
}
for (i=100; i!=50; i--) {
myMotor->setSpeed(i);
delay(50);
}
Serial.print("tock");
myMotor->run(BACKWARD);
for (i=50; i<100; i++) {
myMotor->setSpeed(i);
delay(50);
}
for (i=100; i!=50; i--) {
myMotor->setSpeed(i);
delay(50);
}
Serial.print("tech");
myMotor->run(RELEASE);
delay(1000);
}
Control de motores paso a paso. Estandar: 1'8º en cada paso: 200 pasos por vuelta. Claves: lentitud y precisión.
/*
This is a test sketch for the Adafruit assembled Motor Shield for Arduino v2
It won't work with v1.x motor shields! Only for the v2's with built in PWM
control
For use with the Adafruit Motor Shield v2
----> http://www.adafruit.com/products/1438
*/
#include <Adafruit_MotorShield.h>
// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
// Or, create it with a different I2C address (say for stacking)
// Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x61);
// Connect a stepper motor with 200 steps per revolution (1.8 degree)
// to motor port #2 (M3 and M4)
Adafruit_StepperMotor *myMotor = AFMS.getStepper(200, 2);
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
while (!Serial);
Serial.println("Stepper test!");
if (!AFMS.begin()) { // create with the default frequency 1.6KHz
// if (!AFMS.begin(1000)) { // OR with a different frequency, say 1KHz
Serial.println("Could not find Motor Shield. Check wiring.");
while (1);
}
Serial.println("Motor Shield found.");
myMotor->setSpeed(10); // 10 rpm. Si nos pasamos de velocidad deslizará, fallará...
}
void loop() {
Serial.println("Single coil steps");
myMotor->step(100, FORWARD, SINGLE);
myMotor->step(100, BACKWARD, SINGLE);
Serial.println("Double coil steps");
myMotor->step(100, FORWARD, DOUBLE); //Número de pasos que queremos que avance: 100= 180º. El máximo de pasos es 65535.
myMotor->step(100, BACKWARD, DOUBLE); //Si el motor tiene reductora, harán falta multiplicar el número de pasos proporcionalmente.
Serial.println("Interleave coil steps");
myMotor->step(100, FORWARD, INTERLEAVE);
myMotor->step(100, BACKWARD, INTERLEAVE);
Serial.println("Microstep steps");
myMotor->step(50, FORWARD, MICROSTEP);
myMotor->step(50, BACKWARD, MICROSTEP);
}
Miniservo