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.

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.

A 28byj48 motor config.

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:

NameTypeInclusionDescription
boardstringRequiredname of the board the motor driver is wired to.
pinsobjectRequiredA 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_rotationintRequiredNumber 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.