From Nordic UART Service to MicroPython using PolyMCU and Gattlib

PolyMCU is an Open Source Framework which has been designed to be as flexible as possible: host OS independent (support Linux, Windows, MacOS), support any toolchain (GCC, LLVM), any RTOS (ARM RTX, FreeRTOS), any micro-controller vendor SDK (Nordic Semiconductor, NXP, Freescale, ST). The framework is based on Cmake.

One of the major benefit of the framework is your firmware development is unified across the different development environment and MCU Vendor SDKs. image description

PolyMCU is not another framework that requires to rewrite completely your program to take advantage of its advantages. PolyMCU actually take advantage of the MCU Vendor SDK. If you wrote your firmware using Nordic SDK then migrating to PolyMCU should be straightforward.

GattLib is also an Open Source project which has been introduced to have a C API to communicate with BLE device on Linux machines.

Initially I was planning to write a tutorial to explain how to build a firmware using PolyMCU and its companion host application using GattLib. The idea was to use Nordic UART Service (NUS) and porting Nordic SDK's example to PolyMCU. This BLE Service is simple to understand. It works like a UART-over-Bluetooth.
But after completing my two demo applications (the firmware for Nordic and the Linux application to communicate with the BLE device), I ended up with a not-so-exciting demo where the user will type some strings in the Linux application and the BLE device will respond “Thank you!”.

I wanted something more fun. Why not having a shell running on the BLE device and using NUS to communicate with it. Hmm, I was not seeing myself writing a shell for doing what?

I always wanted to play with MicroPython. Python as a shell REPL (stand for ‘read–eval–print loop’).
It would be cool to have Python running on nRF52 Development Kit (actually nRF52 Preview DK as it is the only Nordic board I have). And that is where I started my new challenge!

After a couple of days of work I managed to have MicroPython on Nordic nRF52 (Preview) DK with LED, Pin, I2C support in Python! I can type the Python commands on my Linux machine. They are sent through Bluetooth using NUS and interpreted on by Nordic nRF52 DK. I managed to read the temperature of the SparkFun Digital Temperature Sensor Breakout – TMP102 using I2C Python interface. image description

Here are the tutorial and blog post of MicroPython on PolyMCU:

Call for contributions:

  • Test PolyMCU on nRF51 DK and nRF52 DK (task difficulty: easy)
  • Port PolyMCU to another Nordic’s board (task difficulty: moderate)
  • Increased PolyMCU MicroPython support on Nordic’s board (task difficulty: from easy to moderate)
  • Improve MicroPython to render better with Nordic UART Service (task difficulty: moderate)