Sony’s new Spresense board offer exciting new capabilities – and Zerynth makes it easier than ever to program it in Python!
Spresense is a very powerful, power-efficient development board designed for IoT and multimedia applications. The multicore microcontroller is composed of six ARM Cortex-M4F cores with a clock speed of 156 MHz. The board comes with GNSS, high-resolution audio I/O and multiple mic inputs which allow a wide range of uses cases.
Here are the Spresense main board key features:
- Sony’s CXD5602 Processor
- 8 MB Flash memory
- PCB with a small footprint
- Dedicated camera connector
- GNSS (GPS) antenna
- Multiple GPIO (UART, SPI, I2C, I2S)
- 2 ADC channels
- Application LED x 4 (Green)
- Power LED (Blue)
- USB serial port
Zerynth is the middleware for the IoT and industry 4.0. It offers a quick and easy way to program 32-bit microcontrollers in Python and connect them to the Cloud. Zerynth also allows a mixed C/Python programming environment. Zerynth Studio is the gateway to the whole Ecosystem. It’s free to download and cross-platform, with a powerful IDE.
This tutorial shows basic usage of the Sony Spresense board with Zerynth. You’ll see how to run Multiblink, ADC and I2C examples. See the specific documentation form more info.
Here’s how to get started with Sony Spresense using Zerynth Studio:
First of all, you need to download and install Zerynth Studio.
Once that is done, you launch Zerynth Studio and create an account (or log in if you already have one).
Now connect the board through the main USB port. Drivers may be needed depending on your system. More info in the official documentation. If drivers have been correctly installed, the Spresense device is recognized by Zerynth Studio.
The next steps are:
- Burn the Spresense Bootloader clicking the “Info” button, then “Burn Bootloader”. Then accept the EULA
- Register the device by clicking the “Z” button from the Zerynth Studio;
- Create a Virtual Machine for the device by clicking the “Z” button for the second time;
- Virtualize the device by clicking the “Z” button for the third time.
We’ll start by cloning the “MultiBlink” example from Zerynth’s Example Library. To do that, simply search for “Multiblink” in the Zerynth Example Library, choose the MultiBlink example, and hit “clone”.
As you can see, the code is very simple. Three threads are launched in parallel, each one blinking one LED with a specific frequency:
We only need to replace the default pins with the pins of the Spresense that are associated with the LEDs we want to blink (as you can see in the pinout), and the code is ready to use!
Once we’re done modifying the code, we can uplink it to the Spresense board.
You should now see LED0, LED1 and LED2 blinking at different frequencies!
ADC with an analog sensor
Let’s now make use of the ADC on the Spresense board. For this demo, you’ll need an analog sensor. We’ll use Adafruit’s ALS-PT19 Light Sensor.
After connecting it to the 3.3V and GND pins of the board to power it, we connect its output at the A0 analog pin on the Spresense.
We then clone the “Analog to Digital Acquisition” example from Zerynth’s Example Library; we’ll comment out some of the code, as we only want to print the sensor’s value on the serial monitor, to test out the sensor itself.
And here’s the code:
Once we’re done editing the code, we can uplink it to the Spresense board.
After opening the Serial Monitor in Zerynth Studio, we should see the raw output of the sensor; if we block the light from hitting the sensor, we can see that its value drops, so it works as expected.
I2C communication with a Weather sensor
Finally, we’re going to show another sensor test, this time using the I2C bus that is present on the Spresense board.
Once again, we will clone an example from the Zerynth Example Library; in our case, we’ll be using the BME280 sensor by Bosch, mounted on the Weather Click by Mikroelektronika. It’s a simple sensor board that communicates three values (temperature, humidity, and pressure) via I2C.
First of all, you will need to connect the SDA and SCL pins in order to enable I2C communication with the Spresense. Then do the same for 3.3 V and GND for the power supply. All the information about the board is available on the pinout.
Finally, search for the ‘get values’ example of the BME280 library and clone it.
After cloning the example, we can uplink it directly to the board (no need to modify the code).
By opening the Serial Monitor, we can see once again that we are getting the correct values for the temperature, humidity, and pressure.
And that is all! As you can see, Zerynth allows you to write a minimal amount of Python to do a huge number of different tasks even on the latest boards. So go and create something beautiful and innovative :)