Python has taken the coding world by storm. Alongside the rise of this new language, the DIY electronics scene has also flourished. Development boards and single board computers from companies like Arduino and Raspberry Pi have changed the way people create home brewed electronics. Wouldn’t it be awesome if you could program an Arduino with Python?
There is no better feeling than combining two cool things. Sadly, it is impossible to directly program an Arduino with Python, as the boards have no option for onboard interpretation of the language. What is possible however, is direct control over USB using a Python program.
Setting Up Your Arduino for Python
For today’s project we will be using an Arduino Uno, along with the pyFirmata interface for Python. You can use almost any Arduino-compatible board for this, though at the time of writing only the Arduino Uno, Mega, Due and Nano are supported by the pyFfirmata interface. If you are already a Python guru, you can add your own board support to pyFirmata — be sure to update their GitHub if you do!
Connect your Arduino board, and open up the IDE. Make sure you have the correct board and port selected in the Tools menu. Load up the StandardFirmata example sketch and upload it to the board. This will allow you to control the Arduino directly so long as it is connected to the computer via USB. Provided the sketch uploads to your board without any errors, you are ready to move on.