upm  0.5.1
Sensor/Actuator repository for libmraa (v0.9.1)
 All Data Structures Files Functions Variables Enumerations Enumerator Macros Groups Pages
Data Structures | Public Types | Public Member Functions
AdafruitMS1438 Class Reference

API for the AdafruitMS1438 Motor Shield. More...

Detailed Description

This class implements support for the stepper and DC motors that can be connected to this Motor Shield. Note: the two servo connections are not controlled by the PCA9685 controller (or this class). They are connected directly to digital PWM pins 9 and 10 on the Arduino* breakout board.

adafruitms1438.jpg

An example using a DC motor connected to M3

// Instantiate an Adafruit MS 1438 on I2C bus 0
new upm::AdafruitMS1438(ADAFRUITMS1438_I2C_BUS,
ADAFRUITMS1438_DEFAULT_I2C_ADDR);
// Setup for use with a DC motor connected to the M3 port
// set a PWM period of 50Hz
ms->setPWMPeriod(50);
// disable first, to be safe
ms->disableMotor(AdafruitMS1438::MOTOR_M3);
// set speed at 50%
ms->setMotorSpeed(AdafruitMS1438::MOTOR_M3, 50);
ms->setMotorDirection(AdafruitMS1438::MOTOR_M3, AdafruitMS1438::DIR_CW);
cout << "Spin M3 at half speed for 3 seconds, then reverse for 3 seconds."
<< endl;
ms->enableMotor(AdafruitMS1438::MOTOR_M3);
sleep(3);
cout << "Reversing M3" << endl;
ms->setMotorDirection(AdafruitMS1438::MOTOR_M3, AdafruitMS1438::DIR_CCW);
sleep(3);
cout << "Stopping M3" << endl;
ms->disableMotor(AdafruitMS1438::MOTOR_M3);
cout << "Exiting" << endl;

An example using a stepper motor connected to M1 & M2

// Instantiate an Adafruit MS 1438 on I2C bus 0
new upm::AdafruitMS1438(ADAFRUITMS1438_I2C_BUS,
ADAFRUITMS1438_DEFAULT_I2C_ADDR);
// Setup for use with a stepper motor connected to the M1 & M2 ports
// set a PWM period of 50Hz
// disable first, to be safe
ms->disableStepper(AdafruitMS1438::STEPMOTOR_M12);
// configure for a NEMA-17, 200 steps per revolution
ms->stepConfig(AdafruitMS1438::STEPMOTOR_M12, 200);
// set speed at 10 RPM's
ms->setStepperSpeed(AdafruitMS1438::STEPMOTOR_M12, 10);
ms->setStepperDirection(AdafruitMS1438::STEPMOTOR_M12,
AdafruitMS1438::DIR_CW);
// enable
cout << "Enabling..." << endl;
ms->enableStepper(AdafruitMS1438::STEPMOTOR_M12);
cout << "Rotating 1 full revolution at 10 RPM speed." << endl;
ms->stepperSteps(AdafruitMS1438::STEPMOTOR_M12, 200);
cout << "Sleeping for 2 seconds..." << endl;
sleep(2);
cout << "Rotating 1/2 revolution in opposite direction at 10 RPM speed."
<< endl;
ms->setStepperDirection(AdafruitMS1438::STEPMOTOR_M12,
AdafruitMS1438::DIR_CCW);
ms->stepperSteps(AdafruitMS1438::STEPMOTOR_M12, 100);
cout << "Disabling..." << endl;
ms->disableStepper(AdafruitMS1438::STEPMOTOR_M12);
cout << "Exiting" << endl;

Public Types

enum  DIRECTION_T { DIR_NONE = 0x00, DIR_CW = 0x01, DIR_CCW = 0x02 }
 
enum  DCMOTORS_T { MOTOR_M1 = 0, MOTOR_M2 = 1, MOTOR_M3 = 2, MOTOR_M4 = 3 }
 
enum  STEPMOTORS_T { STEPMOTOR_M12 = 0, STEPMOTOR_M34 = 1 }
 

Public Member Functions

 AdafruitMS1438 (int bus, uint8_t address=ADAFRUITMS1438_DEFAULT_I2C_ADDR)
 
 ~AdafruitMS1438 ()
 
