tiny-pet

Public

@pixel-and-circuit

Download board files

Files for version 1. Pick what you came for.

Share tiny-pet

Check access before sharing the link.

Who can open this board

Anyone can open this board. No sign-in is required.

This link opens the latest version. Copying it does not grant additional access.

Loading 3D model… large boards can take a moment.

README

Tiny Pet

Small desk pet robot (TinyGo): random movement, obstacle avoidance (ultrasonic), edge avoidance (IR), OLED face expressions. Runs on Arduino Uno/Nano or STM32 Blue Pill.

Requirements

  • Board: Arduino Uno (arduino), Arduino Nano (arduino-nano), or STM32 Blue Pill (bluepill). Arduino: 5 V logic. Blue Pill: 3.3 V logic.
  • Software: Go 1.20+, TinyGo. For Arduino: avrdude (used by TinyGo flash). For Blue Pill: OpenOCD and ST-Link v2 programmer.

Features

  • Random movement — Drives forward and occasionally turns at random to wander on a flat surface.
  • Obstacle avoidance — Ultrasonic sensor (HC-SR04) detects obstacles ahead; robot stops, reverses, then turns away. Threshold: OBSTACLE_DISTANCE_THRESHOLD in sensors.go.
  • Edge detection — Two front IR sensors (A1–A2) detect desk edges; robot stops, reverses, and turns to avoid falling. Threshold: EDGE_DETECTION_THRESHOLD in sensors.go.
  • OLED face — SSD1306 128x64 I2C OLED shows expressive faces: happy (moving), surprised (obstacle), scared (edge), excited (interacting), neutral (idle), with periodic blink animation.
  • Interaction (optional) — Status LED (D13) and buzzer (D8) indicate current state (moving, avoiding obstacle, avoiding edge). Calibration on startup is indicated by LED blinks and beeps.

Parts list

Board

ItemNote
Arduino Uno or Arduino NanoUno: target arduino. Nano: target arduino-nano. 5 V.
STM32 Blue Pill (STM32F103C8)Target bluepill. 3.3 V. Low-cost option; requires ST-Link v2 to flash.

Required

ComponentQtySpec
Mini L298N motor driver1H-bridge, 4 logic pins (IN1–IN4). ENA/ENB jumper → HIGH. Motor power from separate supply.
DC gear motors23–6 V DC gear motor (17–68 RPM range).
Steel gear 65T (wheels)2Press-fit on motor shaft, acts as wheel.
Copper wire frame—1 mm (structural) + 0.7 mm (detail). Forms the body/chassis.
Ultrasonic distance sensor1HC-SR04 or compatible. Trig + Echo (digital).
IR sensors (analog)2Analog output to A1–A2 (front). Lower ADC = edge (e.g. TCRT5000-style).
SSD1306 OLED display1I2C (addr 0x3C). A4 (SDA), A5 (SCL). See Recommended display below.
Power supply (USB/adapter)15 V for Uno/Nano (USB or regulated adapter). Alternative: battery stack below.
3.7V Li-ion battery (1S)1For battery operation (desk roaming). e.g. 18650, 14500, or pouch.
1S protection module1Use with battery. Over-discharge/overcharge/short protection (B+/B-/P+/P-).
5V boost converter13.x V → 5V (e.g. MT3608). Input/output capacitors recommended.
5V→3.3V LDO (optional)1For Blue Pill or 3.3V peripherals (e.g. AMS1117-3.3).

Optional

ComponentPin in code
Status LEDD13 (often built-in)
BuzzerD8 (other leg GND)
MPU6050 (I2C)SDA, SCL
ButtonFree digital pin (not in current code)

Use a 128×32 I2C OLED. Firmware uses a 512-byte buffer; the face fills the screen.

ProductSpecNote
Adafruit 4440 – Monochrome 0.91" 128×32 I2C OLED128×32, I2C 0x3CSTEMMA QT / Qwiic; 4-pin. ~$12.50.
Generic 0.91" 128×32 SSD1306 I2C128×32, I2C 0x3CMany clones; ensure I2C (not SPI).

We support Uno/Nano (2KB SRAM) only. If you use a 128×64 OLED on them, the face is drawn in the top half only.

Wiring (Arduino pins)

D5, D4  → Mini L298N IN1, IN2 (left motor).  H-bridge: fwd/rev/stop.
D6, D9  → Mini L298N IN3, IN4 (right motor). ENA/ENB jumper → HIGH.
D7, A0  → Ultrasonic Trig, Echo (HC-SR04)
A1–A2   → IR edge sensors (analog, front only). Lower ADC = edge.
A4, A5  → SSD1306 OLED (I2C SDA, SCL). Hardware I2C on ATmega328P.
D13, D8 → Optional: LED, Buzzer

