Monthly Archives: March 2021

BERT Machine Learning Model and the RP2040 Thing Plus

via SparkFun: Commerce Blog

The SparkFun RP2040 Thing Plus is awfully enticing to use for machine learning...not only does it have 16 MB of flash memory, but the RP2040 SoC enables the maximum performance for machine learning inference at the lowest power, due to its energy-efficient dual Arm Cortex-M0+ cores working at a comparatively higher frequency of 133 MHz.

SparkFun Thing Plus - RP2040

SparkFun Thing Plus - RP2040


Since a version of the TensorFlow Lite Micro library has been ported for the Raspberry Pi Pico, we can try to start running machine learning models on RP2040 boards that can detect people in images, or recognize gestures and voices. But beyond that, TensorFlow has documentation for building really useful text recognition machine learning models, including the BERT Question Answer model.

Even if you haven't heard of the BERT Question Answer model, it's likely that you've either interacted with systems that follow the same principles. It's what allows machines to read and comprehend human language and interact with us in return. Developed by Google, it stands for Bidirectional Encoder Representations from Transformers, which basically means it uses encoders and decoders to read text input and produce predictions. The bidirectional part means that it reads the text from both left to right and right to left, so that it can understand the context of a word within its text. Basically, it's the key to building machines that can actually communicate with us, like the chat bots you interact with on the web. For example, you can see how the model might be able to pick out an answer from the passage below.

alt text

The question is, can it be converted onto a microcontroller like the RP2040 Thing Plus, which has limited RAM and storage and thus places constraints on size of the machine learning model? We attempted this, by training a model through TensorFlow, and then converting it to C files that could be loaded onto the RP2040 Thing Plus and thus fed new data.

Training the Model

