Prompt file imported from anewcomer/d-bag (
.github/prompts/thumby-official-doc.prompt.md). Copyright stays with the author.
Thumby SDK Official Documentation Context
This document provides essential context for AI coding agents developing Thumby games and applications based on the official Thumby SDK documentation.
Thumby Hardware Overview
- Display: 72x40 pixel monochrome OLED screen
- Controls: 6 buttons (4-way D-pad: Up, Down, Left, Right + 2 action buttons: A, B)
- Platform: Tiny keychain-sized gaming device running MicroPython
- Screen Dimensions: width = 72, height = 40 pixels
- Color: Binary (0 = black/off, 1 = white/on)
Development Environment
Thumby Web Code Editor
- URL: https://code.thumby.us/
- Features:
- Live emulation for instant testing
- File management (local and device)
- Built-in sprite editor
- Direct USB upload to device (MicroUSB cable required)
- Browser support: Chrome and Edge only
- Usage: All code is saved locally in browser storage
API Documentation
- Main Docs: https://thumby.us/API/Get-Started/
- Language: MicroPython
- Import:
import thumby
Core Thumby API Reference
API Submodules (v1.7+)
For optimized performance, import only needed submodules:
thumbyGraphics- Graphics and display functionsthumbyHardware- Hardware integrationthumbyButton- Button input handlingthumbyAudio- Sound and audiothumbyLink- Multiplayer link functionalitythumbySaves- Save/load game data
Display & Graphics
Display Properties
thumby.display.width # 72 pixels
thumby.display.height # 40 pixels
Core Display Functions
thumby.display.update() # Refresh screen - call once per frame
thumby.display.fill(color) # Fill entire display with color (0 or 1)
thumby.display.setPixel(x, y, color) # Set individual pixel
thumby.display.getPixel(x, y) # Get pixel state
thumby.display.drawText(string, x, y, color) # Draw text at position
thumby.display.drawLine(x1, y1, x2, y2, color) # Draw line
thumby.display.drawRectangle(x, y, w, h, color) # Draw rectangle outline
thumby.display.drawFilledRectangle(x, y, w, h, color) # Draw filled rectangle
thumby.display.blit(bitmapData, x, y, w, h, key, mirrorX, mirrorY) # Copy bitmap to screen
thumby.display.setFPS(fps) # Set target frame rate (typically 30)
Best Practice: Frame Updates
Always batch all drawing operations, then call thumby.display.update() once per frame for efficiency.
Sprites
Sprite Constructor
sprite = thumby.Sprite(width, height, bitmapData, x, y, key, mirrorX, mirrorY)
Parameters:
width,height: Sprite dimensions in pixelsbitmapData: Bytearray containing bitmap datax,y: Initial screen positionkey: Transparency key (0 = black is transparent, 1 = white is transparent, -1 = no transparency)mirrorX,mirrorY: Boolean flags for horizontal/vertical flipping
Sprite Methods
sprite.getFrame() # Get current frame index
sprite.setFrame(frame) # Set frame for animation
sprite.x, sprite.y # Position properties
Optimization Tips:
- Keep sprites small (8x8 or 16x16 typical)
- Use sprite sheets for animations
- Manage frame progression manually in game loop
Button Input
Button Check Methods
thumby.buttonA.pressed() # True while button held down
thumby.buttonB.pressed()
thumby.buttonU.pressed() # Up
thumby.buttonD.pressed() # Down
thumby.buttonL.pressed() # Left
thumby.buttonR.pressed() # Right
thumby.buttonA.justPressed() # True only once per press (for menus/triggers)
thumby.buttonB.justPressed()
# ... same for all buttons
Composite Input Functions
thumby.inputPressed() # Returns True if any button pressed
thumby.dpadPressed() # Returns True if any D-pad button pressed
thumby.actionPressed() # Returns True if A or B pressed
Usage Patterns:
- Use
.pressed()for continuous actions (movement, holding) - Use
.justPressed()for single-trigger actions (menu selection, jump)
Audio
Audio Functions
thumby.audio.play(frequency, duration) # Play tone (non-blocking)
thumby.audio.playBlocking(frequency, duration) # Play tone (blocking)
thumby.audio.stop() # Stop current audio
Limitations:
- Simple tone generation only
- Keep audio short to maintain responsiveness
- Use sparingly due to hardware constraints
Save Data
Save Data API
thumby.saveData.setName("GameName") # Set unique name for save file
thumby.saveData.setItem("key", value) # Store value (string/number/list/tuple)
thumby.saveData.getItem("key") # Retrieve value
thumby.saveData.hasItem("key") # Check if key exists
thumby.saveData.save() # Commit changes to persistent storage
thumby.saveData.delItem("key") # Delete item
Save File Location: /Saves/<GameName>/persistent.json
Example Pattern:
thumby.saveData.setName("HighScore")
highScore = 0
if thumby.saveData.hasItem("highscore"):
highScore = int(thumby.saveData.getItem("highscore"))
# After game ends
if newScore > highScore:
thumby.saveData.setItem("highscore", newScore)
thumby.saveData.save()
Multiplayer Link
The Thumby Link cable enables device-to-device communication:
thumby.link.send(data) # Send data to connected Thumby
thumby.link.receive() # Receive data from connected Thumby
File Structure & Organization
Recommended Game Structure
GameName/
├── GameName.py # Main game file (must match folder name)
├── arcade_title_image.png # Title image for Thumby Arcade
├── arcade_title_video.webm # Optional: Title video
└── sprites/ # Optional: sprite data files
Code Organization Best Practices
- Initialization Section: Load saved data, initialize variables
- Main Game Loop:
while True: # 1. Handle input # 2. Update game logic # 3. Draw everything thumby.display.update() - Function Structure: Separate logic for drawing, input, game state
- Naming: Use lowercase for file names and consistent naming
Performance Best Practices
Memory & Speed Optimization
- Import only needed submodules instead of full
thumbymodule - Keep sprites minimal - 8x8 pixels for small objects, up to 16x16 for larger
- Limit per-frame computations - pre-calculate when possible
- Target 30 FPS minimum for responsive gameplay
- Batch drawing operations before calling
display.update() - Use sprite keys for transparency instead of manual pixel checks
Display Optimization
- Screen shows ~12 characters per row of text
- Design concise menus and minimal UI
- Use abbreviated text and symbols
Audio Optimization
- Keep sound effects short (< 500ms typical)
- Avoid audio during intense graphics updates
- Use non-blocking
play()for background effects
Common Game Patterns
Game State Management
STATE_MENU = 0
STATE_PLAYING = 1
STATE_GAMEOVER = 2
gameState = STATE_MENU
while True:
if gameState == STATE_MENU:
# Handle menu input and drawing
elif gameState == STATE_PLAYING:
# Handle gameplay
elif gameState == STATE_GAMEOVER:
# Handle game over screen
thumby.display.update()
Animation Pattern
# Frame counter for animation timing
frameCounter = 0
animationFrame = 0
animationSpeed = 5 # Update every 5 frames
while True:
frameCounter += 1
if frameCounter >= animationSpeed:
frameCounter = 0
animationFrame = (animationFrame + 1) % numFrames
sprite.setFrame(animationFrame)
thumby.display.update()
Collision Detection
def checkCollision(x1, y1, w1, h1, x2, y2, w2, h2):
return (x1 < x2 + w2 and
x1 + w1 > x2 and
y1 < y2 + h2 and
y1 + h1 > y2)
Additional Resources
- Official Documentation: https://thumby.us/
- API Reference: https://thumby.us/API/Get-Started/
- Code Editor: https://code.thumby.us/
- Sample Games: https://github.com/TinyCircuits/TinyCircuits-Thumby-Games
- Making a Game Tutorial: https://thumby.us/Code-Editor/Making-a-game/
- Sprite Documentation: https://thumby.us/API/Sprites/
- Graphics Basics: https://thumby.us/API/Graphics/
- Button Input: https://thumby.us/API/Buttons/
- Save Data: https://thumby.us/API/Save-Files/
Advanced Topics
Thumby BASIC
Alternative to MicroPython for text-based retro programs:
- Documentation: https://github.com/TinyCircuits/TinyCircuits-Thumby-Games/blob/master/ThumbyBasic/README.md
Thumby Color (Next Generation)
For the newer color device with enhanced capabilities:
- Documentation: https://color.thumby.us
- Features 16-bit color, additional buttons, more powerful API
C/C++ Development (Arduino)
Advanced users can use Arduino SDK:
- API Reference: https://thumby.us/CCPP/API-Reference/
- More control but increased complexity
Development Workflow
- Setup: Open Thumby Code Editor in Chrome/Edge
- Code: Write MicroPython game code
- Test: Use built-in emulator for rapid iteration
- Debug: Check display output, button response, save data
- Upload: Connect Thumby via USB and upload to device
- Refine: Test on actual hardware, adjust timing/controls
Key Constraints & Limitations
- Memory: Limited RAM, keep code and assets minimal
- Processing: Simple CPU, avoid complex calculations per frame
- Display: Monochrome only, 72x40 resolution
- Audio: Tone generation only, no complex synthesis
- Storage: Limited, design efficient save data structures
- Power: Battery-powered, optimize for efficiency
Testing Recommendations
- Test in emulator first for rapid iteration
- Test on actual hardware for timing, button feel, display clarity
- Test battery life for longer play sessions
- Test save/load functionality thoroughly
- Test edge cases (button mashing, quick resets, etc.)
This document is based on official Thumby SDK documentation from TinyCircuits. For the most up-to-date information, always refer to the official documentation at https://thumby.us/