Embedded Computing
  • About
  • Blog
  • Hardware
    • Which Platform?
    • Controller Platforms >
      • Adafruit Platform
      • Arduino Plaform
      • BBC micro:bit
      • Espressif Platform
      • iLabs Platform
      • Raspberry Pi Platform (MCU)
      • Seeed Platform
      • Silicon Labs Platform
      • Teensy Plaform
    • Computer Platforms >
      • BeagleBone Platform
      • Raspberry Pi Platform (SBC)
      • UDOO Platform
    • Peripherals >
      • Shields
      • Grove System
      • Sensors
      • Actuators
    • Displays >
      • E-Paper Displays
      • Reflective Displays
      • TFT Displays
      • LCD Displays
    • Legacy Platforms >
      • chipKIT Plaform
      • 4D Systems Platform
      • Intel Platform
      • LaunchPad Plaform
      • BoosterPacks for LaunchPads
      • LightBlue Bean
      • Maple Plaform
      • Mediatek Platform
      • Microsoft Azure IoT DevKit
      • Particle Platform
  • Software
    • Exploring RTOS with Galaxia >
      • Event Library
      • Semaphore Library
      • Mailbox Library
      • Timer Library
      • Clock Library
      • SWI Library
      • Task Library
    • Ultra-Low Power with EnergyTrace >
      • Ultra-Low Power with MSP430
      • Ultra-Low Power with Energia MT and Galaxia
    • Using Integers Instead of Reals
    • Going Python?
  • IoT
    • IoT Platforms: Which Hardware? >
      • Matter with Silicon Labs MG24
    • IoT Services: Which Solution? >
      • Recommended IoT Solutions
      • Platform-Specific IoT Solutions
      • Other IoT Solutions
      • Not tested IoT Solutions
      • Notification Solutions
    • Get Date and Time from Internet with NTP
    • Fast and Easy WiFi Connection with QR-Code
  • Tools
    • How to Start?
    • Reference >
      • Asking for Help
      • Boards Pins Maps
      • Ruler
      • Boards and Plugs
      • I²C Logic Level Converter
      • Standards for Connectors
    • Training >
      • Texas Instruments Workshops
      • Embedded Systems: Shape The World — MOOC edX UTAustinX UT.6.02x
      • Embedded Systems - Shape The World: Microcontroller Input/Output — MOOC edX UTAustinX UT.6.10x
      • Embedded Systems - Shape The World: Multi-Threaded Interfacing — MOOC edX UTAustinX UT.6.20x
      • Real-Time Bluetooth Networks: Shape the World — MOOC edX UTAustinX UT.RTBN.12.01x
      • Systems Thinking with Texas Instruments Robotics System Learning Kit
    • Books >
      • Getting Started with the MSP430 LaunchPad
      • Getting Started with Arduino
      • Arduino Cookbook
    • IDE >
      • The Battle of IDEs
      • More Options
      • Assessing the Next Generation of IDEs
      • Tools for Documentation
    • Equipment >
      • Saleae Logic Analyser
      • Rigol DS1102E Oscilloscope
      • XDS110 Debug Probe with EnergyTrace​
      • Segger J-Link Programmer-Debugger
      • Nordic Power Profiler Kit II
  • Projects
    • Libraries >
      • Master I²C Software Library
      • Date and Time Library
      • highView Library Suite
      • Others Libraries
    • smartDevices >
      • I²C smartColours Smart Sensor
      • I²C smartRFID Smart Sensor
      • I²C smartLED Display
      • I²C smartControls Smart Device
      • I²C smartWiFi Smart Device
      • I²C smartBLE Smart Device
      • I²C smartNode Smart Device
    • IoT Projects >
      • Remote E-Paper Weather and Message Board
      • Typie-Walkie with LoRa and E-Paper Screen
      • Typie-Walkie with E-Paper Screen
      • Remote e-Paper Pictures Panel
      • Remote e-Paper Messages Panel
      • Industrial IoT Project
      • Remote Contactless Temperature Monitor
      • Using Node-RED for IIoT
      • Low Power Home Network Weather Monitoring
      • Updated Low Power Home Network Weather Monitoring
      • Weather and Security Station with Blynk
      • SensorTag to Blynk Using Node-RED
      • Pervasive Reporting
    • AI Projects >
      • Colour Recognition with Neural Network
    • Other Projects >
      • Air Quality Monitoring
      • Driving a Large E-Paper Display with a Compact Xiao RP2040
      • Low-Power E-Paper Weather Station
      • Portable Particulate​ Matter Monitor
      • FRAM-based E-Paper Screen Controller
      • General Purpose 3.5" Screen
      • Colour Recognition with Neural Network
      • A Low Power Weather Station
      • Digital Volt-Amp-Watt Meter
      • Mobile Measurement with LCD Display
      • Screen with SRAM for GUI
      • Volt-Amp-Watt-Meter for Grove
      • Multi-Touch Project with CapTIvate

