Skip to content

Instantly share code, notes, and snippets.

@robo8080
Last active September 19, 2017 01:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robo8080/47ec85a1a71c124aadec4ddc320635ca to your computer and use it in GitHub Desktop.
Save robo8080/47ec85a1a71c124aadec4ddc320635ca to your computer and use it in GitHub Desktop.
#MicroPython + Grove I2C motor driver
from microbit import *
#i2c.init(freq=100000, sda=pin20, scl=pin19)
while True:
# Forwards
print('Forwards')
display.show(Image.ARROW_N)
i2c.write(0x0f, bytearray([0x82,0x46,0x46]))
i2c.write(0x0f, bytearray([0xaa,0x0a,0x01]))
sleep(3000)
# Stop
i2c.write(0x0f, bytearray([0x82,0x00,0x00]))
i2c.write(0x0f, bytearray([0xaa,0x0a,0x01]))
sleep(2000)
# Backwards
display.show(Image.ARROW_S)
print('Backwards')
i2c.write(0x0f, bytearray([0x82,0x46,0x46]))
i2c.write(0x0f, bytearray([0xaa,0x05,0x01]))
sleep(3000)
# Stop
i2c.write(0x0f, bytearray([0x82,0x00,0x00]))
i2c.write(0x0f, bytearray([0xaa,0x0a,0x01]))
sleep(2000)
# Slow Turn Left
display.show(Image.ARROW_W)
print('Left Turn')
i2c.write(0x0f, bytearray([0x82,0x46,0x46]))
i2c.write(0x0f, bytearray([0xaa,0x09,0x01]))
sleep(3000)
# Stop
i2c.write(0x0f, bytearray([0x82,0x00,0x00]))
i2c.write(0x0f, bytearray([0xaa,0x0a,0x01]))
sleep(2000)
# Sharp Right Turn
display.show(Image.ARROW_E)
print('Right Turn')
i2c.write(0x0f, bytearray([0x82,0x46,0x46]))
i2c.write(0x0f, bytearray([0xaa,0x06,0x01]))
sleep(3000)
# Stop
i2c.write(0x0f, bytearray([0x82,0x00,0x00]))
i2c.write(0x0f, bytearray([0xaa,0x0a,0x01]))
sleep(5000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment