Pages: 1 [2]   Go Down
Author Topic: radio shack motor shield docs  (Read 4732 times)
0 Members and 1 Guest are viewing this topic.
SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 124
Posts: 6652
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
The store personnel are clueless as far as technical questions are concerned.
Nothing new there, even for consumer products.

Quote
Radio Shack take note, hire technically competent people if your are going to serve the electronics hobby market.
Nah.  Don't make them do that; they'll just get rid of their "hobby" parts instead.

I think I'm inclined to agree that the Arduino Motor Shield should have better support from the Arduino team, including a library that comes with the distribution...
Logged

United States
Offline Offline
Newbie
*
Karma: 2
Posts: 49
Yes. Thats my donkey
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Since I could not find a good sketch for this shield I thought I would try to make one and by way, My first contribution to the Arduino society.

So for those whom might need a demo sketch:

//----------------------------------------------------------------------
/*
  This is an unofficial demo sketch for using the Official
  'Arduino Motor Shield R3'  and used as a unipolar/bipolar
  stepper driver.
 
  By Duane Bishop Jan-7-2012
  This code is public domain.
 
  Prerequisites:

    Official Aruino Motor Shield R3 or a pin compatible clone.
      (Clones are assumed to be based on L298 driver chip.)

    An Arduino Uno, Decimillia, Mega, or clone that can use
    the Motor Shield.
     
    Read the product info page at:
      http://arduino.cc/en/Main/ArduinoMotorShieldR3

    Correct wiring knowledge for your stepper motor.
      A good guide can be found at:
      http://www.stepperworld.com/pgTutorials.htm
   
    Know how many steps our motor has.
      (If unknown, spin stepper shaft by hand, count detents per
      revolution multiply by two and you'll have the correct number
      of steps for that model of stepper.)   
*/

// How many steps does your stepper have?
int numberOfSteps=200;

// How many milliamps would you like to send to your stepper?
int milliAmps=100; // Per coil.

//Optional
boolean heatsink=false; // If you have one mounted, set to true.

// Import the stepper library.
#include <Stepper.h>

// Label our pins:
int coilA=12;      // Coil-A directional pin.
int coilB=13;      // Coil-B directional pin.
int coilApower=3;  // PWM is used for Coil-A current control.
int coilBpower=11; // PWM is used for Coil-B current control.
int coilAsens=A0;  // Used to monitor current draw of Coil-A
int coilBsens=A1;  // Used to monitor current draw of Coil-A

// Define some variables we'll need.
int currentOfCoilA;
int currentOfCoilB;

// We'll need a function to derive how many milliamps we're using.
int getMilliamps(int sensingPin)
{
  /*
  Arduino references 0~5 volts as value of 0~1023
  But our Motor Control Shield references its load from 0~3.3 volts.
  We need to scale these two ranges so we can make use of it.
  So: 1024/5=204.8 per volt. times that by 3.3 we get 675.84

  However:
  analogRead(); doesn't do decimals so it will only read a maximum
  of 675 (at 2 Amps) on our coil sensing pins.
  */

  int milliSens=0;
  long sensingTotal=0;

  while(milliSens <=255) // Gather readings over whole PWM cycle.
  {
      sensingTotal=sensingTotal + analogRead(sensingPin);
      milliSens++;
  }
 
  int sensingAvg=sensingTotal/256; // Average the readings
  int milliLoad=map(sensingAvg,0,675,0,2000); //Translate to milliamps
  return(milliLoad); //Return the result.
}

void setCoilPower(int power)
{
  int tempVal=0;
  while(getMilliamps(coilAsens) < power)
  {
    tempVal++;
    analogWrite(coilApower,tempVal);
  }
  Serial.print("Setting coilApower=");
  Serial.print(tempVal);

  tempVal=0;
  while(getMilliamps(coilBsens) < power)
  {
    tempVal++;
    analogWrite(coilBpower,tempVal);
  }
  Serial.print(" and coilBpower=");
  Serial.println(tempVal);
  Serial.println("");
}

// Now we'll make our stepper funtion.
Stepper ourStepperFunction(numberOfSteps,coilA,coilB);

void setup()
{
  // Set our pinModes.
  pinMode(coilA,OUTPUT);
  pinMode(coilB,OUTPUT);
  pinMode(coilApower,OUTPUT);
  pinMode(coilBpower,OUTPUT);
  pinMode(coilAsens,INPUT);
  pinMode(coilBsens,INPUT);
 
  // Set the speed of our stepper.
  // (Faster = less torque. 100 is very slow, but very reliable.)
  ourStepperFunction.setSpeed(25);
 
  Serial.begin(9600); // Open you serial monitor to view results.
  // Sanity check.
  if(milliAmps > 2000)
  {
    Serial.println("milliAmps: Set WAY TOO HIGH!!");
    Serial.println("milliAmps: You'll SMOKE your Motor Controller!!");
    Serial.println("Bailing out. Mayday! Mayday!");
    while(milliAmps); // Stay here do not pass.
  }else{
    if(milliAmps >= 1000 && heatsink != true)
    {
      Serial.println("milliAmps: Set too high for stock Motor Shield!");
      Serial.println("milliamps:Install heatsink and set 'heatsink=true'");
      Serial.println("Bailing out.");
      while(milliAmps); // Stay here do not pass.
    }else{
      Serial.println("milliamps: OK.");
      delay(500);
        Serial.print("Ramping power up to: ");
        Serial.print(milliAmps);
        Serial.println(" milliAmps for each coil.");
        setCoilPower(milliAmps);
        Serial.println("Your stepper should now be turning one revolution");
        Serial.println(" in each direction. If not, check your wires.");
        Serial.println(" It the stepper/driver is hot, lower your milliAmps.");
    }
  }
}

void loop()
{
  ourStepperFunction.step(numberOfSteps);
  delay(500);
  ourStepperFunction.step(-numberOfSteps);
}
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
but it dose not have example code do drive a dc moter
What code do you need? Set the direction pin HIGH to go one way. Set it LOW to go the other way. Set the speed using analogWrite() with some value between 0 (slowest) and 255 (fastest).
Hey Paul, It Does not work as you described!  Some examples would be helpfull!
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
but it dose not have example code do drive a dc moter
What code do you need? Set the direction pin HIGH to go one way. Set it LOW to go the other way. Set the speed using analogWrite() with some value between 0 (slowest) and 255 (fastest).

Hey Paul, It does not work as you described!  Some examples (that work) would be helpfull!!
Logged

Offline Offline
God Member
*****
Karma: 1
Posts: 547
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How are you connecting your motor? Both wires from the motor have to go to the same pair of terminals A or B. Meaning there is an A+ and an A-, a B+ and a B-.
Logged

Pages: 1 [2]   Go Up
Jump to: