MicroPython Robot: Part 1

“They’re my friends. I make them.”

– J. F. Sebastian, Blade Runner

The first major project I’m undertaking is the MicroPython and pyboard powered robot.

I’ve decided to split development of this robot over a number of parts, with each one dedicated to a particular task or goal.

This first part deals with the physical construction of the robot, the design choices, and some simple code to make sure things are working as expected before I move on to more complex endeavours in Part 2.

The first question I had to ask myself when considering this project was: What kind of robot do I want to build? There are literally thousands of different designs out there, from robots that can scale walls, to those that can walk, talk, and squirt tomato ketchup. It’s easy to get carried away with these things, and as much as I’d love to build something amazing I had to face the fact that I’m a complete novice, and so I had to start from the bottom, which in robotic terms is a two-wheel buggy that you’re hoping you can make go forwards and backwards without too much difficulty.

Design choice made (for me), I moved onto the construction of the chassis.

For while I toyed with the idea of building the chassis of the robot from scratch; however building a lightweight and straight(!) frame is harder than it looks, and I also lacked the tools required to do a good enough job to appease my OCD. So I decided that purchasing an off-the-shelf chassis was going to be the best option for this project. If things go well then maybe I will consider a handmade or 3D printed one for the next robot.

Handily, the pyboard has built-in support for both traditional and continuous rotation servos, which really helped me narrow down my options for the off-the-shelve chassis, as continuous rotation servos make the perfect motors to drive the wheels of a small robot.

As luck would have it, after a brief search on Amazon, I found the perfect kit, which you can see below. This had mounts for continuous rotation servos, and actually came with the servos themselves plus the wheels to stick onto them! It was also fairly big which will give me options for future expansion.

MicroPython Robot Chassis Parts
MicroPython Robot Chassis Parts

Unfortunately, the exact chassis kit I purchased above is no longer available; however there’s a similar one but you’d need to buy the continuous rotation servos separately,  as the kit comes with normal motors which are not supported out of the box by the pyboard. You can get this alternate frame on  Amazon along with the servos.

The assembly of the frame was fairly straightforward, although bolting the servos into their mounts was a bit fiddly. You’ll definitely need pliers and one of those precision screwdriver sets for this, but after 20 minutes toil the whole thing was together and ready for the pyboard to be mounted.

MicroPython Robot Chassis Bottom
MicroPython Robot Chassis Bottom
MicroPython Robot Chassis Top
MicroPython Robot Chassis Top

Mounting the pyboard was fairly easy too as it comes with two mounting lugs. So in my haste to get the robot up and running I stuck a bolt through them and used some nuts and a couple of small o-rings to stand the pyboard off from the chassis to protect it from short circuits. I will probably redo the mounting in the future to make it more sturdy … and straight.

MicroPython Robot Complete
The Completed MicroPython Robot

 

“Number 5 is alive.”

– Number 5, Short Circuit

Robot assembled, it was time to make sure everything was working correctly.

The pyboard can be controlled via USB with the built in REPL using a serial program. More information about this can be found here.

I decided to use the serial program minicom to connect to the pyboard. To install it on ubuntu based systems use the following command in the terminal:

sudo apt-get install minicom

Once installed, plug the pyboard into the USB and then run the following in the terminal:

sudo minicom --device /dev/ttyACM0

As it mentions in the documentation, you may need to use /dev/ttyACM1 or a higher number to get a successful connection. All being well you should be presented with the following:

Welcome to minicom 2.7

OPTIONS: I18n
Compiled on Feb 7 2016, 13:37:27.
Port /dev/ttyACM0, 18:16:48

Press CTRL-A Z for help on special keys

MicroPython v1.8 on 2016-05-03; PYBv1.0 with STM32F405RG
Type “help()” for more information.
>>>

Connection established and REPL working, I then started work on getting the servos turning.

Referring again to the documentation I created a servo object for each of the attached servos:

servo1 = pyb.Servo(1)
servo2 = pyb.Servo(2)

As soon as the objects were created however, the wheels started to turn, so I needed to set the speed to zero for each of them to get them to stop:

servo1.speed(0)
servo2.speed(0)

Unfortunately this did not have the desired effect! The wheels continued to turn albeit much slower than before. For a while I was stumped with this, but after some frantic googling I discovered the solution, and that was that the servos needed to be calibrated so that my zero, or stopped, was the same as the servos. Handily this is quite easy to do, and basically involves twisting the dial at the bottom of the servo using a precision screwdriver until the servo is stopped after setting the speed to zero using the above code.

Tuning the servos
Tuning the servos

Annoyingly I have found that after a while the servos can drift out of this tuning and being to slowly turn. I’m not really sure what the solution is to this yet, but it’s not a major problem for now.

Servos tuned it was full steam ahead for the robots maiden run, so I set the speed at 20 for each motor and let it loose…

servo2.speed(20)
servo1.speed(20)

But it didn’t go anywhere fast, in fact it proceeded to spin around in a circle as the wheels were turning in opposite directions. Looking at the robot this made sense, as to get the wheels to line up the servos have to be mounted as mirror opposites. Happily, this is easily corrected in the code:

servo1.speed(20)
servo2.speed(-20)

Voilà! The buggy moved forward as desired!

Part 1: Mission accomplished!

In Part 2 I will focusing on exploring movement a lot more, including turning left and right.

One Reply to “MicroPython Robot: Part 1”

  1. I’m a highschool teacher learning Python with my students. So far we have dabbled with some small programs but I can see robotics may help keep their interest. I’m still deciding if I should go the Arduino, RaspberryPi or MicroPython route. Your blog has been informative. Thanks for taking the time to write the posts. I’ve subscribed 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

*

  +  forty eight  =  fifty seven