Skip to content

Dual Motor TinyShield Tutorial

The Dual Motor Shield allows you to drive two independently controlled DC brushed motors. Create your own tiny robots or drones! Using two of the super miniature but very powerful 2mm x 2mm TI DRV8837 Motor Driver (H-Bridge) IC, this shield will allow for up to 1.8A per channel and operate motors between 1.8 and 11V. This shield includes a built-in motor controller to make driving motors simple using the ATtiny841 Arduino Library.

You can use up to four Motor Shields at a time to use up to eight motors.

All the connections to the motors use standard 0.1″ spaced holes to solder motor leads.  

Learn more about the TinyDuino Platform

Note: While the DRV8837 supports 1.8A @ 11V, we highly recommend operating under 500mA @ 5V per channel unless you have some really good heat sinking in place.

Technical Details TI DRV8837 H-bridge motor driver
  • Low MOSFET On-Resistance: HS + LS 280mOhm
  • 1.8A Max Drive Current (Recommend 500mA max)
  • 1.8V to 11V Motor Operating Supply Voltage Range
Power Requirements
  • Voltage: 3.0V - 5.5V
  • Current: 5mA (Logic only)
Pins Used
  • A5/SCL - I2C Serial Clock line
  • A4/SDA - I2C Serial Data line
Dimensions
  • 20mm x 20mm (.787 inches x .787 inches)
  • Max Height (from lower bottom TinyShield Connector to upper top TinyShield Connector): 5.11mm (0.201 inches)
  • Weight: 1.62 grams (.06 ounces)

Notes

  • Up to 4 Dual Motor Shields can be stacked together in one Tiny stack, however, the I2C address needs to be different for each Shield. This can be changed with resistors R1 and R2 (more information at the bottom of the page).   
  • By default, the motor power supply input connection is connected to the VBATT connection on the TinyDuino. Therefore, you can run your TinyDuino and the motors off the same battery when it's plugged into this TinyShield.  However, when using this, be sure not to exceed 5.5V on this power input or it will damage the TinyDuino circuitry.  If a higher motor voltage is required, you can remove resistor R3 which will allow you to run the motor voltage independently from the TinyDuino logic voltage.  
  • Be sure that your power supply is sufficient to operate these motors as well as your logic – batteries work the best. If you are running both the motors and the logic off of one power supply, we recommend avoiding using a switching power supply as the transients caused can potentially damage items connected to the logic side.
  • You do not have to use motors with JST connectors, the board comes in two variations depending on your needs so that you can solder your own motors. The board variation with the JST connectors makes it easy to connect the motors fast without needing soldering equipment.

Materials

TinyZero and Dual Motor TinyShield

Hardware

Software


Hardware Assembly

Connect your processor board of choice to your Dual Motor Shield using the 32 pin tan connectors. Then plug in the battery and the motor(s) to your Motor Shield.

If you selected the Dual Motor Shield without the JST pin connectors, you will need to solder the motors of your choice to the board. The ground pin is noted in the silkscreen on the board with a line parallel to the pads. In other words, solder the black (GND) wire to the left, noted through-hole points, and the red (POWER) wire to the rights, unmarked through-hole point. Although the red and black color scheme is an industry standard, the wire colors on your motors may be different. Always consult component documentation before soldering.

An assembled stack of a TinyZero and Dual Motor TinyShield.

NOTE: In order for the motors to have enough power to move, there must be an external power supply. Here, we use a battery.


Software Setup

You need the ATtiny841 library in order to use the example program in this tutorial. A zip file of the library is included under the Software Materials. To install an Arduino library, check out our Library Installation Page.

Open the Basic Motor Example program in the Arduino IDE, plug your TinyDuino stack into your PC using the MicroUSB cable, ensure your Tools selections are correct for your processor board, and click the upload button.

