Skip to main content

Zerynth Brings Python Convenience to PSoC 6 Wi-Fi BT Pioneer

Main34_fdabe3c4d8dbeb928b66bc1c5c4d3d6861aa8a1e.jpg

First look at recently announced Zerynth support for featured packed PSoC 6 kit.

The combination of Cypress PSoC and Zerynth middleware provides a powerful platform for rapid IoT development, that benefits from advanced hardware capabilities, Python ease-of-use and expansive ecosystem, a real-time O/S with multithreading, cloud integration, and OTA updates.

PSoC Primer

MCU_Portfolio_8b2de17268f0a2d486dabcd36ec4a034405a9796.jpg

Image source: Cypress Roadmap: PSoC and MCU Portfolio.

The Cypress PSoC (programmable system-on-chip) combines an MCU with configurable analogue and digital peripherals, to create a powerful platform for highly integrated, low power solutions. As such it has proved popular in mass market consumer electronics, such as Apple AirPods.

PSoC_6_MCU_Portfolio_2019222ea3eeafcb75c64d049a8d3ddc8ca08eb2.jpg

Image source: Cypress Roadmap: PSoC and MCU Portfolio.

PSoC 6 is the latest family of devices and specifically targets wearables and IoT applications, featuring an Arm Cortex-M4 main application processor, paired with a low power Cortex-M0+ that can be used for functions such as running a BLE stack and capacitive touch sense. Plus of course configurable analogue and digital blocks, along with programmable I/O routing and interconnect.

This combination of resources makes it possible to reduce the bill of materials and physically shrink solutions, while simultaneously reducing power consumption as functions are implemented in the most efficient way, be it on the main or auxiliary processor, else via hard analogue or digital blocks.

PSoC 6 Wi-Fi BT Pioneer kit

P6WBPK_09e83e9c28161865b3d2f922cece868fe685a0d3.jpg

In addition to a PSoC 6 the Wi-Fi BT Pioneer kit (175-4669) key features include:

  • Expansion headers that are compatible with Arduino Uno 3.3-V shields1 and Digilent® Pmod™ modules.
  • Type 1DX ultra-small 2.4-GHz WLAN and Bluetooth functionality module.
  • 12-Mbit external quad-SPI NOR flash that provides a fast, expandable memory for data and code.
  • KitProg2 onboard programmer/debugger with mass storage programming, USB to UART/I2C/SPI bridge functionality, and custom applications support.
  • EZ-PD CCG3 USB Type-C power delivery (PD) system with rechargeable lithium-ion polymer (Li-Po) battery support.
  • CapSense touch-sensing slider (five elements) and two buttons, all of which are capable of both self-capacitance (CSD) and mutual-capacitance (CSX) operation, and a CSD proximity sensor that allows you to evaluate Cypress’ fourth-generation CapSense technology.

ArduinoShield_b57429cde57528de7a51135ce12ca69d30e43e40.jpg

The kit also comes supplied with an Arduino shield that packages a 2.4” TFT display together with 3-axis accelerometer/gyroscope, PDM microphone input, 32-bit stereo codec and more.

The standard development options are PSoC Creator IDE and WICED Studio, both of which use a C toolchain. However, we are interested in the brand new support for Python-based development via Zerynth and next we’ll take a look at setting up the development tools.

Zerynth Studio

ZP_ZS_PysicalDevices_d4b0643b721077c77bb929a93b05a923d7fc7cec.jpg

What follows is a summary of the steps taken to install the Zerynth Studio on Ubuntu Linux, but note that it can also be installed on MS Windows and Mac OS.

We started by creating a new directory:

$ mkdir Zerynth

Then downloaded the software and saved it to this location. Following which extracted the archive and started installation.

$ cd Zerynth

$ tar xvf zerynth.tar.xz

$ ./zerynth

We then chose to perform an online installation, selected the latest version and once this had completed, launched the application. A Zerynth user account is required and handily we can log in with a DesignSpark account!

A couple of additional steps were required to configure udev for device access. First a new rules file was created.

$ sudo vi /etc/udev/rules.d/99-kitprog2.rules

With the contents:

# Match KP2 PID/VID

