First Steps Creating a Robot with MicroPython and Pyboard
Tags: microcontrollers, python, hardware
Published: 2020-07-20 18:02:05

<span>Photo by <a href="https://unsplash.com/@alexkixa?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Alexandre Debiève</a> on <a href="https://unsplash.com/s/photos/electronics?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></span>


<br/><br/>

## What are MicroPython and PyBoard

[MicroPython](https://micropython.org/) is a software implementation of the Python 3 programming language, written in C, that is optimised to run on a microcontroller.

It was [Damien George](https://github.com/dpgeorge) who created MicroPython. He developed it along with running a Kickstarter campaign to fund it and the [pyboard](http://docs.micropython.org/en/latest/pyboard/quickref.html).

The pyboard is a compact and powerful electronics development board that runs MicroPython.

The aim of MicroPython is not to replace C, but to provide a way to program microcontrollers using Python.

## Why Build a Robot

After [finishing the 'Intro to Self Driving Cars' program](https://www.halldorstefans.com/why-i-took-udacitys-intro-to-self-driving-cars-nanodegree-and-was-it-worth-it/), I wanted to build something, like a small car.

And I wanted it to be able to drive around without crashing by sensing its environment.

I started by buying a small [robot kit](https://thepihut.com/products/adafruit-mini-3-layer-round-robot-chassis-kit-2wd-with-dc-motors), which included a chassis, two DC motors, wheels, and a caster ball for balance.
But of course, I would need something that would control the motors, and be the "driver".

## Why Use MicroPython

I already owned a pybord that I had bought about four or five years ago. But, since then, it had been a dust collector.

I had written some small programs to turn the LEDs on and off, but that was it. I never tried to connect a component to it, and get that to work.

I thus thought this would be an excellent opportunity to finally use the pyboard. But I didn't know how it worked.

Therefore I didn't know how to get it to control my car.

## First steps

I needed to get familiar with the board and came across [these tutorials](http://docs.micropython.org/en/latest/pyboard/tutorial/index.html) for the pyboard.
The first ten tutorials are good to get started, needing only the pyboard, a USB cable and a computer. It's a helpful introduction to the board and its possibilities.

In the second part of the tutorials, you'll need some components. But I didn't have them all so; I did only the ones where I did have the elements.
It was a good feeling to get something physical to work.

But the motors in the robot kit I bought are DC motors, and none of the tutorials demonstrated how to control them.

So I wondered how to use the pyboard to control a DC motor.

## Next steps

Reading the description for the robot kit, I saw that run motors will need ~5V and 1.5 A.
But according to [this response](https://forum.micropython.org/viewtopic.php?t=79) on the MicroPython forum, the max current per pin is 25mA.
We see there's a considerable gap between what the motors need and what the pyboard can provide.

After a [bit of research](https://forum.micropython.org/viewtopic.php?f=2&t=277&sid=b155e9c04bf7d79d45324b619f7c4e6d), I realised that I needed something to control the motors.

So my next steps are to understand better what I need and how to use it.

---

If you liked what you read, please consider signing up to my [newsletter](https://email.halldorstefans.com/)