I've been interfacing the pyboard to all kinds of stuff to get a bunch of coding and practice under my belt before I really try to do something like a robot with it. I've ported my 5110 LCD C code for PIC to MicroPython, and connected things like servos, a HY-SRF05 ultrasonic range sensor, a Sharp GP2D12 infrared range sensor, neopixel LEDs, an SSD1306 OLED display, a motor h-bridge controller board & motor using PWM. Just because I was lazy I used someone else's class libraries for the neopixels and for the SSD1306 (for now). Eventually I'll probably write my own code.
Video of PWM control of a motor controller with a SSD1306 OLED display showing the PWM duty cycle. The motor controller is an old MicroCore-11 Quad Motor Driver Module:
Here's the MicroPython PyBoard code that's in the video. It's calling functions (methods?) in someone else's SSD1306 class, and the font is external as well. Right now I can't find where I downloaded it from - will find that and post here later:
import pyb
from pyb import Pin, Timer
from ssd1306 import SSD1306
# I2C connected to Y9, Y10 (I2C bus 2)
display = SSD1306(pinout={'sda': 'Y10',
'scl': 'Y9'},
height=64,
external_vcc=False)
display.poweron()
display.init_display()
p = Pin('X1') # X1 has TIM2, CH1
tim = Timer(2, freq=1000)
ch = tim.channel(1, Timer.PWM, pin=p)
while True:
for x in range(30,101):
ch.pulse_width_percent(x)
display.draw_text(5, 24, " ")
display.draw_text(5, 24, str(x))
display.display()
pyb.delay(70)
pyb.delay(2000)
for x in range(100,29,-1):
ch.pulse_width_percent(x)
display.draw_text(5, 24, " ")
display.draw_text(5, 24, str(x))
display.display()
pyb.delay(70)
pyb.delay(2000)