1

I have a MCP23017 GPIO expander connected to four DRV8833 dual channel Motor drivers. This setup is later meant to drive eight motors concurrently. I tried testing a few patterns and noticed that sometimes when I set the pins on and off in small time increments (~0.005s) after a seemingly random amount of time (either immediately or after ~100+ iterations) the MCP has random pinvalues set to True which I never touched. This random fluctuation makes it very difficult to reliably control the motors.

Here is what the simplified sourcecode looks like

import board
import busio
from adafruit_mcp230xx.mcp23017 import MCP23017
from time import sleep
i2c = busio.I2C(board.SCL, board.SDA)
mcp = MCP23017(i2c)
pins = []
for i in range(15):
    pin = mcp.get_pin(i)
    pin.switch_to_output()
    pins.append(pin)

while True: pins[1].value = True pins[3].value = True running_motors=[(a,i.value) for a,i in enumerate(pins) if i.value] if len(running_motors)>2: raise sleep(0.001) pins[1].value = False pins[2].value = True pins[3].value = False pins[4].value = True sleep(0.001) pins[2].value = False pins[4].value = False sleep(0.5)

At first, running_motors only contains the values [(1, True), (3, True)]. However, after ~100-300 iterations suddenly it prints out [(0, True), (1, True), (3, True)].

This problem does not occur when no motors are connected to the motor drivers. I am using drone motors such as these ones with this setup. I read through the datasheets of both chips but was unable to figure out what may be causing this error, but I have no prior experience with electrical engineering.

Yes
  • 169
  • 7

0 Answers0