design products & applications – August 2019

(Ron) #1

C was intentionally designed to be
mapped easily into machine instructions
for a target processor. This bias towards
the needs of the machine over those
of the programmer is apparent in the
language’s syntax.


Python is also an object-oriented lan-
guage. Python’s syntactical design em-
phasises code readability – for humans



  • which is one key difference between
    Python and C++. Writability, closely as-
    sociated with readability, is another trait
    in Python’s favour. Writability means that
    Python is generally credited with allow-
    ing programmers to write applications
    more quickly.


A second major difference is that Py-
thon is an interpreted language. Like
Basic, the interpretive nature of Python
encourages experimentation, and there-
fore learning by dispensing with the edit/
compile/download/run development cy-
cle used for compiled programming lan-
guages. However, unlike Basic, Python
is a modern, higher level, object-ori-
ented language that incorporates half
a century’s worth of advances in com-
puter science that have appeared since
Basic was first developed.


For example, Python’s variables need
not be declared or typed before use.
Programmers need not worry whether a
variable should be an integer or a float-
ing-point number. The Python interpret-
er figures it all out and makes the appro-
priate choices at run time.


Two more differences between C++
and Python are string handling and
punctuation. Many programmers find
string handling in C++ to be obtuse
and confusing. Python’s string handling
is much simpler and very reminiscent
of Basic’s simple and well-liked string
handling capabilities.


Similarly, C and C++ punctuation – es-
pecially curly braces ({}) – are another
frequent stumbling block for new and
even experienced programmers. It feels
like there are always an odd number of
curly braces in a program, which means
the programmer must dig into the code
to find where the missing curly brace
should go. Python has no such finicky


punctuation, but it does use indentation,
which gives Python code its readability.

The origins of MicroPython
Like C and C++, Python was originally
designed to run on larger computers.
Consequently, the language required
too many resources to be used for
programming microcontrollers. Australian
programmer and physicist Damien George
therefore developed a version of Python
called MicroPython that could run on a
microcontroller’s more limited resources.

MicroPython’s interactive nature centres
on its command interface, formally called
the REPL (read-eval-print-loop) window,
which usually operates over a serial
connection that connects a host PC to
a microcontroller dev board. The REPL
interface accepts user inputs, evaluates
them, and then either returns results to the
user through the REPL window or performs
the command embedded in the statement.

Using the REPL interface, it’s possible
to query a variable, toggle an I/O line, or
send a string of characters to an attached
peripheral. The line is interpreted and
immediately executed as soon as the
enter key is pressed.

CircuitPython support for
dev boards
Each microcontroller has a unique set of
peripherals, and each dev board adds to
that list. These peripherals require support
libraries. This is true for both the Arduino
IDE and for MicroPython. In addition, there
are many add-on peripheral devices, like
Adafruit’s 1655 NeoPixel addressable
RGB LED, that also require library support.

To provide a higher degree of support,
Adafruit has developed its own version
of MicroPython, called CircuitPython.
The company has also converted many
peripheral libraries from its immense
Arduino collection to CircuitPython libraries.

Adafruit designed a line of microcontroller
dev boards explicitly to support CircuitPy-
thon.

These include:


  • 3333 Circuit Playground Express with
    ten addressable, controllable RGB
    LEDs (Figure 1)

    • 3500 Trinket M0 dev board that
      measures only 27mm x 15.3mm x
      2.75mm (Figure 2)

    • 3501 Gemma M0 is about the size
      of a US 25 cent piece (a quarter) and
      can be powered from its USB port or a
      separate battery port (Figure 3)

    • 3403 Feather M0 Express is a dev
      board that features a small breadboard
      area for custom circuitry (Figure 4)




These four Adafruit microcontroller dev
boards are all based on Microchip Tech-
nology‘s SAMD21 microcontrollers with
native USB support. Furthermore, versions
of CircuitPython for other dev boards with
other microcontrollers are also starting to
appear, including Adafruit’s 3406 Feath-
er NRF52 and Nordic Semiconductor’s
nRF52-DK dev boards, both based on
Nordic Semiconductor’s nRF52832 micro-
controller. Additionally, Nordic Semicon-
ductor’s nRF52840-DK dev board, based
on the company’s nRF52840 microcon-
troller, is also supported by CircuitPython.
Both microcontrollers upon which these
three boards are based have Bluetooth

Feature: Rapid microcontroller-based prototyping


dpaonthenet.net 27


Figure 3: Adafruit’s 3501 Gemma M0 is small and can be powered
from its USB port or a separate battery port. (Image source: Adafruit)

Figure 2: Adafruit’s 3500 Trinket M0 dev board measures only 27mm
x 15.3mm x 2mm. (Image source: Adafruit)
Free download pdf