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

DEV-17745
$17.95

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.
model.export(export_dir)

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 > model_data.cc

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

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

Arduino World Gathering 2021: the official community conference you can’t miss

via Arduino Blog

We’re proud to announce the Arduino World Gathering, taking place everywhere in October 2021. Multiple days packed with workshops, lightning talks and project demos; a virtual event for everyone to enjoy.

This is a conference made by you. Whether you built a cool project with Arduino for fun or profit, you want to share a neat hack with the novice users, or you want to host a workshop a particular skill, technique, or special know-how you’ve acquired – we want you. 

Hackers, creators, designers, engineers, educators. Stop what you’re doing and start putting your ideas together now. A call for proposals will open soon.

We’ll talk about hardware, software, open source, creative technology, interactive art, smart products, professional applications, education, home automation, Internet of Things, artificial intelligence and more. All things Arduino!

Enter your email to get notified about the call for proposals and any other AWG updates:

Interested in sponsoring the conference? Contact us.

The post Arduino World Gathering 2021: the official community conference you can’t miss appeared first on Arduino Blog.

PIR Our Last Email

via SparkFun: Commerce Blog

Hello everyone and welcome back to another Friday Product Post here at SparkFun Electronics. We have quite a few new products to get through this week and, if you didn't see our blog yesterday, we have four new PIR Breakout Boards that utilize the EKM-series PIR sensor from Panasonic®. Following that, we are going to look at our new SparkFun Original Ultrasonic Distance Sensor, and then a new ESP32 WROOM Module. Let's jump in and take a closer look!

Get more active with your Passive Infrared!

SparkFun PIR Breakout - 170uA (EKMC4607112K)

SparkFun PIR Breakout - 170uA (EKMC4607112K)

SEN-17372
$19.95
SparkFun PIR Breakout - 1uA (EKMB1107112)

SparkFun PIR Breakout - 1uA (EKMB1107112)

SEN-17373
$29.95
SparkFun Qwiic PIR - 170uA (EKMC4607112K)

SparkFun Qwiic PIR - 170uA (EKMC4607112K)

SEN-17374
$20.95
SparkFun Qwiic PIR - 1uA (EKMB1107112)

SparkFun Qwiic PIR - 1uA (EKMB1107112)

SEN-17375
$30.95

The SparkFun PIR Breakouts (170uA and 1uA) and Qwiic PIRs (170uA and 1uA) use two versions of the EKM-series PIR sensors from Panasonic® to offer low profile motion-sensing options over I2C for both battery-powered and continuously-powered applications. The Qwiic versions of these PIR breakouts feature an ATTiny84, with firmware that handles monitoring the sensor's output signal, debouncing that signal along with a configurable interrupt, and translating it all to the I2C interface (which means it's easy to add a PIR to an existing Qwiic/I2C project).


ARGOS Satellite Transceiver Shield - ARTIC R2

ARGOS Satellite Transceiver Shield - ARTIC R2

SPX-17236
$199.95

Is your project linked to environmental protection, awareness or study, or to protecting human life? Perhaps you are developing a wildlife tracker, ocean buoy, environmental monitoring system or need to transfer emergency medical information? Do you need to be able to transmit and receive data anywhere? If so, this is the product for you! Our ARGOS Satellite Transceiver Shield allows you to send and receive short bursts of data via the ARGOS satellite network, anywhere on Earth including the polar regions.


SparkFun Qwiic Ultrasonic Distance Sensor - HC-SR04

SparkFun Qwiic Ultrasonic Distance Sensor - HC-SR04

SEN-17777
$12.95

You may be familiar with the classic HC-SR04 distance sensor - it's great for providing non-contact distance readings from 2 cm to 400 cm. The SparkFun Qwiic Ultrasonic Distance Sensor improves on the classic by adding a pair of Qwiic connectors to it, so now you can communicate over I2C and daisy chain any other Qwiic product of your choosing.


ESP32 WROOM MCU Module - 16MB (PCB Antenna)

ESP32 WROOM MCU Module - 16MB (PCB Antenna)

WRL-17830
$8.95

The ESP32-WROOM-32E is a powerful, generic Wi-Fi+BT+BLE MCU module that targets a wide variety of applications, ranging from low-power sensor networks to the most demanding tasks, such as voice encoding, music streaming and MP3 decoding.


That's it for this week! As always, we can't wait to see what you make! Shoot us a tweet @sparkfun, or let us know on Instagram or Facebook. We’d love to see what projects you’ve made! Please be safe out there, be kind to one another, and we'll see you next week with even more new products!

Never miss a new product!

comments | comment feed

Tune in to the official Arduino Day 2021 livestream

via Arduino Blog

The Official Arduino Day live stream will be hosted on the Arduino website and social media channels from 4pm CET on March 27th, 2021.

Arduino Day 2021 explores the idea of “undistancing,” with a packed roster of talks, demos, presentations, interviews and more that show us how Arduino can bring us together, even when we’re apart.

The schedule of the event will be posted in the next few hours on the Arduino Day page.

The post Tune in to the official Arduino Day 2021 livestream appeared first on Arduino Blog.