Stepper motor hat and pi5

I just bought the pi5 and stepper motor hat from core electronics (adafruit) to run a stepper motor. I have a couple of questions:

  1. Can you tell me the pinout of the hat for A1 A2 B1 and B2 of a stepper motor. This is not labelled or in the documentation.

  2. The documentation says to run “pip3 install adafruit-circuitpython-motorkit`” but I can not get this to work at all on the pi5. Can anyone help?

Thanks so much. I would appreciate any help to get going

Cheers

1 Like

Can you tell me a little more about this.
Did you throw this command into your terminal and get and error message?
What did the error say?

1 Like

Hi @Chris11134, Welcome to the Forums!!!

If you’re unsure the Product Wiki and the Schematic have the answers.

This part of the schematic should be what you’re after.
image

As Pixmusic said, If you could let us know the exact error you’re facing that would greatly help us be able to point you in the right direction.

I have a suspicion that it’s not letting you install the library due to changes in how Bookworm handles python libraries and using the Python Virtual Environment.

Thanks. Yes I think the error is due to Bookworm.

I get this error:

Error: Externally-managed-environment

Try apt install python3-xyz where xyz is the package you are trying to install.

By the way, I tried apt install python3-adafruit-circuitpython-motorkit to no avail

I get “could not open lock file…”

Hi @Chris11134,

It would be good to read up on Virtual Environments with Bookworm.
This ADAFruit guide alongside the Raspberry Pi documentation and our own Thonny Virtual Environment Guide should be able to get you on your way with this project

The PyPi page for the library does have a mostly Cut and Paste way to get it working but I would highly recommend looking into understanding what each command is doing.

1 Like

Thanks for that. I have installed it successfully: pip3 install adafruit-circuitpython-motorkit in the directory stepper2.

But when I run a python script in that directory, I get the following error:

traceback (most recent call last):
File “/home/pi/stepper2/stepper2.py”, line 2, in
from adafruit_motorkit import MotorKit
ModuleNotFoundError: No module named ‘adafruit_motorkit’

Is there anything you might suggest as to what I am doing wrong?

This is just the simple code in the script:

import time
from adafruit_motorkit import MotorKit

kit = MotorKit()

for i in range(100):
kit.stepper1.onestep()

Thanks

Hi @Chris11134,

That error is from the Libary not being installed in the Virtual Environment you are trying to run the script in.

I would recommend following the steps in our guide here for creating a Virtual Environment in Thonny and installing libraries using Thonny to that environment.

The AdaFruit Circuitpython Motorkit library is available through the Thonny Library manger.

1 Like

Thanks so much for your help. That is tremendous support. I have gotten the step motor working in the virtual environment using Thonny to set it all up. By the way, is it normal for the ICs on the motor hat to get very hot ?

I am just wondering if you might be able to help with a further problem of having to run the hat in a virtual environment. In my project, I am wanting to combine the stepper function with the camera.

Thus I installed picamera2 into my virtual environment using Thonny.

  • When I open my picamera2 script in Thonny within the virtual environment, I get "ModuleNotFoundError: No module named ‘picamera2’.

  • When I open terminal from Thonny in the virtual environment, picamera2 is found as rpicam-hello works.

  • When I run the script in the normal (ie not virtual) environment then the script works.

Have you any suggestions for how to get the picamera2 script working in Thonny within the virtual environment so that it can combine the stepper code with the picamera2 code.

Cheers

Chris

Hi @Chris11134,

It sounds like Picamer2 isn’t part of your virtual environment.

This post from Raspberry Pi should help clear some things up.

1 Like