Lessons and the learning game

Tiny chips: ATtiny85 and CH32V003

Build with the smallest chips: the ATtiny85 and the ten-cent CH32V003. Fit in 8 KB, sleep for battery life, bit-bang I2C, and make a star ornament.

The bench

An ATtiny85 sits in a breadboard on 3.0 V, a coin cell's voltage, with a red lamp on PB0, a yellow lamp on PB1 and a button on PB2. The pins lesson adds a knob on PB4, the I2C lesson swaps the PB0 lamp and the button for a PCF8574 I/O expander on PB0 (SDA) and PB2 (SCL), and the RISC-V lesson puts a CH32V003 board beside the ATtiny85 with a green lamp on PD2. The ATtiny85 prints through its bit-banged serial port on PB3, at 9600 baud.

Take the course at Tiny chips: ATtiny85 and CH32V003 on /learn.

What each sketch does

  • tinywhy: blinks both lamps and says what the chip has.
  • tinypins: a knob on the ADC dims the two PWM lamps, and the button raises a pin-change interrupt.
  • tinybudget: one temperature conversion in fixed point (144 us for 100) or floating point (1872 us, and twice the flash).
  • tinysleep: sleeps between watchdog wakes, flashes a lamp, wakes on the button, and works out a CR2032's life from datasheet currents.
  • tinyi2c: I2C drawn by hand on two pins: a scan, a byte written to the PCF8574 and read back.
  • tinyrvavr and tinyrv: the same CRC-32 on the ATtiny85 (131 ms) and the CH32V003 (6.4 ms).
  • tinystar: the boss, a twinkling star ornament with twinkle, steady and a deep-sleep off mode on one button.

Honest limits of the simulator

  • An ATtiny85 does not power up from a battery part here, so a 3.0 V supply symbol stands in for the CR2032.
  • Chips draw no modeled supply current, so every battery-life figure comes from the ATtiny85 datasheet's typical currents, worked out in the sketch.
  • Every ATtiny85 sleep mode behaves as idle here, so the sketches switch timer 0's interrupt off themselves, as power-down would stop it.
  • The ATtiny85 runs at exactly 8 MHz, with CKDIV8 cleared and no oscillator drift. A real one starts at 1 MHz until the fuse is changed, and its internal oscillator is only good to a few percent.
  • Mokxi's own builds of ATtiny85 sketches are capped at 4 KB; the floating-point version of the budget sketch only builds from the editor.

Low-power products for sleep and battery budgets on the Uno, and Embedded C that survives for writing code that fits small chips.