Monday, 5 March 2012

Arduino and Python Tutorial

Hi there,

I've been working on ideas for my CNC machine/3D-printer and I've decided that making it a computer "peripheral" will be the best idea. This way my computer can do all the heavy lifting and the arduino should only have to drive the stepper motors.

While looking at how the RepRap works I found their microcontroller uses G-code. What is G-code you might ask? It actually tells the 3D-printer what type of movement (linear, circular,...) and for how far to follow that movement. Since there are already free open source CAD programs (Google Sketchup, Blender) that will save as .stl files and an open source program named Skeinfordge that converts .stl files to G-code, all the software needed on the computer is free! I may develop a python or java program that takes interprets the G-code and then tells the arduino which steppers to move and how, but this could also be written into the arduino sketch so I wont worry about that just yet.

The first problem I encountered was how I was going to get all this information from my computer to the arduino. Well luckily the arduino is capable of serial communication while its connected to a computer. Now the challenge was to figure out how to do this. After a bit of researching it seemed like using python to communicate with my arduino would be the easiest. Python is already a fairly easy to understand language so learning it was not to hard. After a few aggravating hours I finally got my small blinking program to work. The idea was that python would send a message to the arduino and then the arduino would make an LED blink twice. Sadly the internet wasn't much help when nothing seemed to be working so this I figured I would make a small tutorial on how to get python running with an arduino.

Check out my step-by-step guide on Instructables!