This is my presentation to the Hackware Singapore makers’ group on 3 December 2019…

[1] About Me

I’m Lup Yuen and I teach IoT…

I teach IoT because…

IoT is difficult because… Just look at the expansive scope in the sketch above! Every single link in the IoT Chain must be executed correctly. Or the whole IoT product falls apart. We are also creating too many expensive IoT gadgets that don’t solve any business problems… “Technology Waiting For A Problem To Solve”

5 years ago I decided to fix every link in the IoT Chain so that we can create really useful and affordable IoT gadgets, the Lean and Agile Way. Let’s study the IoT Chain backwards (right to left)…

What’s Lean and Agile?

1. For any new tech, experiment the cheapest and fastest way possible. Use common materials and resources: open-source code, off-the-shelf hardware. No custom hardware!

2. Set a time frame… If it becomes too hard or too expensive, quit. Something better will probably come along soon! And you should be spending time on more important things.

3. You must feel comfortable teaching the outcome of your experiment. Or blog about it. (I do both) If it’s hard to teach, or if your audience doesn’t see the point, then it’s doomed for zero adoption. Keep tweaking it! (We should do more of this for Rust)

4. Always keep a fuzzy idea what Problem the tech is supposed to solve. With new tech the answer is not obvious. But if you’re persistent with your teaching and blogging, the answer becomes clear someday!

[2] IoT Cloud

IoT Clouds are already stable and mature, no problem there. I used to be an Enterprise Architect so I know that all the tools in the cloud will work fine for IoT. Like Amazon Web Services, the premium, most expensive cloud…

  1. “Push AWS IoT sensor data to Redshift with Kinesis Firehose”
  2. “Transform and Import a JSON file into Amazon Redshift with AWS Glue”
  3. “Connecting AWS Lambda Node.JS to Redshift or PostgreSQL? Try AWS Lambda Layers!”, which has simple useful dashboards and easy integration with JavaScript in the cloud…

  1. “Visualising BBC micro:bit sensors with thethings.iO”
  2. “以 thethings.iO 來將 BBC micro:bit 感測器圖形化”
  3. “Realtime sensor data processing with and Amazon Web Services Kinesis”

Google Cloud, probably the cheapest cloud out of the big 3 clouds (AWS, Azure, Google)…

Alibaba Cloud, if you need something even cheaper, or if your IoT gadget must operate in China (because other clouds may be blocked)…

Also check out Grafana, the open source dashboard tool, and Prometheus, the open source time-series database. Both are analytics tools that were created for enterprises but work well for IoT too.

Beyond that we have cloud-based machine learning, predictive analytics, … Many useful enterprise tools that we may repurpose for IoT. So the IoT Cloud is not a problem.

[3] IoT Network

I used to teach IoT with the Sigfox network in Singapore. The charges for sending and receiving messages are ridiculously low (few dollars per year per device). Though the messages are small (12 bytes) and infrequent (140 messages per day). Perfect for teaching IoT…

  1. “Sigfox Teacher Answers Your Questions”
  2. “Connect STM32 Blue Pill to Sigfox”
  3. “連接 STM32F103C8T6 Blue Pill 開發板與 Sigfox 物聯網”
  4. “Connect BBC micro:bit to Sigfox”
  5. “連接 BBC micro:bit 與 Sigfox 物聯網”

…Except that the Sigfox developer kits are expensive, bulky (Arduino Shield), and limited in choice. Impossible to create a cheap prototype of an IoT gadget and commercialise for mass production. (Remember that Sigfox network is not available in China, the manufacturing powerhouse.) Here’s my painful attempt (50% success rate)…

And for some odd reason, government agencies and companies were reluctant to test IoT concepts on Sigfox even though it’s available nationwide (“non-standard”). Incredibly frustrated, I gave up and moved on. (Remember: Lean and Agile!)

Later the NB-IoT (“standard”) network became available in Singapore through StarHub, Singtel and M1. The telcos didn’t provide much help for using their NB-IoT networks, so I created the missing docs…

  1. “Get Started with NB-IoT and Quectel modules”
  2. “Connect STM32 Blue Pill to NB-IoT with Quectel BC95-G and Apache Mynewt”
  3. “Low Power NB-IoT on STM32 Blue Pill with Apache Mynewt and Embedded Rust”

[4] Transceivers

My first experience creating hardware…

  1. “Story of the UnaShield”
  2. “Making my first ever PCB with Seeed Fusion PCB assembly service”

