It's easy to use the MOSFET Driver with Python or CircuitPython. You can use this breakout with any CircuitPython microcontroller board or with a computer that has GPIO and Python thanks to Adafruit_Blinka, our CircuitPython-for-Python compatibility library.

CircuitPython Microcontroller Wiring

First, wire up a MOSFET driver to your board and attaching a motor to the MOSFET driver terminal blocks, as described on the Plugging into the Terminal Block page, exactly as shown below. Here's an example of wiring a Feather M4 to the MOSFET driver using one of the handy STEMMA JST PH cables:

DC Toy Hobby Motor
These are standard '130 size' DC hobby motors. They come with a wider operating range than most toy motors: from 4.5 to 9VDC instead of 1.5-4.5V. This range makes them perfect...
$1.95
In Stock
If the load that you are driving requires more than 3V, then it will not trigger with this circuit.
  • Board 3V to driver V+ (red wire)
  • Board GND to driver GND (black wire)
  • Board pin 5 to driver In (white wire)
  • Motor black wire to driver terminal block -
  • Motor red wire to driver terminal block +

You can also use standard 0.100" pitch headers to wire it up on a breadboard:

  • Board 3V to driver V+ (red wire)
  • Board GND to driver GND (black wire)
  • Board pin 5 to driver In (white wire)
  • Motor black wire to driver terminal block -
  • Motor red wire to driver terminal block +

Python Computer Wiring

Since there's dozens of Linux computers/boards you can use, below shows wiring for Raspberry Pi. For other platforms, please visit the guide for CircuitPython on Linux to see whether your platform is supported.

Here's the Raspberry Pi wired to the MOSFET driver with a motor and a STEMMA JST PH cable:

  • Pi 3V to driver V+ (red wire)
  • Pi GND to driver GND (black wire)
  • Pi GPIO #5 to driver In (white wire)
  • Motor black wire to driver terminal block -
  • Motor red wire to driver terminal block +

Finally here is an example of how to wire up a Raspberry Pi to the MOSFET driver with a motor using a solderless breadboard:

  • Pi 3V to driver V+ (red wire)
  • Pi GND to driver GND (black wire)
  • Pi GPIO #5 to driver In (white wire)
  • Motor black wire to driver terminal block -
  • Motor red wire to driver terminal block +

Python Installation

You'll need to install the Adafruit_Blinka library that provides the CircuitPython support in Python. This may also require enabling I2C on your platform and verifying you are running Python 3. Since each platform is a little different, and Linux changes often, please visit the CircuitPython on Linux guide to get your computer ready!

CircuitPython Usage

To use with CircuitPython, you need to update code.py with the example script.

Thankfully, this can be done in one go. In the example below, click the Download Project Bundle button below to download the necessary libraries and the code.py file in a zip file. Extract the contents of the zip file, and copy the code.py file to your CIRCUITPY drive.

CIRCUITPY

Python Usage

Once you have the library pip3 installed on your computer, copy or download the following example to your computer, and run the following, replacing code.py with whatever you named the file:

python3 code.py

Example Code

# SPDX-FileCopyrightText: 2022 Liz Clark for Adafruit Industries
#
# SPDX-License-Identifier: MIT

import time
import board
from digitalio import DigitalInOut, Direction

# motor output
solenoid = DigitalInOut(board.D5)
solenoid.direction = Direction.OUTPUT

while True:
    solenoid.value = False
    print("The motor is not triggered.")
    time.sleep(1)
    solenoid.value = True
    print("The motor is triggered.")
    time.sleep(1)

If running CircuitPython: Once everything is saved to the CIRCUITPY drive, connect to the serial console to see the data printed out!

If running Python: The console output will appear wherever you are running Python.

In the example, the pin connected to the breakout is set as an output. Then, in the loop, the pin is turned True and False, toggling the load on and off. In the REPL, the load's status is printed. You'll also see the connected load trigger off and on.

This guide was first published on Dec 14, 2022. It was last updated on Jun 24, 2024.

This page (CircuitPython & Python) was last updated on Jun 24, 2024.

Text editor powered by tinymce.