P
ython is one of the fastest growing
languages in the world. It’s accessible
enough for schools to teach as a first
programming language but powerful enough
to handle the complexities of some of the most
widely used web services, including Instagram,
Spotify, and Netflix. And now Python’s star is
rising in the world of physical computing too.
Languages like C and C++ and their cousin
Arduino used to dominate hardware, from
hobbyists in garages to engineers in industry. But
these days, thousands of makers are switching
to Python to control hardware, whether they’re
programming microcontrollers or designing
microprocessors. Today more than 130
microcontroller boards support Python, including
the original Pyboard, the blazing Teensy 4.0, the
tiny Serpente, a host of Adafruit boards, and even
five Arduinos.
In this article, we’ll explore the reasons behind
this shift, talk about why you might (or might
not!) want to use Python in your next project, and
take a look at some cool hardware projects and
technologies that use Python.
Best for Beginners?
Beginner programmers often ask, “Which
language is best to learn: Python or C++?” There’s
no definitive answer, of course, but here are some
reasons why many programmers might well
respond with “Python.” Let’s start off with user
friendliness. When you upload your code to an
Arduino board, your computer compiles it into a
machine-readable binary format. The semicolons
and curly braces in your code help the compiler
to identify where statements and function blocks
begin and end. Python doesn’t require semicolons
to end lines and instead relies on indentation to
distinguish code blocks. This has the benefit
of making Python code very human-readable
and clean.
Python is also not as nosy about your variables
because as an interpreted language it doesn’t
require the programmer to manage memory
Python manages memory for you. Data types
for variables in C languages (floats, integers,
const signed long, etc.) have to be declared,
but Python will happily interpret these for
you. Because the language isn’t compiled but
interpreted, you can also skip all those pesky
considerations that have to do with memory
management, like “Should I use a constant? Is
this a long or a short? Do I need to use a pointer?”
Python is also a fantastic choice for rapid
prototyping because of its readability and ability
to run without needing to compile. When you
upload your code to an Arduino, it has to compile
and flash the hardware, which takes time. When
you save your CircuitPython code to a board, it
skips that step and executes the code as soon
as you hit Save. But hold up! This doesn’t make
Python code faster. Compiled languages like C++
are actually much faster, because they don’t have
to be interpreted at runtime. For projects where
speed is of the essence (for example, when using
extra demanding sensors or actuators), this is
something to consider, but for most beginner
maker projects it won’t likely be an issue.
MicroPython and CircuitPython
Two Python implementations are heating up the
microcontroller world. First up is MicroPython
(micropython.org), created by Damien George
for the STM32 chip but now popularly used by
both the BBC micro:bit as well as the ESP32.
MicroPython is a direct translation of Python with
its own interpreter.
The other big player is CircuitPython
(circuitpython.org), a fork of MicroPython
maintained by Adafruit Industries. CircuitPython’s
goal is to lower the barrier to entry for beginner
programmers, so the Adafruit team have decided
to sacrifice some functionality in exchange for
simplicity. We’ll show off some of its features
later in this article.
Kattni Rembor, Adafruit
Python
Hardware
Space saver: Mini SAM is a Lego minifigure-sized
microcontroller board by Benjamin Shockley, based on
the Python-compatible Microchip SAMD51G.
29
makeprojects.com
M74_028-34_SS_Python_F1.indd 29M74_028-34_SS_Python_F1.indd 29 7/17/20 10:46 AM7/17/20 10:46 AM
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset