It's easy to use the 8 Channel Solenoid Driver with Python or CircuitPython, and the Adafruit CircuitPython MCP23017 module. This module allows you to easily write Python code that adds up to 16 inputs or outputs over I2C.
You can use this driver with any CircuitPython microcontroller board or with a computer that has GPIO and Python thanks to Adafruit_Blinka, our CircuitPython-for-Python compatibility library.
You'll need a solenoid motor, external DC power supply and a DC jack to terminal block adapter to follow this example.



CircuitPython Microcontroller Wiring
First wire up the breakout to your board exactly as follows. The following is the breakout wired to a Feather RP2040 and two solenoid motors:
-
Board 3.3V to breakout Vcc (red wire)
-
Board GND to breakout GND (black wire)
-
Board SCL to breakout SCL (yellow wire)
- Board SDA to breakout SDA (blue wire)
- Motor 1 positive to breakout + (red wire)
- Motor 1 negative to breakout A0 (black wire)
- Motor 2 positive to breakout + (red wire)
- Motor 2 negative to breakout A4 (black wire)
- DC power supply GND to breakout terminal block GND (black wire)
- DC power supply positive to breakout terminal block V+ (red wire)
Python Computer Wiring
Since there are dozens of Linux computers/boards you can use, we will show 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 breakout with two solenoid motors:
-
Pi 3.3V to breakout Vcc (red wire)
-
Pi GND to breakout GND (black wire)
-
Pi SCL to breakout SCL (yellow wire)
- Pi SDA to breakout SDA (blue wire)
- Motor 1 positive to breakout + (red wire)
- Motor 1 negative to breakout A0 (black wire)
- Motor 2 positive to breakout + (red wire)
- Motor 2 negative to breakout A4 (black wire)
- DC power supply GND to breakout terminal block GND (black wire)
- DC power supply positive to breakout terminal block V+ (red wire)
Python Installation of MCP230xx Library
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!
Once that's done, from your command line run the following command:
pip3 install adafruit-circuitpython-mcp230xx
If your default Python is version 3 you may need to run 'pip' instead. Just make sure you aren't trying to use CircuitPython on Python 2.x, it isn't supported!
CircuitPython Usage
To use with CircuitPython, you need to first install the Adafruit_CircuitPython_MCP230xx library, and its dependencies, into the lib folder on your CIRCUITPY drive. Then you need to update code.py with the example script.
Thankfully, we can do this 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 entire lib folder and the code.py file to your CIRCUITPY drive.
Your CIRCUITPY/lib folder should contain the following folders:
- adafruit_bus_device/
- adafruit_mcp230xx/

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
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.
# SPDX-FileCopyrightText: 2025 Liz Clark for Adafruit Industries # # SPDX-License-Identifier: MIT import time import board from adafruit_mcp230xx.mcp23017 import MCP23017 i2c = board.STEMMA_I2C() mcp = MCP23017(i2c) noid_1 = mcp.get_pin(0) noid_2 = mcp.get_pin(4) noid_1.switch_to_output(value=False) noid_2.switch_to_output(value=False) while True: noid_1.value = True print(f"Solenoid 1: {noid_1.value}, Solenoid 2: {noid_2.value}") time.sleep(0.2) noid_1.value = False print(f"Solenoid 1: {noid_1.value}, Solenoid 2: {noid_2.value}") time.sleep(0.2) noid_2.value = True print(f"Solenoid 1: {noid_1.value}, Solenoid 2: {noid_2.value}") time.sleep(0.2) noid_2.value = False print(f"Solenoid 1: {noid_1.value}, Solenoid 2: {noid_2.value}") time.sleep(1) noid_1.value = True noid_2.value = True print(f"Solenoid 1: {noid_1.value}, Solenoid 2: {noid_2.value}") time.sleep(1) noid_1.value = False noid_2.value = False print(f"Solenoid 1: {noid_1.value}, Solenoid 2: {noid_2.value}") time.sleep(2)
First, the MCP23017 is instantiated over I2C. Then, in the loop, the solenoid connected to pin A0 on the breakout is toggled, followed by the solenoid connected to pin A4. Both motors are then turned on and turned off together. You'll see your motors move and the corresponding LEDs on the breakout turn on and off.
Page last edited April 15, 2025
Text editor powered by tinymce.