Configure a 28BYJ-48 Stepper Motor
The 28byj48
model of the motor component supports small unipolar stepper motors controlled by stepper motor drivers like ULN2003. The 28byj48
is often used for low-current and low-precision applications and supports full, half, and quarter stepping with 4096 steps in a rotation in full-step mode.
Tip
Viam also supports:
- stepper motors with higher step resolution with the
gpiostepper
model - advanced stepper driver chips like TMC5072 or DMC4000 that have their own microcontrollers that handle things like speed and acceleration control
To configure a 28byj48
motor as a component of your machine, first configure the board to which the motor driver is wired.
Then, add the motor:
Navigate to the CONFIGURE tab of your machine’s page in the Viam app.
Click the + icon next to your machine part in the left-hand menu and select Component.
Select the motor
type, then select the 28byj48
model.
Enter a name or use the suggested name for your motor and click Create.
Edit and fill in the attributes as applicable.
{
"components": [
{
"name": "<your-board-name>",
"model": "<your-board-model>",
"type": "board",
"namespace": "rdk",
"attributes": {},
"depends_on": [],
},
{
"name": "<your-motor-name>",
"model": "28byj48",
"type": "motor",
"namespace": "rdk",
"attributes": {
"board": "<your-board-name>",
"pins": {
"in1": "<pin-number>",
"in2": "<pin-number>",
"in3": "<pin-number>",
"in4": "<pin-number>"
},
"ticks_per_rotation": <int>
},
"depends_on": []
}
]
}
Example configuration for a 28byj48
stepper motor:
{
"components": [
{
"name": "example-board",
"model": "pi",
"type": "board",
"namespace": "rdk"
},
{
"name": "example-motor",
"model": "28byj48",
"type": "motor",
"namespace": "rdk",
"attributes": {
"board": "example-board",
"pins": {
"in1": "11",
"in2": "12",
"in3": "13",
"in4": "15"
},
"ticks_per_rotation": 4096
}
}
]
}
The following attributes are available for 28byj48
motors:
Name | Type | Required? | Description |
---|---|---|---|
board | string | Required | name of the board the motor driver is wired to. |
pins | object | Required | A JSON object containing the pin numbers the in1 , in2 , in3 , and in4 pins of the motor driver are wired to on the board. |
ticks_per_rotation | int | Required | Number of full steps in a rotation. The motor takes 5.625*(1/64)° per step. One full rotation (360°) is 4096 steps. |
Refer to your motor and motor driver data sheets for specifics.
Test the motor
Once your motor is configured and connected, open the motor’s TEST panel on the CONFIGURE or CONTROL tabs. Use the buttons to try turning your motor forwards or backwards at different power levels and check whether it moves as expected.
If the motor does not appear on the TEST panel, or if you notice unexpected behavior, check your machine’s LOGS tab for errors, and review the configuration.
Have questions, or want to meet other people working on robots? Join our Community Discord.
If you notice any issues with the documentation, feel free to file an issue or edit this file.
Was this page helpful?
Glad to hear it! If you have any other feedback please let us know:
We're sorry about that. To help us improve, please tell us what we can do better:
Thank you!