
OSO BOOK C1
joeycastillo/The-Open-Book
For details on how to build, test and use Open Book, I've made documentation available here.

Battery-powered handheld virtual pet on a custom 2-layer STM32L433 PCB. FreeRTOS, hand-written SSD1306 and LIS3DH drivers, wake-on-motion.
Pocket pet is an open-source printed circuit board by kondovskii, from the kondovskii/pocket-pet repository on GitHub. It is a 2-layer board of 55 × 70 mm with 38 parts on 61 nets, routed with 342 tracks and 58 vias.
Its parts include 11 capacitors, 8 resistors, 5 connectors, 3 ICs and 3 switches. It belongs with the power boards and the STM32 boards of this library.
Battery-powered handheld virtual pet on a custom 2-layer PCB. STM32L433, FreeRTOS, hand-written SSD1306 driver, wake-on-motion.
Status: working. Board assembled and running the full firmware — display, accelerometer, buttons, and battery power all verified on the custom hardware.
Built to close four specific gaps: custom PCB design, bare-metal ARM programming, RTOS usage, and datasheet-level driver work. Every part was chosen and every driver written from the datasheet rather than pulled from a library, so that each decision is defensible.
| Block | Part | Notes |
|---|---|---|
| MCU | STM32L433CCT6 (LQFP-48) | Cortex-M4F, 256K flash, low-power STOP2 modes |
| Charger | MCP73831 | ~196 mA charge current (R_PROG = 5.1 k) |
| Regulator | MCP1700-3302 | 3.3 V LDO, low quiescent current |
| Input | USB-C, charge only | 5.1 k CC1/CC2 pull-downs for correct sink advertisement |
| Display | SSD1306 128x64, SPI | Hand-written driver, no vendor library |
| Motion | LIS3DH, I2C | Hand-written driver; soldered direct, isolatable via R6 |
| Battery | 500 mAh LiPo | JST-PH |
2-layer FR4, designed in KiCad, fabricated by JLCPCB.
MSI at 32 MHz, not HSI16, not 80 MHz. MSI is the oscillator the L4 wakes on coming out of STOP mode, and it can be trimmed against an LSE crystal. 32 MHz was chosen over the 80 MHz maximum because the workload — a 128x64 display refresh and an accelerometer read — does not need it, and lower active current is free. The power story for a battery device is duty cycle (STOP2 at roughly 1 uA versus milliamps awake), not clock rate.
USB-C is charge-only. No USB data. The 5.1 k pull-downs on CC1 and CC2 are what make a charger treat the board as a valid sink; without them a compliant USB-C supply provides no VBUS at all. Programming and debug go over SWD, which keeps the firmware simpler and the BOM smaller.
0 ohm jumpers on the peripheral rails. R5 and R6 sit in series with the display and accelerometer supplies so either can be cut to measure that peripheral's current draw in isolation, or to remove it from the picture while debugging.
I2C pull-ups fitted but not populated. R7 and R8 are marked DNP because the LIS3DH module carries its own. Measured at 10 k, which is weak for 400 kHz on a board with no ground plane, so the bus runs at 100 kHz — the workload is roughly 60 bytes per second, so there is nothing to gain from the higher rate and the slower edges have four times the rise-time margin.
Peripherals soldered directly. The original plan was female headers so modules could be swapped. They were dropped because SW1, the power switch, is surface-mounted flat to the board and cannot rise with them — sockets would have left it recessed roughly 8.5 mm below the display plane and complicated the enclosure. The 0 ohm rail jumpers (R5, R6) preserve the debugging benefit: either peripheral can be isolated or current-measured by lifting one resistor.
SWD broken out to a 6-pin header with SWDIO, SWCLK, SWO, NRST, 3V3 and GND, in ST-Link pin order.
Written from the SSD1306 datasheet rather than pulled from a library: SPI transport with manual DC and CS control, the full initialisation sequence, a 1024-byte framebuffer, Bresenham line drawing, and a 5x7 column-major font.
Draw to RAM, flush once. Every primitive writes to the framebuffer and
nothing reaches the panel until ssd1306_update_screen(). Frames appear whole
rather than building up visibly, and the flush is a single 1024-byte SPI burst
instead of hundreds of small transfers.
The font is column-major because that matches the controller's own vertical byte layout, so rendering a glyph is a single bit test per pixel with no transposition.
Clipping lives in one place. Only ssd1306_draw_pixel() bounds-checks;
lines, rectangles and text all inherit it. One guard to get right instead of
six, and no way for them to disagree.
Validated on a NUCLEO-L432KC with a 7-pin SPI module before the custom boards arrived, so that display bring-up and board bring-up could be debugged independently. A blank screen on the custom board now means a hardware fault, not an unproven driver.
I2C driver for the LIS3DH, written from the datasheet: register map, burst reads, and a WHO_AM_I identity check that fails loudly rather than returning plausible garbage.
Auto-increment must be requested explicitly. Bit 7 of the register address
tells the part to advance its internal pointer across a burst. Without it,
reading six bytes from OUT_X_L returns the same register six times — all
three axes identical, which looks exactly like a dead sensor rather than a
protocol mistake.
Block Data Update is enabled so the part cannot refresh an output register pair between the read of the low byte and the high byte. Without it, occasional samples are the low half of one reading stitched to the high half of the next.
Signed arithmetic shift for the 12-bit values. Output is left-justified 16-bit; high-resolution mode makes only the top 12 bits meaningful. Shifting a signed type sign-extends and preserves negative readings, where the same shift on an unsigned type would turn -1 into 4095.
The I2C address depends on the board, not the chip. On the Nucleo bench
wiring SA0 and CS float, and the module's own strapping gives 0x19. On the
custom board J6 ties SA0 to ground and CS to 3V3, giving 0x18. The address
therefore lives in pocket_pet_pins.h behind a board selector rather than in
the driver, because it is a board fact.
Three tasks, no shared state.
inputTask polls and debounces the buttons, detects shake, publishes events
petTask owns the pet state, applies events, ticks it forward once a second
displayTask redraws at 8 fps, taking a new state when one is availableTasks communicate only through queues, and the pet state is passed by value rather than by pointer — each task works on its own copy, so there is no shared memory, no mutex, and no race to get wrong.
The two queues have deliberately different depths. The state queue is depth 1 because the display only ever cares about the newest state; a deeper one would just mean rendering stale frames. The event queue is depth 4 because a dropped button press is a bug, where a dropped frame is not.
Input is edge-triggered, not level. A press registers on the released-to-pressed transition, so holding a button feeds the pet once rather than continuously.
The display task runs on a timer, not on the queue. It was originally
blocked on osWaitForever, which meant it only redrew when the pet state
changed — once a second, far too slow for animation. It now wakes every 125 ms
and takes a new state if one is waiting, so rendering rate and simulation rate
are decoupled.
Three stats decay on separate timescales: hunger fastest, then mood, then energy. Any stat reaching zero starts a two-minute distress countdown with a visible warning; ignoring it kills the pet. The countdown exists so that death is a consequence of ignoring something, not a surprise.
The lowest stat decides the pet's expression, so it looks as bad as its worst problem rather than averaging out and hiding the thing the player needs to notice.
Two buttons, four actions. Left feeds. Right plays on a short press and toggles sleep on a one-second hold. Shaking the board is a third input, detected by comparing squared acceleration magnitude against a threshold — squared, so the comparison needs no square root and no floating point.
Sleep is the only way to recover energy, and playing costs it, so the stats interact rather than being three independent bars.
Actions trigger a two-second reaction animation. This confirms the press registered, and gives the less-frequently-seen animations a reason to exist — most moods map to slow-moving stats you rarely watch change.
Found during a design review after the boards were already at fab. Documented rather than hidden — these are the v1.1 fix list.
snprintf, newlib
reentrancy and the scaled bitmap blit comfortably exceed. The symptom was a
HardFault minutes after boot, triggered by bursts of input, with nothing
obviously stack-related in the trace. It was fixed once by hand, but the
default task's stack size lives in generated code outside the USER CODE
markers, so the next CubeMX regeneration quietly reverted it. Now set in the
.ioc at 2 KB per task, with configCHECK_FOR_STACK_OVERFLOW enabled so any
future overflow halts in a named hook rather than surfacing as an unrelated
fault.MX_I2C1_Init() still carried the Fast
Mode timing value, so the bus ran at 400 kHz regardless. With 10 k pull-ups
and no ground plane that was marginal, and produced intermittent LIS3DH
failures that looked like a driver or wiring fault. Toggling the mode and
disabling custom timing both failed to force a recalculation; the value had
to be entered by hand. Verify hi2c1.Init.Timing in i2c.c after any speed
change rather than trusting the .ioc.hardware/pocket-pet/ KiCad project, fab outputs under fab/
firmware/pocket-pet-nucleo/ Bring-up project, NUCLEO-L432KC
firmware/pocket-pet-board/ Custom board project
docs/ Schematic PDF, renders, BOMRequires STM32CubeIDE. Import the project with "Copy projects into workspace" unchecked so the IDE edits the repo in place; keep the workspace outside the repository. The .ioc file is the source of truth for pin configuration — if you change pins, regenerate from CubeMX rather than editing generated code. Any value in generated code outside the USER CODE markers — task stack sizes, heap size, peripheral settings — must be changed in the .ioc, not the source. Hand edits there are overwritten on the next regeneration without warning.
Sprite data is not included in this repository. The bunny animations are from VegaJourney's 32x32 Bunny pack (licence permits use but not redistribution), converted to 1-bit bitmaps.
To build: copy firmware/common/pet_sprites.h.template to pet_sprites.h
and supply your own sprite arrays. Any 1-bit bitmap works —
ssd1306_draw_bitmap() takes row-major, MSB-first data, which is what
image2cpp produces with horizontal
orientation selected.
MIT
| Qty | Value | Footprint | References |
|---|---|---|---|
| 6 | 100nF | Capacitor_SMD:C_0805_2012Metric_Pad1.18x1.45mm_HandSolder | C5, C6, C7, C8, C9, C11 |
| 3 | 4.7uF | Capacitor_SMD:C_0805_2012Metric_Pad1.18x1.45mm_HandSolder | C1, C2, C10 |
| 3 | 5.1k | Resistor_SMD:R_0805_2012Metric_Pad1.20x1.40mm_HandSolder | R1, R2, R3 |
| 2 | 0R | Resistor_SMD:R_0805_2012Metric_Pad1.20x1.40mm_HandSolder | R5, R6 |
| 2 | 4.7k | Resistor_SMD:R_0805_2012Metric_Pad1.20x1.40mm_HandSolder | R7, R8 |
| 2 | SW_Push | Button_Switch_THT:SW_PUSH_6mm | SW2, SW3 |
| 1 | 10k | Resistor_SMD:R_0805_2012Metric_Pad1.20x1.40mm_HandSolder | R4 |
| 1 | 1uF | Capacitor_SMD:C_0805_2012Metric_Pad1.18x1.45mm_HandSolder | C3 |
| 1 | 2.2uF | Capacitor_SMD:C_0805_2012Metric_Pad1.18x1.45mm_HandSolder | C4 |
| 1 | Conn_01x02 | Connector_JST:JST_PH_S2B-PH-K_1x02_P2.00mm_Horizontal | J2 |
| 1 | Conn_01x06 | Connector_PinHeader_2.54mm:PinHeader_1x06_P2.54mm_Vertical | J3 |
| 1 | Conn_01x07 | Connector_PinHeader_2.54mm:PinHeader_1x07_P2.54mm_Vertical | J4 |
| 1 | Conn_01x11 | Connector_PinHeader_2.54mm:PinHeader_1x11_P2.54mm_Vertical | J6 |
| 1 | LOGO | pocket-pet:swirl | G*** |
| 1 | LOGO | pocket-pet:swansmall | G*** |
| 1 | MCP1700x-330xxTT | Package_TO_SOT_SMD:SOT-23 | U2 |
| 1 | MCP73831-2-OT | Package_TO_SOT_SMD:SOT-23-5 | U1 |
| 1 | STM32L433CCTx | Package_QFP:LQFP-48_7x7mm_P0.5mm | U3 |
| 1 | SW_SPDT | pocket-pet:SW_Slide_SS12D00G3_P2.5mm | SW1 |
| 1 | TestPoint | TestPoint:TestPoint_Pad_D1.5mm | TP1 |
| 1 | TestPoint | TestPoint:TestPoint_THTPad_D2.0mm_Drill1.0mm | TP2 |
| 1 | USB_C_Receptacle_USB2.0_16P | Connector_USB:USB_C_Receptacle_HRO_TYPE-C-31-M-12 | J1 |
The 34 most common of 38 parts.

joeycastillo/The-Open-Book
For details on how to build, test and use Open Book, I've made documentation available here.


hackclub/OnBoard
💡 Join 1,000 teenagers and make your first PCB with a $100 grant!


Ardumower/ardumower
Develop an open source robotic lawn mower (HW+SW reference platform)

CRImier/MyKiCad
My KiCad boards. Can't be bothered uploading individually anymore, so here you go.


It measures 55 × 70 mm and has 2 copper layers, 1.6 mm thick.
38 parts. The full list of its parts is on this page, with links to each part's symbol and footprint where PCBKit's library has them.
From the kondovskii/pocket-pet repository on GitHub, at the commit this page was made from: the board is hardware/pocket-pet/pocket-pet.kicad_pcb and its schematic hardware/panel-back/panel-back.kicad_sch. PCBKit opens the board in the browser, with nothing to install.
Its repository states no licence, so its author keeps all rights: ask kondovskii before reusing the design.