Lesson 10 · 60 minutes

The 32 KB Backpack

Engineering is choosing

Today's goal

Choose a feature set that fits in the Arduino's memory, justify every choice, and prove it fits by compiling it.

Ideas in this lesson

Sense → Think → Do

Before any robot senses, thinks or does anything, someone chose which senses, thoughts and actions it has room for. Today you are that someone.

How the session runs

  1. Show the budget: about 32.2 KB in all. The default build uses about 32.2 KB: it is full.
  2. Hand out the price list: IMU 1.9 KB, laser 1.3 KB, IR remote 0.8 KB, 20 extra demos 0.75 KB, ADS1115 inputs 0.35 KB, mux 0.34 KB (off by default), sonar 0.3 KB.
  3. Each group picks a mission: maze runner, line racer, show robot for a party, classroom-safe robot.
  4. Choose a loadout for the mission. It must fit. Write why each feature is in or out.
  5. Open the sketch and set the USE_ flags at the top (1 = in, 0 = out). Compile in the Arduino IDE and read 'Sketch uses N bytes'. Did your estimate match?
  6. Flash it and show the robot doing its mission. The app greys out demos the robot does not have.
  7. Discuss: the extra demos and everything else do not quite fit together. Which would you drop, and why?

Try this

When it goes wrong

What you seeWhat it means
'Sketch too big' when compilingOver budget: turn one more feature off and compile again.
A feature is missing on the robotIts USE_ flag is 0, or the part was not found at start-up (check the console).
Demos greyed out in the appBuilt without USE_EXTRA_DEMOS. Expected: the robot tells the app which demos it has.
Notes for the grown-up

This lesson works best for older kids, but the trade-off idea works at any age as a 'packing for a trip' game. The real story: this sketch went from 84 bytes free to fitting a laser, an IR remote and a sonar by rewriting parts to be smaller. Then in 0.10.19 the laser had to come out to make room for calibration saved on the robot, and in 0.10.20 it came back: the calibration runs moved into their own program, calibration.ino (then named mecanum_calibration.ino), made from the same source with the sensors left out. Two programs sharing one EEPROM is how real products do it: a factory test program, then the product.

Ages: K-5: 'pack the backpack' with paper cards for each feature and a fixed number of slots. 6-12: compile real builds and compare estimated vs actual sizes.

Materials: Laptop with Arduino IDE (or arduino-cli) and the sketch, robot, USB cable, feature price cards, mission cards.

← Robots Go WrongAll lessons →