Hardware, robots and physics › Learn with missions

Hardware, robots and physics

Missions: guided builds on the Bench

A mission is a small build you wire on the playground's Bench tab. It starts with the parts placed and nothing wired. Its steps say which wires to make, and tick each step as its wires appear. When every wire is there and the mission's test plan passes, the mission is finished.

There are eleven, from a blinking LED to a two-board robot. Each is an ordinary arche-lang model with a requirement and a test case. Each also runs on your computer with archec.

The missions#

# Mission Level Boards What it teaches
1 Blink beginner Arduino UNO a pin, a LED, a periodic step
2 A button lights a LED beginner Arduino Nano an input and an output
3 A knob dims a LED beginner Arduino UNO an analog input, PWM
4 A servo follows a knob beginner Arduino UNO a servo on its own battery, a common ground (board-ground)
5 Parking sensor intermediate Arduino UNO a state machine, a requirement per behaviour
6 A night light on 3.3 V intermediate STM32 Blue Pill a 3.3 V board, hysteresis, Embassy firmware
7 Two boards over UART intermediate Arduino UNO, Arduino Nano a message, a link, two binaries
8 5 V meets 3.3 V intermediate Arduino UNO, NodeMCU a level shifter (pin-level)
9 A weather screen intermediate Raspberry Pi Pico I²C, a ui on a 128×64 screen
10 A Wi-Fi weather node advanced NodeMCU an RGB LED, a message over Wi-Fi
11 A two-wheeled robot advanced Raspberry Pi 4, Arduino Mega 2560 a motor driver, a battery, a deployment on two boards

They are in examples/missions/, one folder each (01-blink, 02-button-led…).

Play one#

In the playground, open the Bench tab and pick a mission from the list. It loads the mission's starting model. The Steps panel beside the bench lists what to do.

  1. Click a pin, then another: that is a wire, written into the model as a link (uno.d13 -> led.pin).
  2. A step is ticked once all its wires are there. The bench says how many are left ("2 connections to go").
  3. "Wire it for me" makes the wires that are left.
  4. When every wire is there, press Run. The mission is finished when its test plan passes. The Steps panel then shows "What you learn".

Some missions end with a link that is not a wire: a message from one part of the software to another (tx.cmd -> rx.cmd). The bench does not draw software parts. Write that link in the model, or press "Wire it for me".

On your computer:

cd examples/missions/01-blink
archec check start.arche          # the parts placed, nothing wired
archec sim done.arche --test      # the test plan of the wired model
archec gen done.arche --target c  # the UNO's firmware

What a mission is#

A mission is a folder with three files. There is no new syntax: the models are plain arche-lang, and the rest is JSON.

File What it holds
start.arche the starting model: the boards, the devices and the software placed, no wires
done.arche the same model wired: what the mission expects. It has at least one requirement and the test plan that marks the mission finished
mission.json the title, level, minutes and boards; the steps; what you learn; the test plan's id; the firmware it makes

start.arche is done.arche without the links of the steps. Only its first line differs: // Mission 1, Blink: to wire. in place of wired..

mission.json:

{
  "title": "Blink",
  "summary": "An Arduino UNO turns a LED on and off every half second.",
  "level": "beginner",
  "minutes": 10,
  "boards": ["ArduinoUnoR3"],
  "steps": [
    { "text": "Wire the LED's pin to the UNO's D13.", "links": ["uno.d13 -> led.pin"] }
  ],
  "learn": ["A board part has a port per header pin: uno.d13 is the pin printed D13."],
  "test": "TP-BLINK",
  "gen": [{ "target": "c", "deployment": "OnUno" }]
}
Field Meaning
title, summary its name, and one sentence on what is built
level beginner, intermediate or advanced
minutes about how long it takes
boards the store boards it uses, by component name
steps each step's text, and the links it makes, written as in done.arche ("a.p -> b.q", in either direction)
learn "What you learn": a few points, shown at the end
test the test plan of done.arche that marks it finished
gen the firmware made of done.arche: each target (and deployment) of archec gen
noGen why a board gets no firmware, when one does not (an ESP8266)

The checks#

test/missions.test.js checks every mission:

  • start.arche has no error. Warnings are fine: a half-wired model warns.
  • done.arche has no error.
  • The steps' links, together, are exactly the links done.arche has and start.arche lacks: missingLinks(start, done).links. None is said twice.
  • start.arche is done.arche without those links.
  • done.arche has a requirement, and its test plan passes in archec sim done.arche --test <plan>.
  • archec gen succeeds for each entry of gen.

The site's build reads the missions through the site API, missions(). A malformed mission stops the build.

In code#

src/missions.ts reads and checks missions. It reads no disk, so the playground's worker uses it too. It is exported from the library and from the playground's module.

Function What it does
readMission(id, files) a mission from its three files, or the list of what is wrong
loadMissions(list, read) every mission of a folder, in order of name
missionProgress(mission, program) each step, done once its links are in the model; the links to go
checkMission(mission, start, done) what the files must agree on (the checks above, but the test plan's run)
missionLinkKey(link) a link as they are compared: its two ends, in either order

Limits#

  • The firmware drives only the devices that have a driver on that board. archec gen succeeds for every mission that has gen. Its notes say what is left for you:
    • On the AVR boards (hal avr), the HC-SR04 (mission 5), the L298N and the TT motors (mission 11) have no C driver yet. Drive them in drivers.c.
    • With Embassy, the LDR module (mission 6) and the DHT11 (mission 9) have no Rust driver. The SSD1306's driver has no write (mission 9).
  • The NodeMCU's ESP8266 gets no firmware (missions 8 and 10, see Make AVR firmware). Mission 8 generates the UNO's binary only.
  • The hub of mission 10 is a computer of your own: the model says what it receives, not its program.
  • On the UNO and the Nano, the UART is on D0 and D1, the USB serial's pins. Missions 7 and 8 warn about it (pin-conflict). Unplug those wires while you upload.
  • The bench draws boards and devices. A bus with ports (the serial line, the Wi-Fi) is drawn as a device. A link between software parts is written in the model.

See also Boards, AVR firmware and the browser simulator.