The course
Charts on small screens is an intermediate Coding course in seven lessons. Every lesson runs on one circuit, the capsule console: an ESP32-C3, a 2.4 inch ILI9341 screen on GPIO 18 to 21, and a BME280 cabin sensor on I2C (SDA 4, SCL 5). Each lesson opens its own sketch, and steps are checked against what the board prints: scales, tick lists, peaks, bar widths, needle angles, frame times and alarms.
- Scales and axes: a day of cabin temperatures mapped onto pixels with a linear scale, a y axis that has to flip, and nice 1, 2, 5 ticks. Fewer ticks, and when an axis should start at zero.
- Line charts: 960 CO2 samples in 240 columns. Bresenham lines, a decimation that silently hides a workout spike, min and max columns that keep it, and an alarm line counted from the data.
- Bars: six oxygen tanks. Widths and gaps in whole pixels, bars that always start at zero, sorting by index, and color spent on one message.
- Sparklines: four word-sized charts with a scale each, a normal band, and a minimum span so noise stays flat.
- Gauges: the live cabin pressure on a dial. A value mapped onto an angle, sine and cosine for the needle's tip, a storm front from the sensor's slider, and a wider sweep.
- Scrolling real time: ten samples a second into a ring buffer, an auto scale that forgets, and two ways to draw: scrolling at about 39 ms a frame against an oscilloscope sweep at 1.6 ms.
- Boss: a sensor dashboard.
The boss
The dashboard is four cards from one BME280: a sweeping temperature trace on a fixed scale, a pressure dial with a red zone, a humidity bar with its limit, and a banner that says in words what is wrong. Four times a second it reads the sensor and redraws only what changed, inside a 250 ms frame budget. The steps drag the sensor's sliders to trip each alarm, test an alarm by moving its limit, and end with a panel of your own.
The screen and the sensor
The ILI9341 is driven over bit-banged SPI by mokxi_ili9341.h, the same
driver as the handheld console course. Clearing the whole screen takes about
110 ms down that wire, which is why every lesson after the first thinks
about what to redraw. The BME280 uses the familiar Adafruit library calls
(bme.readTemperature(), readPressure(), readHumidity()), and its
temperature, pressure and humidity sliders change what it measures while a
sketch runs.
How the C3 engine differs
The board runs Mokxi's own firmware runtime, not the Arduino core: the same
setup() and loop(), Wire, Serial and snprintf with floats. The C3
has no floating point unit, so floats run in software; a few hundred trig
calls a frame are no trouble. The logs in lessons 1 to 4 are fixed or made
from a seeded generator, so every number in the steps is the same on every
run.
Where next
- Vectors, trig and matrices for code: the math behind the gauge needle, ending in a compass on the same screen.
- Generative art and cellular automata: more drawing on the C3, on an LED panel.