picocalc-review
This skill should be used when the user asks to "review PicoCalc code", "check my PicoCalc app", "validate PicoCalc script", "audit embedded code", "is this PicoCalc code correct", or wants feedback on MicroPython code targeting the PicoCalc device. Activate when reviewing any Python code that imports picocalc, uses PicoDisplay, PicoKeyboard, or targets the 320x320 handheld.
Review PicoCalc Code
Evaluate MicroPython code for the PicoCalc embedded platform. Check for correctness, safety, and pattern compliance.
Review Checklist
Memory Management
-
gc.collect()called at app start inmain() - Large data uses
bytearraynotlistwhere possible - Key buffer pre-allocated as
bytearray(10), not created per-read - No unbounded list/dict growth in main loop
- Modules cleaned up if loaded dynamically
Hardware Safety
- I2C reads wrapped in try/except OSError
- PWM audio stopped (
duty_u16(0)) in cleanup/exit path - Display cleared (
fill(0); show()) on exit - No keyboard reset (
_REG_RST) during initialization - SPI buses not conflicting (display=SPI1, SD=SPI0)
- PWM objects created once, not recreated in loops
Application Structure
- Class-based with
__init__,run,handle_input,draw - ESC key (
b'\x1b\x1b') exit path back to menu -
main()function as standalone entry point -
if __name__ == "__main__": main()guard - Top-level try/except with
sys.print_exception(e) - Uses
utime(nottime) for ticks_ms/ticks_diff/sleep_ms - Uses
urandom(notrandom) for random numbers
Display Correctness
- Colors are 4-bit grayscale (0-15), not RGB
-
show()called after drawing operations - Coordinates within 0-319 range
- Text accounts for 6x8 font (53 cols x 40 rows)
- Avoids
fill(0)in draw loop — use static+animate, erase-move-draw, or overwrite patterns instead -
beginDraw()+fill(0)only for one-time initial draws, NOT every frame - Does NOT call
fill(0); show()on exit — just returns to menu - Static screens drawn once, only animated elements update per frame
Input Handling
- Reads via
picocalc.terminal.readinto(key_buffer) - Checks
if not count: returnfor no-key case - Matches escape sequences as
bytesnot individual chars - Handles
Nonereturn from readinto
Network Safety (if applicable)
- WiFi/BLE operations wrapped in try/except
- Interface reset pattern for recovery
- Credentials not hardcoded (use wifi.json)
- gc.collect() before/after network operations
Common Mistakes
| Mistake | Correct |
|---|---|
import time; time.ticks_ms() | import utime; utime.ticks_ms() |
import random; random.randint() | import urandom; urandom.randint() |
RGB color 0xFF0000 | Grayscale 0-15 |
Drawing without show() | Always call show() after draw cycle |
time.sleep(1) blocking loop | utime.ticks_diff() for timing |
Creating bytearray(10) per frame | Pre-allocate in __init__ |
Additional Resources
- references/memory-checklist.md - Memory patterns
- references/hardware-safety.md - Hardware safety with examples
- references/app-structure-checklist.md - Pattern compliance