Aksha: An Arduino based ML Pencil powered by TensorFlow Lite Micro

Naveen Manwani
Analytics Vidhya
Published in
7 min readJul 17, 2021
Created by the author through Canva, the image listed under (CC BY 2.0 license)

Zoom Call: A temporary portal for temples of Education

In India, Schools and Colleges are considered not less than temples, and in Hinglish, they are even associated as “Vidya kae Mandir” i.e. temples of Education.

However, due to the current ongoing pandemic, these temples closed their doors for their devotees and started looking for online solutions to continue providing education to their devotees.

Photo by August de Richelieu from Pexels

Like many others, my sister's daughter's school also ended up using zoom call to conduct online classes. So, one fine morning I just took a break from my WFH schedule and went across the room where my sister’s daughter was attending her Hindi language class.

I observed that the teacher on the other side of the zoom call was musically reciting the Hindi alphabet which encouraged my sister’s daughter and other students to follow along but during the same day when my sister asked her daughter to write Hindi alphabets she was not ready to do it at the first go.

Then I realized that the teacher made the learning fun for my sister’s daughters but there are no ways to make that part of learning fun for toddlers when it comes down to writing.

Photo by author, the image listed under (CC BY 2.0 license)

Furthermore, this whole situation allowed me to cook a solution for this interesting problem and I ended up making Aksha The ML pencil for toddlers to draw Hindi alphabets in air powered by TensorFlow Lite Micro.

Purpose

After making you aware of Why I built Aksha an ML Pencil it’s time to demonstrate to the entire TensorFlow lite community and Embedded Machine Learning enthusiasts about How I built it.

Shifting Gears

Now from this point onwards, this article will shift from story mode to tutorial mode so all developers get ready, here comes your favorite part.

Hardware Requirements:

To follow along you’ll be needing the below-mentioned items:

Photo by author, the image listed under (CC BY 2.0 license)
Photo by author, the image listed under (CC BY 2.0 license)

Demo SetUp A: Taping the micro USB cable on top of a stick with Kapton tape.

Photo by author, the image listed under (CC BY 2.0 license)

Demo SetUp B: the micro USB cable on top of a stick with Kapton tape with Arduino 33 BLE Sense Board.

Photo by author, the image listed under (CC BY 2.0 license)

Software Requirements

  • Arduino IDE
  • An up-to-date version of the Chrome web browser to use Web Bluetooth APIs.

Software libraries to Install

Machine Learning Workflow

To construct Aksha the ML Pencil I outlined a workflow, which is more or less not different from any other Deep Learning workflow.

  1. Decide on a goal i.e. To build an ML pencil that will recognize 5 Hindi alphabets by analyzing their accelerometer and gyroscope data using Machine Learning.
  2. Collecting Data: through Web Bluetooth APIs.
  3. Model Training: on the collected Data using Google Colab.
  4. Deployment: Deployment of the trained model for 5 Hindi alphabets on Arduino Nano 33 BLE Board using Arduino IDE and TensorFlow Lite Micro

#Note: However, before starting with the above-endorsed workflow, to make the Arduino 33 BLE Sense Board capable of collecting data, I deployed Magic Wand Code on it, available through the Harvard_TinyMLx library in Arduino IDE.

Photo by author, the image listed under (CC BY 2.0 license)

Data Collection

After deploying the magic wand code on the Arduino Board, I navigated to https://tinymlx.org/magic_wand for data collection.

  • Connected the Arduino board over Bluetooth, by clicking on the Bluetooth button.
  • Then after pairing the board, I was ready to collect data through Chrome’s WebBLE API.
Photo by author, the image listed under (CC BY 2.0 license)

Recording Data

After setting up everything successfully, I started recording data for the Hindi Alphabets mentioned below, the glimpse of the same can be seen in the gif below.

Photo by author, the image listed under (CC BY 2.0 license)

