Skip to content

Dual Motor TinyShield Tutorial

This tutorial will teach you how to use the Dual Motor TinyShield so that your next project can use some tiny motors.

To learn more about the TinyDuino Platform, click here


Description

The Dual Motor TinyShield allows you to drive two independently controlled DC brushed motors from your TinyDuino. 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 TinyShield includes a built-in motor controller to make driving motors simple and uses the TinyDuino I2C interface - saving GPIO pins on the TinyDuino processor for other tasks. An easy-to-use Arduino library is provided to control this.

Since this TinyShield uses I2C for communication, multiple Dual Motor TinyShields can be stacked on the same TinyDuino board (up to four Dual Motor TinyShields, or 8 different motors). To do this, you just need to remove some resistors to change the I2C addresses of the additional boards. More on this later.

The board includes bypass capacitors a heatskink for the chips. The heatsink is located on a large plane on the bottom side of the board. An external power connection is supplied to connect to your motor power source. All the connections to the motors use standard 0.1″ spaced holes that you can solder your motor leads into.  

The TI DRV8837 has one H-bridge driver consisting of N-channel power MOSFETs to drive a DC motor, one winding of a stepper motor, or other devices like solenoids. An internal charge pump generates needed gate-drive voltages. There are internal shutdown functions for overcurrent protection, short-circuit protection, undervoltage lockout and over temperature. The DRV8837 can supply up to 1.8 A of output current. It operates on a motor power-supply voltage from 1.8 V to 11 V .

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.

To see what other TinyShields are compatible with this TinyShield, see the TinyShield Compatibility Matrix

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
TinyDuino 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 TinyShields can be stacked together in one TinyDuino stack. However, the I2C address needs to be different for each TinyShield. This can be changed with resistors R1 and R2 (soldering is required for this).   
  • 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.  
  • Even though the motor driver can support 11V at 1.8Amps, we do not recommend using more than a 5V motor at 500mA due to the small size.  
  • 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.
  • The board kinda looks like a surprised face.
  • You don't 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 if that is something you are interested in.
  • 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 TinyShield using the 32 pin tan connectors. Then plug in the battery and the motor(s) to your Motor TinyShield.

If you selected the Dual Motor TinyShield 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 motor library in order to use the example program in this tutorial. A zip file of the library is included under the Software Materials. Once downloaded, you will need to put the unzipped, downloaded library folder under your \Arduino\library folder. The default placement for this folder is under the \Documents folder on Windows and Macintosh devices.

After this library is properly included in the Arduino library, you should be able to download and use the Basic Motor Example program. This example is also included in a zip file under the Software Materials.

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 TinySheild Basic Example
  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 30 July 2015
  By Ben Rose
  Modified 24 May 2019
  By Hunter Hykes
  https://TinyCircuits.com
*/

#include <Wire.h>
#include "MotorDriver.h"
//#define Serial SerialUSB
MotorDriver motor(2);//value passed is the address- remove resistor R1 for 1, R2 for 2, R1 and R2 for 3

int maxPWM = 10000;
int steps = 100;
int stepSize = maxPWM / steps;

void setup() {
  Serial.begin(9600);
  Wire.begin();
  //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)) {
    Serial.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 TinyShields 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 TinyShields, 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 some projects MOVE!


Contact Us

If you have any questions or feedback, feel free to email us at info@tinycircuits.com or make a post on the forum.

Show us what you make by tagging @TinyCircuits on Instagram, Twitter, or Facebook so we can feature it!

Thanks for making with us!


Downloads