One of the greatest innovations in facility construction is the idea of pre-fabricating building components in a factory months before it is needed on the job site. It allows for work to not only be completed quickly—once ground is broken on site—but also serves to increase quality. Software development of IoT embedded devices can leverage a similar concept thanks to software development frameworks (also referred to as software development kits or SDKs). To understand what an SDK is, think of just acquiring the wood to build a house from complete scratch. You would have to chop down trees, dry out the wood in a kiln, and cut the wood into usable lumber. Or you could visit a lumber yard and simply purchase the dimensional lumber that is pretty much guaranteed to be nearly perfect for the task at hand. You are empowered to spend less time on the non-value-added (albeit important) tasks and more time creating the home the end-user wants.
Zerynth SDK
SDKs are a sort of a software development equivalent of shopping for lumber from a lumber yard instead of chopping down trees yourself. One SDK option for embedded developers looking to program IoT devices in Python is the Zerynth platform. Zerynth supports many popular 32-bit microcontroller architectures, including SAMD21, ESP32, ESP8266, and NRF52832, to name a few. The SDK is available for installation on Windows, Mac OS, and Linux. The Zerynth SDK is comprised of two major components: the Zerynth Toolchain and the Zerynth Studio Integrated Development Environment (IDE) (Figure 1).
Figure 1: The Zerynth Integrated Development Environment allows Python developers to write, debug, manage and deploy firmware for the Internet of Things. (Source: Green Shoe Garage)
The Zerynth Toolchain (ZTC) is the command-line tool that serves as the core for firmware development, debugging, and device management within the Zerynth ecosystem. Zerynth Studio is a graphical interface that sits atop the ZTC command-line interface. It provides a graphical code editor and debugger interface and a plethora of Python code examples to help in getting started with Zerynth. An exciting feature of the IDE is support for so-called virtual devices, which allows a developer to develop and verify application code without a physical device to be connected to the local host computer. The code editor features many modern features, including syntax highlighting, autocompletion, and smart snippets. Other features that should make developers happy include built-in support for Git repositories and a built-in package manager. Developers have access to both official Python code libraries provided by Zerynth as well as libraries submitted by the user community. The ability to tap into repositories of proven, reliable source code allows developers to focus on value-added functionality for their clients instead of wasting time on reinventing the wheel on commonly used Python code. The power of the source code libraries is amplified by a second major component of the Zerynth ecosystem, the Zerynth Operating System (OS).
Zerynth OS
Zerynth OS is a multithreaded, real-time operating system (RTOS) tuned to work on a variety of 32-bit microcontroller architectures with limited memory and storage resources. It contains highly customized software stacks for many communications protocols, including Wi-Fi®, Bluetooth®, and LoRa. It also provides security and power management functionality. The use of abstraction layers for both the hardware and RTOS interactions allows Zerynth OS to be highly independent of the underlying microcontroller platforms. The core of the Zerynth OS is the Zerynth Virtual Machine (VM), which runs the user-written Python scripts atop of any number of RTOSes and hardware platforms. Out-of-the-box RTOSes include FreeRtos and CHIBIOS. Through the use of a so-called VM Operative System Abstraction Layer (VOSAL), developers can create high-performance applications running atop the Zerynth VM that leverage OS-level features such as semaphores and threads, regardless of the underlying RTOS selected. With regard to hardware abstraction, Zerynth OS provides a mechanism (VM Hardware Abstraction Layer or VHAL) to interact with many of the peripherals found on modern microcontrollers such as interrupts, GPIO, I2C, SPI, ADC, PWM, and UART. The VHAL, custom-written for each supported microcontroller, provides a single, standard software interface to all the previously mentioned peripherals. In other words, write the application Python code once, and it will work on multiple hardware platforms, so long as the device has the peripherals onboard.
Zerynth Device Manager
Of course, developing Python code for an IoT device is only half the battle. Eventually, a device must go out into the world and connect to the internet to perform its intended purpose. To aid in the various functions associated with fielding an IoT device (e.g., remotely provision, organize, monitor, and manage multiple devices worldwide), the Zerynth Device Manager (ZDM) is provided to developers as well. Through the ZDM, devices can be securely onboarded to the cloud. Managing devices across their lifecycle to include remote procedure calls (RPC) and Firmware Over-the-Air (FOTA) upgrades are also possible using REST APIs via the ZDM. The ZDM provides tools to aggregate and store the data collected by the fielded IoT devices. It also includes event management and an alarm mechanism to respond to the raw data as it is received. The ZDM can be used as a cloud-based service or can be installed on-site for those clients that have unique security or business needs. If, however, a developer requires the use of a third-party cloud service provider (e.g., Amazon Web Services, Microsoft Azure, Google Cloud Platform, Ubidots, The Things Network), it is a simple matter of changing a line of code in the Python application, not a complete code rewrite.
Python and Zerynth: Power to the Coder
Python is a powerful programming language that continues to gain traction in use cases beyond traditional desktop applications. Developers of embedded electronics, especially IoT devices, stand to benefit significantly from adopting software development frameworks such as Zerynth. Frameworks ensure consistency and can even contribute to improved performance, energy management, and security. When combined with the uniquity and capabilities of the Python language, frameworks empower developers to build the highest quality embedded systems by eliminating the grunt work, providing proven source code libraries for repetitive tasks, and free resources to focus on client-facing functionality.
About Author
Michael Parks, P.E. is the owner of Green Shoe Garage, a custom electronics design studio and technology consultancy located in Southern Maryland. He produces the S.T.E.A.M. Power podcast to help raise public awareness of technical and scientific matters. Michael is also a licensed Professional Engineer in the state of Maryland and holds a Master’s degree in systems engineering from Johns Hopkins University.
Source: Mouser Electronics