background image

/*

 

Ardumoto

 

Example

 

Sketch

  

by:

 

Jim

 

Lindblom

 

  

date:

 

November

 

8,

 

2013

 

  

license:

 

Public

 

domain.

 

Please

 

use,

 

reuse,

 

and

 

modify

 

this

  

  

sketch!

 

  

Adapted

 

to

 

v20

 

hardware

 

by:

 

Marshall

 

Taylor

 

  

date:

 

March

 

31,

 

2017

 

  

Three

 

useful

 

functions

 

are

 

defined:

 

    

setupArdumoto()

 ­­ 

Setup

 

the

 

Ardumoto

 

Shield

 

pins

 

    

driveArdumoto([motor],

 

[direction],

 

[speed])

 ­­ 

Drive

 

[mot

or]

  

      

(0

 

for

 

A,

 

1

 

for

 

B)

 

in

 

[direction]

 

(0

 

or

 

1)

 

at

 

a

 

[speed]

 

      

between

 

0

 

and

 

255.

 

It

 

will

 

spin

 

until

 

told

 

to

 

stop.

 

    

stopArdumoto([motor])

 ­­ 

Stop

 

driving

 

[motor]

 

(0

 

or

 

1).

 

  

setupArdumoto()

 

is

 

called

 

in

 

the

 

setup().

 

  

The

 

loop()

 

demonstrates

 

use

 

of

 

the

 

motor

 

driving

 

functions.

 

*/

//

 

Clockwise

 

and

 

counter

­

clockwise

 

definitions.

//

 

Depending

 

on

 

how

 

you

 

wired

 

your

 

motors,

 

you

 

may

 

need

 

to

 

swa

p.
#define

 

FORWARD

  

0

#define

 

REVERSE

 

1

//

 

Motor

 

definitions

 

to

 

make

 

life

 

easier:

#define

 

MOTOR_A

 

0

#define

 

MOTOR_B

 

1

//

 

Pin

 

Assignments

 

//

//Default

 

pins:

#define

 

DIRA

 

2

 

//

 

Direction

 

control

 

for

 

motor

 

A

#define

 

PWMA

 

3

  

//

 

PWM

 

control

 

(speed)

 

for

 

motor

 

A

#define

 

DIRB

 

4

 

//

 

Direction

 

control

 

for

 

motor

 

B

#define

 

PWMB

 

11

 

//

 

PWM

 

control

 

(speed)

 

for

 

motor

 

B

////Alternate

 

pins:

//#define

 

DIRA

 

8

 

//

 

Direction

 

control

 

for

 

motor

 

A

//#define

 

PWMA

 

9

 

//

 

PWM

 

control

 

(speed)

 

for

 

motor

 

A

//#define

 

DIRB

 

7

 

//

 

Direction

 

control

 

for

 

motor

 

B

//#define

 

PWMB

 

10

 

//

 

PWM

 

control

 

(speed)

 

for

 

motor

 

B

void setup()
{

 

setupArdumoto();

 

//

 

Set

 

all

 

pins

 

as

 

outputs

}

 

void loop()
{

 

//

 

Drive

 

motor

 

A

 

(and

 

only

 

motor

 

A)

 

at

 

various

 

speeds,

 

then

 

stop.

driveArdumoto(MOTOR_A,

 

REVERSE,

 

255);

 

//

 

Set

 

motor

 

A

 

to

 

REVE

RSE

 

at

 

max

delay(1000);

  

//

 

Motor

 

A

 

will

 

spin

 

as

 

set

 

for

 

1

 

second

driveArdumoto(MOTOR_A,

 

FORWARD,

 

127);

  

//

 

Set

 

motor

 

A

 

to

 

FOR

WARD

 

at

 

half

delay(1000);

  

//

 

Motor

 

A

 

will

 

keep

 

trucking

 

for

 

1

 

second

 

stopArdumoto(MOTOR_A);

  

//

 

STOP

 

motor

 

A

 

//

 

Drive

 

motor

 

B

 

(and

 

only

 

motor

 

B)

 

at

 

various

 

speeds,

 

then

 

stop.

Page 12 of 17

Summary of Contents for Ardumoto Kit

Page 1: ...hield either alone or with a set of motors and wheels in our Ardumoto Shield Kit This kit includes the shield as well as pairs of tires motors and connectors And of course it s all stuffed in a classi...

Page 2: ...gory You ll also need a handful of connectors to get everything wired up together We recommend Stackable Headers to connect your Ardumoto to your Arduino and two or three 3 5mm Screw Terminals to help...

Page 3: ...is a great platform for first time motor users and experienced ones too There are however a few concepts you should be familiar with before clicking over to the next few pages Here are some tutorials...

Page 4: ...means it can individually drive up to two motors So it s perfect for a two wheel drive vehicle But if you have a special four wheel drive platform you might need something else or just two L298s Each...

Page 5: ...es two pins the digital output for direction and the PWM for speed The factory configuration uses Arduino pins 2 3 4 and 11 The alternate configuration uses pins 7 8 9 and 10 If the alternate pins are...

Page 6: ...ilding simple two wheel drive robot platforms connect one motor to port A and the other motor to port B Technically there is no right or wrong way to connect your motor s wires to the two output pins...

Page 7: ...debug your code LEDs in operation Supply Voltage The Ardumoto Shield should be powered through one of two power supply inputs Pick one or the other 1 The barrel jack input on the Arduino 2 The V input...

Page 8: ...r a Project tutorial Ardumoto Shield Assembly Tips Before you can start using the Ardumoto Shield you have to do a little assembly Embrace your inner electronics technician and whip out that soldering...

Page 9: ...looking for lower profile installation If this is your first shield assembly we recommend reading through our shield assembly guide There are all sorts of tricks to installing shield headers and maki...

Page 10: ...otors being driven Disconnect all the jumpers and wire up the L298 in any way you please Unlike other prototyping areas you may have encountered in the past these holes are not wired together You don...

Page 11: ...ell This shape of robot relies mostly on balance and slides across the floor If driving on carpet slick clear tape can be added to the corners to prevent catching Example Code Controlling the Ardumoto...

Page 12: ...to make life easier define MOTOR_A 0 define MOTOR_B 1 Pin Assignments Default pins define DIRA 2 Direction control for motor A define PWMA 3 PWM control speed for motor A define DIRB 4 Direction contr...

Page 13: ...for a second Now spin in place driveArdumoto MOTOR_A FORWARD 255 Motor A at max spe ed driveArdumoto MOTOR_B REVERSE 255 Motor B at max spe ed delay 2000 Drive forward for a second stopArdumoto MOTOR...

Page 14: ...12 LOW digitalWrite 12 LOW Motor A will spin clockwise To make it spin the other way write the pin HIGH digitalWrite 12 HIGH Motor A will spin counter clockwis e Note The rotation direction depends o...

Page 15: ...dumoto Schematic To make the Ardumoto we ve connected the pairs with one of each inverted to allow a direction control The enable pin is then PWM d such that the output goes between drive enabled and...

Page 16: ...ing drive configuration Bridging output and control lines for 4A single drive add a heatsink with thermal tape Resources Ardumoto Shield Schematic A PDF of the shield s schematic Ardumoto Shield Githu...

Page 17: ...is an I2C based low voltage DC motor driver Assembly Guide for RedBot with Shadow Chassis Assembly Guide for the RedBot Kit This tutorial includes extra parts to follow to go along with the RedBot In...

Reviews: