SparkFun Support and Front Desk will be closed on Thursday 11/14 from 1-2:30pm for a company event. Please plan to pick up your orders before or after this timeframe.

Member #1069886

Member Since: July 20, 2017

Country: United States

  • And here is a short implementation example:

    car = motobit()
  • Here is a handy class for people who want to program the moto:bit in micropython:

    from microbit import *
    class motobit:
        #8-bit index of the motobit functions (expressed in hex)
        left_motor = 0x21
        right_motor = 0x20
        motor_enable = 0x70
        invert_left = 0x12
        invert_right = 0x13
        #8-bit address of the motobit itself (expressed in hex)
        motobit_address = 0x59
        #method to combine an 8-bit index with an 8-bit command and send it to the motobit via i2c
        def write16bit(self, index, command):
            i2c.write(self.motobit_address,bytes([index, command]), repeat = False)
        #method to enable the motors, use motobit.enable(1) to enable motors
        def enable (self, run):
            self.write16bit(self.motor_enable, run)
        #method to run a single motor
        #power is in the range [-127,127] and will be clipped if too big
        def run_motor (self, motor, power):
            # add 128 to the power because the actual range of input is 0-255
            #now make sure power is in the range 0-255
            if power < 0: 
                power = 0
            elif power > 255:
                power = 255
            #send the command to drive the appropriate motor
            self.write16bit(motor, power)
        #method to drive both motors 
        def drive(self, left_speed, right_speed):
            self.run_motor(self.right_motor, right_speed)
            self.run_motor(self.left_motor, left_speed)
        #method to invert the left motor, use motobit.invert_left_motor(1) to enable, (0 to disable)
        def invert_left_motor(self, invert):
        #method to invert the right motor, use motobit.invert_right_motor(1) to enable, (0 to disable)
        def invert_right_motor(self, invert):

No public wish lists :(