Skip to content

Instantly share code, notes, and snippets.

@stonehippo
Last active November 28, 2024 19:31
Show Gist options
  • Save stonehippo/6b9f2f0d4cbec54f61ddb91adcd0b289 to your computer and use it in GitHub Desktop.
Save stonehippo/6b9f2f0d4cbec54f61ddb91adcd0b289 to your computer and use it in GitHub Desktop.
A class for the SparkFun moto:bit for use with BBC micro:bit micro python

SparkFun moto:bit driver for BBC micro:bit micropython

The SparkFun moto:bit is a motor controller carrier for the BBC micro:bit. This board is also available as part of the SparkFun micro:bot kit.

SparkFun provides a MakeCode extension for using this board, but no driver for working with the board using micro:bit-flavored micropython. Given the spiffy new micro:bit Python Editor, it would nice to be able to program this motor controller in micropython. This class makes that easy to do.

The code has been moved to a new repo: https://github.com/stonehippo/micropython_motobit.

Usage

The Python Editor doesn't support loading modules (I think), so the easiest thing to do right now is copy and paste the class into the editor. The Python Editor supports creating additional files (in the Project tab). My suggestion is to copy motobit.py contents into a new file. Once that's done, it's pretty easy to get things going:

from motobit import Motobit

mb = Motobit()
mb.set_motor_speed(Motobit.RIGHT, 55)
mb.set_motor_speed(Motobit.LEFT, 55, reverse=True)
mb.enable() # turn on the motors, and go!
...
mb.disable() # turn the motors off

This code was based on the moto:bit PXT extension.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment