Just hooking up the Arduino to the computer doesn't do the trick, so maybe no RX/TX problem?!
I have to overwrite my code but overwriting with let's say "Examples > Blink" doesn't help, it has to be a code that runs at least one motor. There is no difference whether my power supply for the motors comes from a wall wart or from a NiMH battery pack, in either case the set-up won't run from the start but will do so after I overwritten the code and tested my motors once.
// Thank you for helping !
Set-up:
[*] Arduino Duemilanove
[*] Motor Shield v.2
[*] 2 small steppers (https://www.adafruit.com/products/858)
[*] 2 separate power supplies for Arduino and motors (jumper on motor shield removed)
This is my code:
Code: Select all
// 17.07.2014
#include <AccelStepper.h>
#include <Wire.h>
#include <Adafruit_MotorShield.h>
Adafruit_MotorShield AFMSbot(0x61); // Rightmost jumper closed
Adafruit_MotorShield AFMStop(0x60); // Default address, no jumpers
// Connect two steppers with 200 steps per revolution (1.8 degree)
Adafruit_StepperMotor *myStepper1 = AFMStop.getStepper(100, 1);
Adafruit_StepperMotor *myStepper2 = AFMStop.getStepper(100, 2);
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
int buttonState = 0; // variable for reading the pushbutton status
// wrappers for the first motor!
void forwardstep1() {
myStepper1->onestep(FORWARD, DOUBLE);
}
void backwardstep1() {
myStepper1->onestep(BACKWARD, DOUBLE);
}
//wrappers for the second motor!
void forwardstep2() {
myStepper2->onestep(FORWARD, DOUBLE);
}
void backwardstep2() {
myStepper2->onestep(BACKWARD, DOUBLE);
}
AccelStepper stepper1(forwardstep1,backwardstep1);
AccelStepper stepper2(backwardstep2,forwardstep2);
void setup()
{
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
AFMSbot.begin(); // Start the shield
stepper1.setMaxSpeed(50.0);
stepper1.setAcceleration(100.0);
stepper1.moveTo(300);
stepper2.setMaxSpeed(50.0);
stepper2.setAcceleration(100.0);
stepper2.moveTo(300);
}
void loop()
{
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// Motors on :
digitalWrite(ledPin, HIGH); // control LED on
stepper1.run();
stepper2.run();
}
else {
digitalWrite(ledPin, LOW); // control LED off
myStepper1->release(); // stop rotation and turn off holding torque.
myStepper2->release(); // stop rotation and turn off holding torque.
digitalWrite(ledPin, LOW); // control LED off
}
// Change direction at the limits
if (stepper1.distanceToGo() == 0)
stepper1.moveTo(-stepper1.currentPosition());
if (stepper2.distanceToGo() == 0)
stepper2.moveTo(-stepper2.currentPosition());
}