11
The connection between 24BYJ48 Stepper Motor and I2C Motor Driver is shown as blow:
Download the
Grove-I2C motor driver V1.3 demo code
, and open the
StepperControlMode2.ino
:
#include <Wire.h>
#define MotorSpeedSet 0x82
#define PWMFrequenceSet 0x84
#define DirectionSet 0xaa
#define MotorSetA 0xa1
#define MotorSetB 0xa5
#define Nothing 0x01
#define EnableStepper 0x1a
#define UnenableStepper 0x1b
#define Stepernu 0x1c
#define I2CMotorDriverAdd 0x0f
// Set the address of the I2CMotorDriver
// set the steps you want, if 255, the stepper will rotate continuously;
void
SteperStepset
(
unsigned
char
stepnu
)
{
Wire
.
beginTransmission
(
I2CMotorDriverAdd
);
// transmit to device I2CMotorDriverAdd
Wire
.
write
(
Stepernu
);
// Send the stepernu command
Wire
.
write
(
stepnu
);
// send the steps
Wire
.
write
(
Nothing
);
// send nothing
Wire
.
endTransmission
();
// stop transmitting
}
.......
.......
.......
.......
void
stepperrun
()
{
Serial
.
println
(
"sent command to + direction, very fast"
);
SteperStepset
(
255
);
StepperMotorEnable
(
1
,
1
);
// ennable the i2c motor driver a stepper.
delay
(
5000
);
Serial
.
println
(
"sent command to - direction, slow"
);
SteperStepset
(
255
);
StepperMotorEnable
(
0
,
20
);