Configure a 28byj48 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 2048 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 robot, first configure the board to which the motor driver is wired.
Then, add the motor:
Navigate to the Config tab of your robot’s page in the Viam app.
Click on the Components subtab and navigate to the Create component menu.
Enter a name for your motor, select the type motor
, and select the 28byj48
model.
Click Create component.
Edit and fill in the attributes as applicable.
{
"components": [
{
"name": "<your-board-name>",
"type": "board",
"model": "<your-board-model>",
"attributes": {},
"depends_on": [],
},
{
"name": "<your-motor-name>",
"type": "motor",
"model": "28byj48",
"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",
"type": "board",
"model": "pi"
},
{
"name": "example-motor",
"type": "motor",
"model": "28byj48",
"attributes": {
"board": "example-board",
"pins": {
"in1": "16",
"in2": "18",
"in3": "29",
"in4": "22"
},
"ticks_per_rotation": 200
}
}
]
}
The following attributes are available for 28byj48
motors:
Name | Type | Inclusion | 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, 4096 steps is 360°. One full rotation is 4096 steps. |
Refer to your motor and motor driver data sheets for specifics.
Have questions, or want to meet other people working on robots? Join our Community Discord.
Was this page helpful?
Glad to hear it! If there is anything we could be doing better, please create an issue.
We're sorry about that. If you'd like to talk to us for help, please join the Community Discord. To ensure we know what's wrong with this page, you can also open an issue.