Learnt that making IoT gadgets at low volume is very expensive. This is the “Minimum Order Quantity” problem. Always repurpose somebody else’s hardware whenever possible, don’t create new hardware! Make up for it with really good firmware.

Best benchmark for checking whether a particular technology (like NB-IoT) is mature and cheap to manufacture (in China): Just search Taobao. Look at the sheer number of affordable NB-IoT Developer Kits available, some even have programmable STM32 microcontrollers and onboard GPS! Most of these NB-IoT developer kits are backed by China telcos.

  1. “Quick Scan of NB-IoT STM32 Dev Kits on Taobao”
  2. “Quick Peek of Huawei LiteOS with NB-IoT on Ghostyu NB-EK-L476 Developer Kit (STM32L476RCT6)”
  3. “Build an NB-IoT GPS Tracker on STM32 L476 with Apache Mynewt and Embedded Rust”

My choice today for IoT Network: NB-IoT. Works well worldwide (including China) with few gotchas. Strangely low adoption for such good technology. But please don’t ask your telco for a trial NB-IoT SIM (ask me why)

[5] Sensors

Best thing about Arduino: Arduino drivers are available for all kinds of sensors. (Even though many Arduino drivers use dodgy Bit Banging.) When we move out of Arduino, we face problems finding drivers…

Apache Mynewt is an open-source Real Time Operating System that has built-in drivers for many types of sensors. So I shifted from Arduino and cocoOS to Mynewt…

Lesson Learnt: When choosing your IoT device firmware platform, make sure it has drivers for your sensors and transceivers, present and future!

[6] Real Time Operating Systems

For most IoT gadgets we need to transmit sensor data while reading sensors concurrently. This code can get very messy…

We need proper multitasking. I started with cocoOS, a lightweight cooperative (coroutine) task scheduler for Arduino and STM32 platforms…

  1. “Juggling Arduino Sensors With cocoOS”
  2. “Juggling Sigfox Downlink And Arduino Sensors With cocoOS”
  3. “Juggling STM32 Blue Pill For Arduino Jugglers”

With a cooperative task scheduler like cocoOS, the firmware needs to be designed carefully before coding. Which could be a problem if you’re not an embedded software architect. So I switched to an open source Real Time Operating System that supports preemptive multitasking: Apache Mynewt

  1. “Create your IoT gadget with Apache Mynewt and STM32 Blue Pill”
  2. “Connect STM32 Blue Pill to ESP8266 with Apache Mynewt”
  3. “Build Your IoT Sensor Network — STM32 Blue Pill + nRF24L01 + ESP8266 + Apache Mynewt +”
  4. “Low Power NB-IoT on STM32 Blue Pill with Apache Mynewt and Embedded Rust”

Mynewt is easy to customise in C, I created my own drivers for NB-IoT, ESP8266, low power support. Built-in support for CoAP, JSON and CBOR, perfect for NB-IoT. Small footprint, runs well on STM32 Blue Pill (which has 64 KB Flash ROM, 20 KB RAM) and Nordic nRF52. Also check out Zephyr, a modern open source RTOS that is supported by the microcontroller companies: STMicro, Nordic, NXP, …

My choice for Real Time OS: Apache Mynewt

[7] Microcontrollers

Arduino Uno is a Dead End for IoT Education: Hard to create affordable commercial products at volume. (Same for BBC micro:bit.) And Bit-Banging in C is just bad for IoT learners. So I taught myself STM32 Blue Pill. The tiny development board contains a 32-bit Arm microcontroller by STMicro with proper ports for UART, I2C, SPI, USB, CAN, … Costs only US$ 2 (or 5 pieces for S$ 16)

STM32 Blue Pill passes my “Taobao Benchmark” with flying colours, so no worries about commercialising your IoT gadget. Hard to find coding tutorials for STM32 Blue Pill, so I wrote many, many STM32 Blue Pill coding tutorials in C and Rust (and some translated into Chinese)…

  1. “Create your IoT gadget with Apache Mynewt and STM32 Blue Pill”
  2. “Visual Embedded Rust Programming with Visual Studio Code”
  3. “連接 STM32F103C8T6 Blue Pill 開發板與 Sigfox 物聯網”
  4. “Super Blue Pill — Like STM32 Blue Pill, But Better!”

My choice for Microcontroller: STM32 Blue Pill or Nordic nRF52832, which has Bluetooth and more RAM and ROM (512 KB flash ROM, 64 KB RAM)

[8] Embedded Programming

