One of the cool things about this HAT design is that it is possible to stack them. Every HAT you stack can control another 2 steppers or 4 DC motors (or a mix of the two)

You can stack up to 32 HAT for a total of 64 steppers or 128 DC motors! Most people will probably just stack two or maybe three but hey, you never know. (PS if you drive 64 steppers from one Raspberry Pi send us a photo, OK?)

If you need to control a bunch of servos as well, you can use our 16-channel servo HAT and stack it with this HAT to add a crazy large # of servos.

Stacking HATs is very easy. Each HAT you want to stack on top of must have stacking headers installed. The top HAT does not have to have stacking headers unless you eventually want to put something on top of it.

The only thing to watch for when stacking HATs is every HAT must have a unique I2C address. The default address is 0x60. You can adjust the address of the motor HATs to range from 0x60 to 0x80 for a total of 32 unique addresses.

Addressing the HATs

Each board in the stack must be assigned a unique address. This is done with the address jumpers on the left side of the board. The I2C base address for each board is 0x60. The binary address that you program with the address jumpers is added to the base I2C address.

To program the address offset, use a drop of solder to bridge the corresponding address jumper for each binary '1' in the address.

The bottom-most jumper is address bit #0, then the one above of that is address bit #1, etc up to address bit #5

Board 0: Address = 0x60 Offset = binary 0000 (no jumpers required)
Board 1: Address = 0x61 Offset = binary 0001 (bridge A0)
Board 2: Address = 0x62 Offset = binary 0010 (bridge A1, the one above A0)
Board 3: Address = 0x63 Offset = binary 0011 (bridge A0 & A1, two bottom jumpers)
Board 4: Address = 0x64 Offset = binary 0100 (bridge A2, middle jumper)


Note that address 0x70 is the "all call" address for the controller chip on the HAT. All boards will respond to address 0x70 - regardless of the address jumper settings.

Stacking in Code

Now that you've changed the I2C address on the hardware, you need to set it in your code. When you initialise the class, you can set the address.

from adafruit_motorkit import MotorKit
# Initialise the first hat on the default address
kit1 = MotorKit()
# Initialise the second hat on a different address
kit2 = MotorKit(address=0x61)

Then you can use kit1 and kit2 to control the motors attached to the associated hat.

This guide was first published on Jan 27, 2015. It was last updated on Dec 09, 2023.

This page (Stacking HATs) was last updated on Jan 23, 2015.

Text editor powered by tinymce.