TensorFlow has extensive documentation that leads you through training the model, but the amount of code required is surprisingly simple. It comes down to five main steps: choosing the model (in this case it's MobileBert, since it’s thin and compact for resource-limited microcontroller use), loading in data, retraining the model with the given data, evaluating it, and exporting it to TensorFlow Lite format (tflite).

# Chooses a model specification that represents the model.
spec = model_spec.get('mobilebert_qa')

# Gets the training data and validation data.
train_data = QuestionAnswerDataLoader.from_squad(train_data_path, spec,     is_training=True)
validation_data = QuestionAnswerDataLoader.from_squad(validation_data_path,     spec, is_training=False)

# Fine-tunes the model.
model = question_answer.create(train_data, model_spec=spec)

# Gets the evaluation result.
metric = model.evaluate(validation_data)

# Exports the model to the TensorFlow Lite format with metadata in the     export directory.

The data we'll be giving it comes from a large scale dataset meant to train machine reading comprehension called TriviaQA.

Once we export the model to a file with the format tflite, we'll need to convert the model to a C array such that it can run on a microcontroller using xxd.

xxd -i converted_model.tflite >

Running Inference on the RP2040 Thing Plus

Running inference on a device basically means loading and testing the model onto the microcontroller. TensorFlow does have documentation for running inference on microcontrollers, and includes many steps, including loading the library headers, model headers, loading the module, allocating memory, and testing the model/retraining with new data that it hasn't seen before.

#include "pico/stdlib.h"
#include "tensorflow/lite/micro/all_ops_resolver.h"
#include "tensorflow/lite/micro/micro_error_reporter.h"
#include "tensorflow/lite/micro/micro_interpreter.h"
#include "tensorflow/lite/schema/schema_generated.h"
#include "tensorflow/lite/version.h"
#include "conv_bert_quant.h"

Lastly, we can run the model with an input, like the passage below, and see in the console what kind of answers the model produces to comprehend the text.

alt text

Final Thoughts

It's quite amazing that a microcontroller can run a machine learning model like BERT, but thanks to TensorFlow, it's possible to run all sorts of machine learning modules. What kind of machine learning applications interest you? I highly reccomend giving them a try on one of the RP2040 boards because they are so well equipped for this kind of heavy lifting. Comment below what you want to try, and happy hacking!

comments | comment feed

Name that Ware, March 2021

via Hacking – bunnie's blog

The ware for March 2021 is shown below.

This is an interesting ware that made its way to my inbox via a person who wishes to be credited as simply “Lih”.

I definitely had a bit of trouble guessing its purpose, but certain strange things started to make more sense once I found out. I wonder how quickly others will pick up on the oddities, and piece it together!

Winner, Name that Ware February 2021

via Hacking – bunnie's blog

The ware is a sampling mixer from an HP 8508A vector voltmeter – foreground is a VCO and step generator that sends trigger pulses to samplers on both of the 2 input channels. The wiper is used to equalize the delay between the two channels. I found Cody’s analysis to be interesting and thought-provoking, so I’ll give him the prize for this month. Congrats, email me for your prize! I was also wondering if anyone was going to squint really hard and see the HP logo, and sure enough Name That Ware regular willmore saw it!

Custom machine stand ‘lets you know’ if drill bits aren’t stored properly

via Arduino Blog

YouTuber Cranktown City recently acquired a new milling machine/drill press, and needed somewhere sturdy to place it. Rather than buying something, he went to work making a nice custom stand with a drawer on top and space for a toolbox below that.

To help keep things organized, this top drawer features a 3D-printed drill index with an interesting trick. In addition to providing storage for the drill bits, it “encourages” you to put them back. Each drill cavity has a small switch, all of which are daisy-chained together. The switch signal is fed to an Arduino Nano, which reads high when all drills are present, and low if one or more is missing. If one is missing for too long, it triggers a sound module that insults him into proper organization, and lights up a strip of LEDs as an extra reminder.

Code and CAD for the project is available on GitHub if you’d like to try something similar!

The post Custom machine stand ‘lets you know’ if drill bits aren’t stored properly appeared first on Arduino Blog.

“Let’s Invent the Future Together”

via SparkFun: Commerce Blog

We're excited to participate in this year’s GTC21 conference, with two great sessions for attendees to watch! While we can't give away too many details right now, stayed tuned for more info and links to our sessions. We can't wait to share what we've been working on!

Haven't heard of GTC21? GTC21 is a great conference held by NVIDIA that focuses on artificial intelligence. This year’s online format allows you to explore the latest in AI from the comfort of your desk, couch, backyard, etc. With more than 1,400 sessions free to attend, this conference covers multiple industries and interests for those interested in AI. Topics range from autonomous machines, to high-performance computing, to graphics and game design, to data science and deep learning, to IoT! The week of AI exploration and innovation starts with a keynote from NVIDIA's Founder and CEO, Jensen Huang. See more details below!

Conference details:

  • April 12-16th
  • Watch online demos, live and recorded sessions, panels and more!
  • Register for free over on GTC21's site

While there are more than a thousand(!) sessions to watch for free, NVIDIA is also offering opportunities for paid, hands-on training with their Deep Learning Institute (DLI). Attendees can spend a full day further exploring topics such as AI, accelerated computing or accelerated data science, and earn an NVIDIA DLI certificate! Explore training available on the conference's site.

Keynote details:

Keynote talk details. Image of NVIDIA Found and CEO Jensen Huang

This year’s conference kicks off with a keynote from NVIDIA’s Founder and CEO, Jensen Huang. Expect exciting announcements and more about NVIDIA’s company vision for computing. Keynote begins Monday, April 12th, at 8:30 a.m. PDT/ 9:30 a.m. MDT/ 11:30 a.m. EDT. More information about the keynote is available on GTC21's site.

comments | comment feed

Drag-n-drop coding for Raspberry Pi Pico

via Raspberry Pi

Introducing Piper Make: a Raspberry Pi Pico-friendly drag-n-drop coding tool that’s free for anyone to use.

piper make screenshot
The ‘Digital View’ option displays a dynamic view of Raspberry Pi Pico showing GPIO states

Edtech startup Piper, Inc. launched this brand new browser-based coding tool on #PiDay. If you already have a Raspberry Pi Pico, head to and start playing with the coding tool for free.

Pico in front of Piper Make screen
If you already have a Raspberry Pi Pico, you can get started right away

Complete coding challenges with Pico

The block coding environment invites you to try a series of challenges. When you succeed in blinking an LED, the next challenge is opened up to you. New challenges are released every month, and it’s a great way to guide your learning and give you a sense of achievement as you check off each task.

But I don’t have a Pico or the components I need!

You’re going to need some kit to complete these challenges. The components you’ll need are easy to get hold of, and they’re things you probably already have lying around if you like to tinker, but if you’re a coding newbie and don’t have a workshop full of trinkets, Piper makes it easy for you. You can join their Makers Club and receive a one-off Starter Kit containing a Raspberry Pi Pico, LEDs, resistors, switches, and wires.

Piper Make starter kit
The Starter Kit contains everything you need to complete the first challenges

If you sign up to Piper’s Monthly Makers Club you’ll receive the Starter Kit, plus new hardware each month to help you complete the latest challenge. Each Raspberry Pi Pico board ships with Piper Make firmware already loaded, so you can plug and play.

Piper Make starter kit in action
Trying out the traffic light challenge with the Starter Kit

If you already have things like a breadboard, LEDs, and so on, then you don’t need to sign up at all. Dive straight in and get started on the challenges.

I have a Raspberry Pi Pico. How do I play?

A quick tip before we go: when you hit the Piper Make landing page for the first time, don’t click ‘Getting Started’ just yet. You need to set up your Pico first of all, so scroll down and select ‘Setup my Pico’. Once you’ve done that, you’re good to go.

Scroll down on the landing page to set up your Pico before hitting ‘Getting Started’

The post Drag-n-drop coding for Raspberry Pi Pico appeared first on Raspberry Pi.