Strategies I used for successful data collection:

  • I didn’t switch the tab or refresh the page while recording the data in the browser.
  • I recorded as many samples as I can in one go, normally I did 500–600 samples per alphabet.
{0: 'इ', 1: 'क', 2: 'ट', 3: 'न', 4: 'प'}
GIF by author, created through Hnet under (CC BY 2.0 license)

Labeling Data

After recording the data, I cleaned the noisy and not-appropriately recorded Hindi alphabets.

Then I switched to data labeling which would have been easy if I was labeling some English alphabets but Google Input tools came to my rescue and allowed me to label the recorded Hindi alphabets pretty easily.

Photo by author, the image listed under (CC BY 2.0 license)

Have a look at the below GIF, to visually understand the approach I followed to clean and label the recorded Hindi Alphabets data.

Photo by author, through Canva and Hnet, the image listed under (CC BY 2.0 license)
Photo by author, through Canva and Hnet, the image listed under (CC BY 2.0 license)

Downloading Data

For each alphabet, after completing the data recording, cleaning, and labeling step, I clicked on the Download button, and a JSON file got downloaded into my system. I generated 2 JSON files per alphabet to have a good amount of Hindi alphabets data for the ML Model training step.

Photo by author, the image listed under (CC BY 2.0 license)

Model Training

To train an ML model on the collected data, I cruised to the below link, made few changes added the collected data in the directory, and in the end got a TensorFlow Lite for Microcontrollers model for the Hindi Alphabets dataset, I collected in the previous step.

Model Deployment

Before deploying the model using the Arduino IDE on Arduino 33 BLE Sense Board, apart from the filenames of the Magic Wand code Module I made two specific changes in the codebase.

  1. In “hindi_alphabets.ino” I replaced the label count and the labels information with my Hindi Alphabets count and Labels Information
Photo by author, the image listed under (CC BY 2.0 license)

2. I replaced the entire content of the file “magic_wand_model_data.cpp” with the content of TensorFlow Lite for Microcontrollers model which is nothing but a “.cc” file generate after ML model training and named it as “hindi_alphabets_model_data.cpp”.

Then, with a lot of courage, I uploaded the code or in another way, I started compiling the Sketch to Arduino 33 BLE Sense Board.

Photo by author, the image listed under (CC BY 2.0 license)

After Compiling the code, to test the Hindi Alphabets Model, I opened the Serial monitor present in the Arduino IDE made few movements in the air using the Board and luckily the Serial monitor was able to correctly identify those movements as Hindi alphabets.

And that’s how Aksha: An Arduino based ML Pencil came into existence

The demo is included below, don’t miss it.

ML Pencil Demo

The demo below showcases How Aksha The ML pencil works.

Video by author, the video listed under (CC BY 2.0 license)

Resources:

  1. Github repo with tinyML examples can be found here.
  2. Pete Warden Tutorial: Building a Magic Wand.
  3. HarvardX’s Tiny ML Course.
  4. Introduction to Embedded Machine Learning

Github Repo:

The code, models, JSON file, videos, and most importantly, the entire Hindi Alphabets recorded data can be found here.

https://github.com/ElephantHunters/Hindi_Alphabets_Recognition.git

Use it and extend what I Built.

Gratitude Corner:

  • Firstly a big shout out to Pete Warden who presented the tutorial: “Building a Magic Wand” at TinyML Summit 2021 which in turn motivated me to develop something simple, fun but most importantly a useful application of TinyML.
  • Secondly, I would also like to thank Brian Plancher whose frugal advice allowed me to record data for Hindi alphabets in a better way.

Thank You for Your Attention

Photo by Monstera from Pexels

You using your time to read my work means the world to me. I fully mean that.

Hope you enjoyed this article!

If you loved it, you can Buy Me A Coffee!

Also, follow me on Medium and LinkedIn if you want to! I would love that.

--

--

Naveen Manwani
Analytics Vidhya

Electronics Engineer by degree, ML engineer by interest, Hardware tinkerer by choice