C programming is hard… Especially C Pointers! MicroPython is too big to run on STM32 Blue Pill, my benchmark for high-volume, lost-cost microcontrollers. Can we squeeze Embedded JavaScript (Static TypeScript) into STM32 Blue Pill? No!

  1. “STM32 Blue Pill USB Bootloader — How I fixed the USB Storage, Serial, DFU and WebUSB interfaces”
  2. “STM32 Blue Pill — Analyse and Optimise Your RAM and ROM”
  3. “STM32 Blue Pill — Shrink your math libraries with Qfplib”
  4. “STM32 Blue Pill — Dissecting the WebUSB Bootloader for MakeCode”
  5. “STM32 Blue Pill — Bootloading the WebUSB Bootloader”
  6. “[Work In Progress] STM32 Blue Pill Visual Programming with MakeCode, CODAL and libopencm3”

Why not switch from C to Rust, the safer, modern alternative? The Rust compiler stops you from using bad pointers (unless you mark it unsafe). It compiles into efficient Arm machine code. Works well with C libraries and drivers (like Mynewt). And well supported by open-source coding tools like VSCode. We can run pure Embedded Rust...

Or run Rust on top of an embedded OS like FreeRTOS…

I decided to run Rust on top of Apache Mynewt embedded OS, because it’s a modern, mature and reliable OS…

  1. “Rust Rocks NB-IoT! STM32 Blue Pill with Quectel BC95-G on Apache Mynewt”
  2. “Hosting Embedded Rust apps on Apache Mynewt with STM32 Blue Pill”
  3. “Safer, Simpler Embedded Rust with Apache Mynewt on STM32 Blue Pill”

Rust has a steep learning curve. My advice: Start coding in Rust the simple, C-like way. Then learn the harder Rust parts (borrowing, generics, traits, macros) and clean up your code. Maybe one day newbies can learn Rust through Visual Rust…

  1. “Visual Embedded Rust Programming with Visual Studio Code”
  2. “Advanced Topics for Visual Embedded Rust Programming”
  3. “Visual Programming with Embedded Rust? Yes we can with Apache Mynewt and Google Blockly!”

My choice for Embedded Programming: Rust with Apache Mynewt on VSCode. Programming for drivers may still need C. I’m keen to roll out Visual Rust but it’s hard for me to do this alone. Lemme know if you can help!

🛈 What is VSCode? Is it related to Visual Studio? How is Microsoft involved? Read this

[9] Current Projects

Now that we have fixed every link of the IoT Chain, let’s validate with new projects, the Lean and Agile Way!

PineTime Smart Watch

Smart Watch based on Nordic nRF52832 microcontroller. Colour 240x240 touchscreen, heart rate sensor, accelerometer, Bluetooth 5, 4 MB flash, US$ 22. Not available to general public yet because open-source firmware is still in development: TinyGo, Zephyr, Mynewt+Rust (I’m now coding this, helped by an open-source volunteer in Germany)

  1. “Sneak Peek of PineTime Smart Watch… And why it’s perfect for teaching IoT”
  2. “Building a Rust Driver for PineTime’s Touch Controller”

Bluetooth Mesh on Nordic nRF52

Nordic nRF52832 could become my preferred development board because it has Bluetooth and more RAM/ROM than STM32 Blue Pill. 32-bit Arm microcontroller, 512 KB flash ROM, 64 KB RAM. More expensive than STM32 Blue Pill of course (US$ 7 on Taobao). Because we are coding with Apache Mynewt OS and calling the same APIs for GPIO, I2C, SPI, etc so the code for STM32 Blue Pill also works on Nordic nRF52.

  1. “Coding nRF52 with Rust and Apache Mynewt on Visual Studio Code”
  2. “Bluetooth Mesh with nRF52 and Apache Mynewt”

Trivia: BBC micro:bit is based on Nordic nRF51, the weaker predecessor of nRF52. That’s why micro:bit feels a little wonky sometimes…

  1. “Connect BBC micro:bit to Sigfox”
  2. “連接 BBC micro:bit 與 Sigfox 物聯網”


Alternative to Arm microcontrollers. Many cheap development boards coming from China. Some of the boards even work like STM32 Blue Pill (GD32 VF103). But they lack proper OS drivers and coding tools…

  1. “Porting Apache Mynewt OS to GigaDevice GD32 VF103 on RISC-V”
  2. “Hey GD32 VF103 on RISC-V: I surrender… For now”


Lots of potential for creating ultra-low power IoT gadgets. But FPGA programming is way too hard! Maybe it needs a visual programming tool.

  1. “Why use FPGA for IoT? Here’s what I think…”
  2. “Program Your First FPGA With GOWIN GW1N-4”