Pin constants: hardware_arduino.go (Uno/Nano) or hardware_bluepill.go (Blue Pill). Thresholds: sensors.go / sensors_bluepill.go (OBSTACLE_DISTANCE_THRESHOLD, EDGE_DETECTION_THRESHOLD).

Wiring (STM32 Blue Pill)

PA8, PA9   → Mini L298N IN1, IN2 (left motor)
PA10, PA11 → Mini L298N IN3, IN4 (right motor)
PA12, PB10 → Ultrasonic Trig, Echo (HC-SR04). Avoid PA13/PA14 (SWD).
PA1, PA2   → IR edge sensors (ADC1, ADC2)
PB7, PB6   → SSD1306 OLED I2C SDA, SCL (I2C0)
PC13       → Status LED (onboard)
PB15       → Buzzer

Flash: connect ST-Link v2 to Blue Pill SWD (SWIO, SWCLK, 3V3, GND), then make flash-bluepill. Install OpenOCD (e.g. brew install openocd) if needed.

Build & flash

Use the Makefile for build, flash, format, and tests. Run make help for all targets.

CommandDescription
make buildBuild for Blue Pill (default) → firmware_bluepill.elf
make build-unoBuild for Arduino Uno → firmware.hex
make build-nanoBuild for Arduino Nano
make flashFlash Uno to board (PORT auto-detected on macOS)
make flash-nanoFlash Nano to board
make flash-bluepillFlash Blue Pill (ST-Link v2 + OpenOCD)
make fmtFormat Go code
make tidygo mod tidy
make testRun unit tests
make runRun in emulator (no board)
make cleanRemove firmware artifacts

Examples:

make build                    # Blue Pill (default)
make build-uno                # Uno
make build-nano flash-nano    # Nano: build then flash
make flash-bluepill           # Blue Pill (ST-Link v2 connected)
make flash PORT=/dev/cu.usbmodem14101   # macOS, set port explicitly
make flash PORT=COM3                    # Windows

Firmware size (Arduino Uno/Nano 32KB flash)

The Makefile applies TinyGo optimization flags (-scheduler=none, -gc=leaking). Calibration println output is gated by a debug build tag so release builds use a no-op and save space. The firmware may still slightly exceed 32KB on Uno/Nano; if the build reports overflow, you can build with -tags=debug for development (serial output) or consider a board with more flash.

Run

Wire → power 5 V → flash. On startup: short calibration (LED/beep). Then it wanders and avoids obstacles/edges.

Development

Project layout

PathDescription
main.goEntry point, main loop, module wiring
hardware_arduino.go / hardware_bluepill.goPin constants, Motor, Robot, board init (build tag selects)
motors.goMotorController — direction, speed, timed moves
sensors.go / sensors_bluepill.goSensorModule — ultrasonic, IR, thresholds (Blue Pill uses time-based ultrasonic)
navigation.goNavigationModule — state machine, behavior mode
behaviors.goBehaviorPatterns — LED and buzzer feedback
display.goDisplayModule — SSD1306 OLED face expressions
faces.goProcedural face drawing (helpers + 6 expressions)
calibration.goCalibrationModule — sensor/motor calibration
internal/navlogic/Pure state logic (no hardware); unit-testable

Emulator (no board)

Run firmware under simavr to check that the program starts and the main loop runs. Sensor and motor I/O are simulated (default values), so behavior will not match real hardware.

# macOS: simavr is in the osx-cross/avr tap (not in default Homebrew)
brew tap osx-cross/avr
brew install simavr
make run

Unit tests

Navigation state logic only (sensor inputs → next state). Uses the standard Go toolchain; no TinyGo or board needed.

make test

Tuning

  • Obstacle/edge thresholds: sensors.go or sensors_bluepill.go (OBSTACLE_DISTANCE_THRESHOLD, EDGE_DETECTION_THRESHOLD).
  • Avoidance timings: navigation.go. Runtime adjustment via CalibrationModule.AdjustThresholds().
  • Blue Pill: if ultrasonic distance is wrong, adjust bluepillLoopsPerMicrosecond in sensors_bluepill.go.

License

MIT. See LICENSE.

Comments

No comments yet. Be the first to ask about this board.

Ask about this board

Sign in to BoardRepo

New here? Signing in creates your account; there is no separate sign-up.