Lesson plan

Tiny chips: ATtiny85 and CH32V003 lesson plan

The eight-pin ATtiny85 and the ten-cent CH32V003 RISC-V: six pins and their fuses, an 8 KB budget with no multiplier, sleep and the watchdog for coin-cell life, I2C bit-banged by hand, a race between the two chips, and a twinkling star ornament.

3 chapters, 7 lessons, about 6 hours, on the ATtiny85. Every lesson runs in the browser, with nothing to install.

The unit

Objectives and materials

By the end, students can

  • Why tiny, which pin does what, and what fits in 8 KB.
  • Sleep for battery life, I2C by hand, and the RISC-V alternative.
  • A coin-cell star ornament that twinkles and sleeps.

Materials for the whole unit

  • ATtiny85
  • Full-size breadboard
  • I/O expander, PCF8574
  • LED x 2
  • Potentiometer
  • Pushbutton
  • Resistor x 2
  • WCH CH32V003 (RISC-V, 16 KB)

Every part is already on the simulator’s bench, so there is nothing to buy or hand out. The counts are the most any one lesson uses, if you build it on real breadboards too.

Chapter 1. About 2 h 25 min

Life in eight pins

Why tiny, which pin does what, and what fits in 8 KB.

LessonTimeWhat students do
Why tinyAn eight-pin ATtiny85 on a coin cell’s 3 V: six I/O pins, 8 KB of flash, 512 bytes of SRAM, 8 MHz from its own oscillator, a serial port it makes itself, and two lamps blinking for about a dollar.45 min
  1. Run it: a whole computer in eight pins
  2. Two lamps, one port
  3. Why use a chip this small
  4. Up the tempo
Pins and fusesSix pins doing four jobs: a knob on the ADC, two PWM lamps, a button on the pin-change interrupt and a software serial port, plus the fuses that set the clock and can turn the RESET pin into a seventh.55 min
  1. Run it: the pin map
  2. Turn the knob
  3. Press the button
  4. The lamps are PWM
  5. Fuses
8 KB budgetsFlash, SRAM and time on a chip with no multiplier: a temperature conversion in fixed point fits in 3.4 KB and runs 100 times in 144 microseconds; the same in floating point needs 7.3 KB and 1872 microseconds.45 min
  1. Run it: fixed point
  2. 512 bytes of SRAM
  3. No multiplier
  4. Try floating point

Materials

  • ATtiny85
  • Full-size breadboard
  • LED x 2
  • Potentiometer
  • Pushbutton
  • Resistor x 2

Check for understanding

Each student finishes "8 KB budgets" on their own, without opening the hints. The simulator checks 4 of its 4 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Try floating point".

Chapter 2. About 2 h 35 min

Tiny chip skills

Sleep for battery life, I2C by hand, and the RISC-V alternative.

LessonTimeWhat students do
Sleep and wakeA coin cell lasts as long as the chip sleeps: the watchdog wakes the ATtiny85 every half second to flash a lamp, the button wakes it at once, and the datasheet’s currents say 63 days, or 669 at eight seconds.55 min
  1. Run it: the sums first
  2. Asleep
  3. The watchdog alarm clock
  4. The button wakes it too
  5. Sleep longer
Bit-banged I2CI2C by hand on two ordinary pins: open drain by switching the pin direction, a START and a STOP, eight bits and an ACK, a scan that finds a PCF8574 at 0x20, and a byte written to its pins and read back.55 min
  1. Run it: a scan with no library
  2. Open drain, by hand
  3. Write a byte to eight pins
  4. Read it back
  5. Your own pattern
RISC-V for centsThe ten-cent CH32V003, a 32-bit RISC-V at 48 MHz, races the ATtiny85 on the same CRC-32: 6.4 ms against 131 ms, the same answer, and what 32 bits and six times the clock buy you.45 min
  1. Run it: the same code on two chips
  2. The AVR finishes
  3. It blinks too
  4. Choosing between them

Materials

  • ATtiny85
  • Full-size breadboard
  • I/O expander, PCF8574
  • LED x 2
  • Pushbutton
  • Resistor x 2
  • WCH CH32V003 (RISC-V, 16 KB)

Check for understanding

Each student finishes "RISC-V for cents" on their own, without opening the hints. The simulator checks 4 of its 4 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Choosing between them".

Chapter 3. About 1 h 5 min

Boss project

A coin-cell star ornament that twinkles and sleeps.

LessonTimeWhat students do
Boss: a coin-cell star ornamentA twinkling star ornament on an ATtiny85: two lamps twinkle at random in PWM, the button steps through twinkle, steady and off, and off is a deep sleep that only the button ends, with the battery sums from the datasheet.65 min
  1. Run it: a star that twinkles
  2. Twinkling
  3. Steady
  4. Off really is off
  5. Wake it up
  6. Make it yours

Materials

  • ATtiny85
  • Full-size breadboard
  • LED x 2
  • Pushbutton
  • Resistor x 2

Check for understanding

Each student finishes "Boss: a coin-cell star ornament" on their own, without opening the hints. The simulator checks 6 of its 6 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Make it yours".

Your class

Teach this unit as a class

Start a class from this course and its 7 lessons are assigned in one go, in order. Students join with a six-character code or printed login cards, and each one’s work comes back to you.

The class tools are free for 30 days for one class of up to 20 students, with no card. The lessons themselves are free either way.