Disclaimer: In this class, we aim to setup a development environment that is as isolated as possible without being fully containerized. This is possible via a Git repository that supports:
- a conda environment for Python, Jupyter, plotting, serial tooling, and TensorFlow
- a downloaded Arduino CLI binary placed in
tools/arduino-cli/- repo-local Arduino CLI state so package indexes, downloads, caches, and sketchbook files do not spill into each student’s global machine setup
First, you are to clone the repository.
1
2
git clone https://github.com/ngo-classes/tinyml.git
cd tinyml
The layout of this repository can be presented as follows.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
.
├── .arduino-build-cache/
├── .arduino-data/
├── .arduino-downloads/
├── .arduino-user/
├── arduino-cli.yaml
├── data/
├── environment.yml
├── firmware/
├── models/
├── notebooks/
├── scripts/
└── tools/
└── arduino-cli/
environment.yml: conda environment definitionarduino-cli.yaml: Arduino CLI configurationtools/arduino-cli/: where each student places the correct Arduino CLI binary for their OSdata/: reserved for datasets; contents ignored by git by defaultmodels/: reserved for trained/exported models; contents ignored by git by default.arduino-*: local Arduino CLI package/cache/user state, kept in the repo but ignored by git
1
2
conda env create -f environment.yml
conda activate tinyml
You are to download the latest binary release of Arduino CLI and unzip the downloaded files. Next, place one of the following in tools/arduino-cli/ depending on your system:
arduino-cli.exe for Windowsarduino-cli for macOS or LinuxThat directory is intentionally git-ignored so the binary file is not accidentally committed.
For macOS/Linux/Git Bash, run the followings:
1
source scripts/activate.sh
For Windows PowerShell, run the followings:
1
2
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
.\scripts\activate.ps1
For macOS/Linux/Git Bash, run the followings:
1
2
chmod u+x scripts/check-setup.sh
scripts/check-setup.sh
For Windows PowerShell, run the followings:
1
.\scripts\check-setup.ps1
Arduino Mbed OS Nano Boards core used by the Nano 33 BLE/BLE Sense, plus the course libraries ArduinoBLE, Arduino_LSM9DS1, and Harvard_TinyMLx.For macOS/Linux/Git Bash, run the followings:
1
2
chmod u+x scripts/bootstrap-arduino.sh
scripts/bootstrap-arduino.sh
For Windows PowerShell, run the followings:
1
.\scripts\bootstrap-arduino.ps1
In this set up, we are using PlatformIO from inside VSCode. Therefore, it is important that you do not need to install PlatformIO Core separately for this workflow; PlatformIO Core is bundled with the VS Code extension and is meant to be used through the PlatformIO IDE Terminal.
Download and install the official Microsoft build of Visual Studio Code. PlatformIO IDE is built on top of VS Code.
Do the followings in VSCode:
PlatformIO IDE extension.
PlatformIO icon will show up on the left activity bar.
platformio use builtin Use a built-in PlatformIO Core is checked.
PlatformIO sidebar
Once that terminal opens, test:
1
pio --version
If it works there, PlatformIO is installed correctly inside VS Code.
PlatformIO’s own quick start uses a Blink project to introduce the workflow. ([PlatformIO Documentation][1])
In VS Code:
After creation, PlatformIO will generate a standard project structure with:
platformio.ini src/ foldermain.cpp inside src/ ([PlatformIO Documentation][1])main.cpp with BlinkOpen src/main.cpp and replace the contents with the Blink example. PlatformIO’s quick start provides the Arduino-based Blink code and notes that it is for Arduino-based boards. ([PlatformIO Documentation][1])
Use:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include "Arduino.h"
// Set LED_BUILTIN if it is not defined by Arduino framework
// #define LED_BUILTIN 13
void setup()
{
pinMode(LED_BUILTIN, OUTPUT);
}
void loop()
{
digitalWrite(LED_BUILTIN, HIGH);
delay(1000);
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
}
This is essentially the same Blink pattern PlatformIO shows in its quick start. ([PlatformIO Documentation][1])
PlatformIO documents two easy routes: toolbar or keyboard shortcut. The toolbar is less mysterious for students. ([PlatformIO Documentation][1])
Keyboard shortcut
cmd-shift-b as the build shortcut.You can also use the task menu:
After a successful build:
Or:
The keyboard shortcut PlatformIO lists for upload is ctrl+alt+u. ([PlatformIO Documentation][1])
PlatformIO includes a Serial Port Monitor in the toolbar and in its task system. It also allows customization in platformio.ini through monitor-related options such as monitor_port and monitor_speed. ([PlatformIO Documentation][1])
To open it:
Or:
The listed shortcut is ctrl+alt+s. ([PlatformIO Documentation][1])
If you want to define the monitor baud rate in platformio.ini, PlatformIO documents monitor_speed for that purpose. ([PlatformIO Documentation][1])
Example:
1
2
[env:yourboard]
monitor_speed = 115200
PlatformIO documents the status-bar toolbar and its common buttons. This is worth showing students explicitly because it becomes their dashboard. The toolbar includes quick access to:
PlatformIO exposes a Project Task Explorer under the PlatformIO activity bar and also integrates tasks into Terminal → Run Task…. That is useful when students need a visible list of actions such as Build, Upload, Clean, and Monitor instead of memorizing icons or shortcuts. ([PlatformIO Documentation][1])
If your repo contains several firmware projects, PlatformIO supports multi-project workspaces through VS Code’s multi-root workspaces. That is the official route when you are working on multiple related firmware folders at once. ([PlatformIO Documentation][1])
pio command not found”Usually one of these:
platformio-ide.useBuiltinPIOCore is offPATH was overwritten instead of extendedpio to work system-wide without using Install Shell Commands ([PlatformIO Documentation][1])firmware/ starter sketch templatesnotebooks/serial_plot.ipynbmodels/README.md describing naming conventions for exported models