Code
//-------------------------------------------------------------------------------
//  TinyCircuits Dual Motor Driver Basic Example
//  Last modified 24 Feb 2020
//  
//  This example code shows basic usage of the ASD2302 Dual Motor Driver TinyShield.
//  The library intance is created with the hardware address of the motor driver
//  (up to 4 boards/8 motors) and then intialized with begin(maximum PWM value).
//  The Dual Motor Driver has 16 bit PWM output capability, but keep in mind the
//  output frequency is low when using a large timer value- great for some things,
//  like driving servos. To drive the motors, use setMotor(motor, value) to set
//  motor 1 or 2 to -maxPWM to +maxPWM.
//
//  The board uses the ATtiny841 microcontroller and has direct register access-
//  so just about any of the internal peripherals could be put to use.
//
//  Written by Ben Rose, TinyCircuits http://TinyCircuits.com
//
//-------------------------------------------------------------------------------


#include <Wire.h>
#include <MotorDriver.h>

MotorDriver motor(NO_R_REMOVED);//this value affects the I2C address, which can be changed by
                                //removing resistors R1 or R2. Then the corresponding R1_REMOVED,
                                //R2_REMOVED, R1_R2_REMOVED can be set.
                                //Default is NO_R_REMOVED


#if defined (ARDUINO_ARCH_AVR)
#define SerialMonitorInterface Serial
#elif defined(ARDUINO_ARCH_SAMD)
#define SerialMonitorInterface SerialUSB
#endif


int maxPWM=1000;
int steps=10;
int stepSize=maxPWM/steps;

void setup(){
  SerialMonitorInterface.begin(9600);
  Wire.begin();
  while(!SerialMonitorInterface)//This will block until the Serial Monitor is opened on TinyScreen+/TinyZero platform!


  //The value passed to begin() is the maximum PWM value, which is 16 bit(up to 65535)
  //This value also determines the output frequency- by default, 8MHz divided by the maxPWM value
  if(motor.begin(maxPWM)){
    SerialMonitorInterface.println("Motor driver not detected!");
    while(1);
  }
  //The failsafe turns off motors if a command is not sent in a certain amount of time.
  //Failsafe is set in milliseconds- comment or set to 0 to disable
  motor.setFailsafe(1000);
}

void loop(){
  int i;
  for(i=-maxPWM;i<maxPWM;i+=stepSize){
    delay(10);
    motor.setMotor(1,i);
    motor.setMotor(2,i);
  }
  for(i=maxPWM;i>-maxPWM;i-=stepSize){
    delay(10);
    motor.setMotor(1,i);
    motor.setMotor(2,i);
  }
}

Once the program is uploaded to the board, open up your Serial Monitor (you can find this under the Tools tab, or magnifying glass icon in the top right of the Arduino IDE), and then you should see your motors moving back and forth. If you want the motors to begin moving as soon as the program is uploaded and power is connected, you can comment out the line:

//while(!SerialMonitorInterface)

in the setup() loop.


More Motors?!

If you want to add more motors to your project, you can do that! All you have to do is remove some address resistors noted on the board in order to use other, non-conflicting I2C addresses. You can use up to four different Dual Motor Shields at a time. You may see the line in the program noted:

MotorDriver motor(NO_R_REMOVED); // Default address with no Resistors removed

To add more motor objects for different Shields, you need to initialize the motor objects with different I2C addresses as well as removing the respective address resistors on the boards:

  • MotorDriver motor2(R1_REMOVED); // Add a second Dual Motor TinyShield by removing resistor R1
  • MotorDriver motor3(R2_REMOVED); // Add a third Dual Motor TinyShield by removing resistor R2
  • MotorDriver motor4(R1_R2_REMOVED); // Add a fourth Dual Motor TinyShield by removing resistors R1 and R2

Now get out there and make something move!


Downloads


Contact Us

If you have any questions or feedback, feel free to email us or make a post on our forum. Show us what you make by tagging @TinyCircuits on Instagram, Twitter, or Facebook so we can feature it.

Thanks for making with us!