uint32_t getMillis (STEPMOTORS_T motor)
 
void initClock (STEPMOTORS_T motor)
 
void setPWMPeriod (float hz)
 
void enableMotor (DCMOTORS_T motor)
 
void disableMotor (DCMOTORS_T motor)
 
void enableStepper (STEPMOTORS_T motor)
 
void disableStepper (STEPMOTORS_T motor)
 
void setMotorSpeed (DCMOTORS_T motor, int speed)
 
void setStepperSpeed (STEPMOTORS_T motor, int speed)
 
void setMotorDirection (DCMOTORS_T motor, DIRECTION_T dir)
 
void setStepperDirection (STEPMOTORS_T motor, DIRECTION_T dir)
 
void stepConfig (STEPMOTORS_T motor, unsigned int stepsPerRev)
 
void stepperSteps (STEPMOTORS_T motor, unsigned int steps)
 

Member Enumeration Documentation

Enum to specify the direction of a motor

enum DCMOTORS_T

Enum to specify a DC motor

Enum to specify a stepper motor

Constructor & Destructor Documentation

AdafruitMS1438 ( int  bus,
uint8_t  address = ADAFRUITMS1438_DEFAULT_I2C_ADDR 
)

AdafruitMS1438 constructor

Parameters
busI2C bus to use
addressAddress for this sensor

Here is the call graph for this function:

AdafruitMS1438 destructor

Member Function Documentation

uint32_t getMillis ( STEPMOTORS_T  motor)

Returns the number of milliseconds elapsed since initClock(...) was last called.

Returns
Elapsed milliseconds

Here is the caller graph for this function:

void initClock ( STEPMOTORS_T  motor)

Resets the clock

Here is the caller graph for this function:

void setPWMPeriod ( float  hz)

Sets the PWM period. Note: this applies to all PWM channels.

Parameters
hzSets the PWM period

Here is the call graph for this function:

Here is the caller graph for this function:

void enableMotor ( DCMOTORS_T  motor)

Enables PWM output for a motor

Parameters
motorDC motor to enable

Here is the call graph for this function:

void disableMotor ( DCMOTORS_T  motor)

Disables PWM output for a motor

Parameters
motorDC motor to disable

Here is the call graph for this function:

Here is the caller graph for this function:

void enableStepper ( STEPMOTORS_T  motor)

Enables output for a stepper motor

Parameters
motorStepper motor to enable

Here is the call graph for this function:

void disableStepper ( STEPMOTORS_T  motor)

Disable output for a stepper motor

Parameters
motorStepper motor to disable

Here is the call graph for this function:

void setMotorSpeed ( DCMOTORS_T  motor,
int  speed 
)

set the speed of a DC motor. Values can range from 0 (off) to 100 (full speed).

Parameters
motorthe DC motor to configure
speedspeed to set the motor to

Here is the call graph for this function:

void setStepperSpeed ( STEPMOTORS_T  motor,
int  speed 
)

Sets the speed of a stepper in revolutions per minute (RPM)

Parameters
motorDC motor to configure
speedSpeed to set the motor to
void setMotorDirection ( DCMOTORS_T  motor,
DIRECTION_T  dir 
)

Sets the direction of a DC motor, clockwise or counterclockwise

Parameters
motorDC motor to configure
dirDirection to set the motor in

Here is the call graph for this function:

void setStepperDirection ( STEPMOTORS_T  motor,
DIRECTION_T  dir 
)

Sets the direction of a stepper motor, clockwise or counterclockwise

Parameters
motorStepper motor to configure
dirDirection to set the motor in
void stepConfig ( STEPMOTORS_T  motor,
unsigned int  stepsPerRev 
)

Sets a stepper motor configuration

Parameters
motorStepper motor to configure
stepsPerRevNumber of steps to complete a full revolution

Here is the call graph for this function:

Here is the caller graph for this function:

void stepperSteps ( STEPMOTORS_T  motor,
unsigned int  steps 
)

Steps a stepper motor a specified number of steps

Parameters
motorStepper motor to step
stepsNumber of steps to move the stepper motor

Here is the call graph for this function:


The documentation for this class was generated from the following files: