All paths

Machine learning on a microcontroller

Gesture recognition from scratch in plain Python on a Raspberry Pi: features, k-nearest neighbors, decision trees, a neuron, gradient descent and a tiny neural network, and weights exported as C arrays for a microcontroller.

Raspberry Pi 4 Model BFree7 lessons5 h4 chapters3,070 XPCoding · Expert+400 XP

0 of 7 done

What you will build

3 projects, built step by step

7 lessons in 4 chapters, about 5 hours on a simulated Raspberry Pi 4 Model B. Free, in your browser, every step checked by the simulator.

Chapter 1 project

k-nearest neighbors

The simplest model there is: label a gesture like its nearest training gestures. Distance, votes, accuracy, choosing k, a confusion matrix, why the z-scores matter, and what k-NN costs a microcontroller.

Open it in the simulator
Chapter 2 project

A neuron

One artificial neuron: a weighted sum, a bias and a step. Set its weights by hand, then let the perceptron rule learn them, find where a single neuron gives up (a problem that is not linearly separable with one feature), and fire a lamp from it.

Open it in the simulator
Chapter 3 project

Weights in C

Ship the model: print the trained weights and the z-score constants as C arrays a microcontroller sketch can paste in, quantize them to int8, prove the small model still agrees, and print the C classify function that uses them.

Open it in the simulator
The map

Chapter by chapter

Each lesson opens when the one before it is done, and each chapter ends in a project.

Chapter 1

Data first

Turn raw sensor traces into features and split them honestly.

  1. Open330 XP

    Data and features

    Gestures from a wrist accelerometer: raw traces, six features that summarize half a second in six numbers, class averages that show why it can work, an honest train/test split, and z-scores computed from the training set only.

    0 of 5 steps

  2. ProjectLocked660 XP

    k-nearest neighbors

    The simplest model there is: label a gesture like its nearest training gestures. Distance, votes, accuracy, choosing k, a confusion matrix, why the z-scores matter, and what k-NN costs a microcontroller.

    0 of 5 steps

5 questions, graded as you go.
Chapter 2

Models you can read

Decision trees and a single neuron, and where each one breaks.

  1. Locked280 XP

    Decision trees

    A model you can read: the best first question by Gini impurity, a depth-2 tree printed as rules, overfitting made visible with three mislabeled gestures, and the tree turned into C if statements.

    0 of 4 steps

  2. ProjectLocked560 XP

    A neuron

    One artificial neuron: a weighted sum, a bias and a step. Set its weights by hand, then let the perceptron rule learn them, find where a single neuron gives up (a problem that is not linearly separable with one feature), and fire a lamp from it.

    0 of 4 steps

4 questions, graded as you go.
Chapter 3

Train and ship

Gradient descent on the Pi, then weights a microcontroller can run.

  1. Locked330 XP

    Training on the Pi

    Gradient descent from scratch: softmax regression for all three gestures, the cross-entropy loss falling epoch by epoch, test accuracy and confidence, learning rates too small and too big, and a 6-4-3 neural network trained by backpropagation.

    0 of 5 steps

  2. ProjectLocked560 XP

    Weights in C

    Ship the model: print the trained weights and the z-score constants as C arrays a microcontroller sketch can paste in, quantize them to int8, prove the small model still agrees, and print the C classify function that uses them.

    0 of 4 steps

5 questions, graded as you go.
Chapter 4

Boss

Live gesture recognition on the traffic lights.

  1. Locked350 XP

    Boss: gesture recognition

    The boss: the whole pipeline live. Press the button, a fresh gesture is recorded, featurized, z-scored and classified, and the traffic lights show wave, punch or circle; a confidence threshold says "not sure" to a gesture it was never taught; and 30 never-seen gestures measure it honestly.

    0 of 6 steps

3 questions, graded as you go.
Syllabus

Every lesson in the course

All 7 lessons, in order, each with what it covers. Any of them opens in the editor right away.

Chapter 1

Data first

  1. Data and featuresGestures from a wrist accelerometer: raw traces, six features that summarize half a second in six numbers, class averages that show why it can work, an honest train/test split, and z-scores computed from the training set only.
  2. k-nearest neighborsThe simplest model there is: label a gesture like its nearest training gestures. Distance, votes, accuracy, choosing k, a confusion matrix, why the z-scores matter, and what k-NN costs a microcontroller.
Chapter 2

Models you can read

  1. Decision treesA model you can read: the best first question by Gini impurity, a depth-2 tree printed as rules, overfitting made visible with three mislabeled gestures, and the tree turned into C if statements.
  2. A neuronOne artificial neuron: a weighted sum, a bias and a step. Set its weights by hand, then let the perceptron rule learn them, find where a single neuron gives up (a problem that is not linearly separable with one feature), and fire a lamp from it.
Chapter 3

Train and ship

  1. Training on the PiGradient descent from scratch: softmax regression for all three gestures, the cross-entropy loss falling epoch by epoch, test accuracy and confidence, learning rates too small and too big, and a 6-4-3 neural network trained by backpropagation.
  2. Weights in CShip the model: print the trained weights and the z-score constants as C arrays a microcontroller sketch can paste in, quantize them to int8, prove the small model still agrees, and print the C classify function that uses them.
Chapter 4

Boss

  1. Boss: gesture recognitionThe boss: the whole pipeline live. Press the button, a fresh gesture is recorded, featurized, z-scored and classified, and the traffic lights show wave, punch or circle; a confidence threshold says "not sure" to a gesture it was never taught; and 30 never-seen gestures measure it honestly.
Kits

Build it on your bench too

Every lesson runs in the simulator with nothing to buy. When you want the real thing, these kits have the parts.

Have a kit already?

Find your kit

Pick the starter kit you own and run every lesson in its manual with the same parts on the same pins.

See every kit
Questions

About Machine learning on a microcontroller

Is Machine learning on a microcontroller free?

Yes. All 7 lessons of Machine learning on a microcontroller are free and run in your browser, with nothing to install and no parts to buy before you start.

Do I need a real Raspberry Pi 4 Model B?

No. Every lesson runs on a simulated Raspberry Pi 4 Model B with its parts on the canvas, and the simulator checks each step as you go. When you want to build it for real, the same wiring and code work on a real board.

How long does Machine learning on a microcontroller take?

About 5 hours: 7 lessons in 4 chapters, each one a few short steps. Your progress is kept, so you can stop after any lesson and pick up where you left off.

What will I build?

Each chapter ends in a project that puts it together: k-nearest neighbors, A neuron and Weights in C.

Where do I start?

With "Data and features", and each lesson builds on the one before it. New to circuits? Electronics basics is the course that starts from zero.