SUBSYSTEMS=="usb", ATTRS{idVendor}=="04b4", ATTRS{idProduct}=="f148", ENV{CY_KP2_PID_VID}="f148:04b4"

# Match KP2 CMSIS-DAP

SUBSYSTEMS=="usb", ATTRS{interface}=="KitProg2 CMSIS-DAP", ENV{CY_KP2_PID_VID}=="f148:04b4", MODE="0666"

Following which the udev rules were reloaded.

$ sudo udevadm control --reload-rules && udevadm trigger

At this point the board was plugged in and this resulted in a file manager window opening as the on-board flash was mounted as USB storage. More importantly, in the Device field at the top of Zerynth Studio, we could select the drop down list and find PSoC6 WiFi-Bt Pioneer Kit available under Physical Devices.

Easy as 1-2-3

There are three initial steps that must be performed in readiness for loading an application and these are all carried out via the the same toolbar button with a Z icon, located to the right of the Device drop-down. On first press this puts a registration firmware on the target, obtains a unique ID for the microcontroller and then registers it with the Zerynth backend.

On the second press we are prompted to create a virtual machine (VM).

ZP_ZS_CreateVM_757f05929402d22fc2b145f98477fc4b4eb56a93.jpg

Finally, on third press we select the VM that we would like to use.

ZP_ZS_Virtualize_57f7e6ced9a34e1d18b310d5dea79cda22b6a8ce.jpg

Now we are ready to run our first Zerynth application!

First steps

ZP_ZS_Blink_4bb9e65e6a417cf687a436fc2bdf1b170d38bfe7.jpg

A selection of examples are accessible via the light bulb icon in the left-hand toolbar and these include both a classic Hello World — which uses the serial console for output — and the more typical for embedded platforms, LED blink. Upon clicking on an example the project description and contents of main.py are displayed, following which you can select to clone a copy locally.

pinMode(LED0,OUTPUT)

# loop forever
while True:
    digitalWrite(LED0, HIGH)  # turn the LED ON by setting the voltage HIGH
    sleep(1000)               # wait for a second
    digitalWrite(LED0, LOW)   # turn the LED OFF by setting the voltage LOW
    sleep(1000)               # wait for a second

Above we can see the blink example, which should look reassuringly familiar to anyone who has worked with Arduino and the Programming Guide explains how this was an inspiration when it came to pin and function naming.

To verify our project we click the tick mark icon in the top toolbar and following which can load this onto the target by pressing the Uplink button with the up-arrow icon.

ZP_P6WBP_LED_407954b9699683199750b75da081756cef5cc433.jpg

Sure enough, after a short delay LED5 starts to flash.

Other basic examples include digital and ADC read, along with more advanced examples which demonstrate use of multi-threading and timers, for example.

Getting more advanced

ZP_ZS_CapSense_d28d82dabeec2bd991af09e8fa7266bb0e9c3a8d.jpg

At the time of writing there is a single PSoC-specific example, which demonstrates how to read the CapSense buttons and slider on the Pioneer kit. Along with this there is also a healthy selection of more advanced generic examples which show off Zerynth Standard Library capabilities, such as RTC and filesystem support, interrupts, cryptography, power saving, and the C language interface which allows mixing C and Python code in the same project.

There are also Official Libraries which add support for a variety of IoT platforms, Ethereum Blockchain, various sensors, along with incredibly handy standards such as Modbus and MQTT. There is also support for publishing Community Libraries to, and installing them from, GitHub.

One particularly neat capability that we’ll save for a future post is the Zerynth Advanced Device Manager (ADM), which provides high level functionality for managed Over The Air (OTA) updates, remote procedure call — where a hosted JSON RPC interface can be used to remotely call a Python function on the device! — and per device user interfaces.

Of course, something else that we’ve not explored yet is the configurable analogue and digital blocks that the PSoC platform is noted for. It appears as though, at the present time at least, these would need to be configured using the official Cypress tools. However, this aspect of the device configuration would presumably be far more static in configuration than the firmware.

Andrew Back

Open source (hardware and software!) advocate, Treasurer and Director of the Free and Open Source Silicon Foundation, organiser of Wuthering Bytes technology festival and founder of the Open Source Hardware User Group.