Going Python with the Pervasive Displays E-Paper Display Pico Kit​ Touch

With all the fanfare about Python on microcontrollers, I wanted to investigate. I had been already exposed to Python as it is the official language for the latest fischertechnik Robotics TXT 4.0 controller.

So I took one project already developed in C++ and ported it to Python: the Basic_Touch_GUI example of the PDLS_EXT3_Basic_Touch. ​I targeted the Raspberry Pi micro-controller and single-board computers, and found unexpected results.

​The EPDK-271-Touch used in this project was sampled by Pervasive Displays.

The Python library is available at the PDLS_EXT3_Python_Touch repository. It also support the 3.70-Touch e-paper screen from Pervasive Displays.
Picture

Porting a project 

​There are two flavours of Python for embedded systems, CircuitPython and MicroPython, with subtle differences. My initial idea was to use the Adafruit Blinka package as hardware abstraction layer on all the boards, MCU-based Pico and single-board computers Zero 2W or Model 4B.​

As both C/C++ and Python rely on objects, the main code remains almost identical. The syntax of Python is different from the syntax of C/C++ but remains a syntax: no more accolades or curly braces but colons and indents. 
Picture
Picture
Initial Arduino code

    
Translated code into Python

    
Objects being objects, I faced no major issues when porting the project. A nice feature, the dir() command lists the content of an object.

Python has a different approach to variables, with global to access shared variables. The automatic management of variables resulted in memory fragmentation with dedicated garbage collection tools to reclaim the fragments.

Python brings its own shell, an interactive interface called REPL for Read-Evaluate-Print Loop. This feature is very handy for exploring the language and running code line by line.

Picture
The same tools are available for C/C++ and Python, although the tools for Python do not feel as mature as those for C/C++.
  • Simplified IDE Thonny instead of Arduino; 
  • More capable Visual Studio Code with the right extensions. ​
Picture
Picture
Picture
Picture
Picture
Thonny, Visual Studio Code and extensions Python, Pico-W-Go and Jupyter 

Raspberry Pi Pico

​Alas, on the ​Raspberry Pi Pico, the memory couldn't handle the project on top of the Blinka packages, despite all the recommended optimisations, so I had to perform a second port based on the official Raspberry Pi version of Python. The Pico-W-Go extension for Visual Studio Code manages the automatic connection to the ​Raspberry Pi Pico.

Results are far from good. The project raised a memory overflow on the Raspberry Pi Pico and I had to remove one of the four fonts.

However, I managed to run the classic Tic-Tac-Toe game on the Raspberry Pi Pico (pictured below).

Picture

Raspberry Pi Zero 2 W and Pi Model 4B

​On the Raspberry Pi single-board computers, the memory limitations didn't apply. However, the speed was really slow. Updating the screen takes two seconds instead of 700 ms in C/C++.
​
I also explored the integration with Jupyter to design an interactive notebook: a same document include explanations in Markdown and snippets in Python.

​Jupyter runs as a web server on the Raspberry Pi Zero 2W or Model 4B and displays the pages on any browser. A Run button executes the code on the Raspberry Pi and displays the output below.

​This is a great tool to combine explanations to read and snippets of code to run. ​

Conclusion

I'm not convinced that Python is a valid solution for microcontrollers. It requires huge resources, runs very slowly, lacks any strong typing and doesn't fit with low-level operations like hardware control, which is at the very core of embedded systems.

As an interpreted language, Python brings a clear advantage in executing each line of code separately, reminiscent of BASIC. 

However, for single-board computers with GPIOs like the Raspberry Pi 4B, the integration of Python with Jupyter offers a great option for designing interactive notebooks, by combining explanations to read and snippets of code to run. 
Picture

Pros

  • Built-in interactive shell
  • Integration with Jupyter

Cons

  • Resource intensive
  • Very slow

Wrap-Up

  • Resource intensive
  • Not recommended for micro-controllers
  • Integration with Jupyter

Links

  • PDLS_EXT3_Python_Touch repository
  • Pervasive Displays EPDK-2.71-Touch product page
  • Thonny IDE
  • Visual Studio Code
  • Python and extension for Visual Studio Code
  • CircuitPython and MicroPython
  • Pico-W-Go and extension for Visual Studio Code
  • Jupyter and extension for Visual Studio Code
  • Official MicroPython from Raspberry Pi for Pico
  • Adafruit Blinka package​


Posted: 08 Feb 2023
Updated: 02 Mar 2023, 11 Mar 2023

Powered by Create your own unique website with customizable templates.