Skip to main content
Version: FILS English

Desk Pet

A small interactive robot that lives on your desk and reacts to the world around it, built on Raspberry Pi Pico (RP2040) and written in Rust.

info

Author: Ion Mihai-Codruț
GitHub Project Link: https://github.com/UPB-PMRust-Students/fils-project-2026-justiMpuls3

Description

Desk Pet is a 2WD robot designed to sit on a desk and behave like a simple companion. It has five moods managed by a Finite State Machine: it wanders around when idle, gets excited when you touch it, reacts to RFID cards that act as "food", turns sad if you ignore it for too long, and can be driven manually over Bluetooth. The HC-SR04 ultrasonic sensor keeps it from falling off the edge of the desk.

Everything runs asynchronously using the Embassy framework — each sensor and actuator has its own task, and they communicate through shared channels without blocking each other.

Motivation

I wanted to build something that felt alive, not just functional. The idea of a robot with moods that change based on real input, touch, proximity, RFID; made the project interesting to design. Using Rust for embedded also appealed to me because the compiler forces you to think carefully about every resource you use, which is a good habit for hardware projects.

Architecture

The system is built around a central FSM task. Sensor tasks detect events and send them over Embassy channels to the FSM, which decides the next state and commands the actuator tasks.

┌──────────────────────────────────────────────────────────┐
│ Raspberry Pi Pico (RP2040) │
│ │
│ [touch_task] ──┐ │
│ [rfid_task] ──┤──► [fsm_task] ──► [motor_task] │
│ [ultrasonic_task] ──┤ ├──► [lcd_task] │
│ [bluetooth_task] ──┘ └──► [buzzer_task] │
└──────────────────────────────────────────────────────────┘

Power Architecture

The batteries feed the L298N motor driver directly. The LM2596 buck converter steps the battery voltage down to a stable 5V, which goes into the Pico's VSYS pin (Pin 39). The Pico's internal regulator then produces 3.3V on Pin 36, which powers all sensors (RFID, touch, LCD). This keeps the noisy motor power completely separated from the logic supply.

[4xAA Batteries ~6V]
|
|-------------------------------------------> L298N motor power (direct)
|
+--> [LM2596 Buck Converter -> 5V] --> Pico VSYS (Pin 39)
|
Pico 3V3_OUT (Pin 36)
|
.------------+------------.
MFRC522 LCD TTP223

FSM State Table

StateEntry TriggerMotorsLCDBuzzer
IdleStartup / timeout resetSlow wander"Hello! :)"Silent
HappyTouch sensor (GP22)Spin in place"Yay! ^_^"Happy tone
FedRFID tag detected (GP10-14)Short dance"Yum! Nom nom"Jingle
SadNo input for 30 sSlow drift"Feed me... :("Low tone
RemoteControlBT command via GP0/1Follows commands"Remote mode"Silent

Schematic

Schematic

Hardware

Week 4-10

Prototip Hardware Desk Pet Figure 1: Current hardware prototype of the Desk Pet robot. All electrical connections have been completed and tested successfully. Remaining work focuses on cable organization and final component placement on the chassis.

Bill of Materials

#ComponentQtyShopPrice
1Raspberry Pi Pico (RP2040)1Optimus Digital~23 RON
22WD Robot Car Chassis + DC motors1Optimus Digital~45 RON
3L298N Dual Motor Driver1Optimus Digital~23 RON
4MFRC522 RFID Module + 2 tags1Optimus Digital~23 RON
5TTP223 Capacitive Touch Sensor1Optimus Digital~2 RON
6HC-SR04 Ultrasonic Sensor1Optimus Digital~4 RON
7LCD 1602 with I2C backpack1Optimus Digital~16 RON
8Passie Buzzer1Optimus Digital~1 RON
9HC-05 Bluetooth Module1Optimus Digital~35 RON
10LM2596 Buck Converter1Optimus Digital~13 RON
11Breadboard 400p1Optimus Digital~13 RON
Total: ~198 RON

Pin Mapping

GPIOPico PinPeripheralSignalNotes
GP01HC-05 BluetoothUART0 TXConnects to HC-05 RX
GP12HC-05 BluetoothUART0 RXConnects to HC-05 TX
GP24L298NIN1Motor A direction
GP35L298NIN2Motor A direction
GP46L298NIN3Motor B direction
GP57L298NIN4Motor B direction
GP69L298NENBMotor B speed (PWM)
GP811LCD 1602I2C0 SDAData line
GP912LCD 1602I2C0 SCLClock line
GP1014MFRC522SPI1 SCKSPI clock
GP1115MFRC522SPI1 MOSISPI data out
GP1216MFRC522SPI1 MISOSPI data in
GP1317MFRC522SPI1 CSChip select
GP1419MFRC522RSTReset pin
GP1621L298NENAMotor A speed (PWM)
GP1925BuzzerPWM outPWM SLICE1 B
GP2229TTP223GPIO inTouch signal
GP2732HC-SR04ECHO inVia 1kΩ/2kΩ voltage divider (5V→3.3V)
GP2834HC-SR04TRIG outTrigger pulse
VSYS39LM2596Power in5V from buck converter
3V3_OUT36SensorsPower out3.3V to RFID, LCD, Touch
GND3, 38All modulesCommon groundShared with LM2596 GND
note

The HC-SR04 ECHO pin outputs 5V logic but the RP2040 GPIO is 3.3V tolerant only. A voltage divider (1kΩ in series + 2kΩ to GND) brings the signal down to ~3.3V before it enters GP27.

Software

The firmware is written in Rust using the Embassy async executor on thumbv6m-none-eabi (Cortex-M0+).

Results

  • Firmware compiles with cargo build --release targeting thumbv6m-none-eabi.
  • All five FSM states work correctly on hardware.
  • LCD shows the right message for each state in real time.
  • RFID tag detection is reliable and correctly triggers the Fed state.
  • HC-SR04 stops the robot before it reaches the desk edge (~10 cm threshold).
  • TTP223 touch response is immediate with no debounce issues.
  • HC-05 Bluetooth responds to W/A/S/D/X serial commands from a phone terminal.
  • Motor PWM control gives smooth speed transitions.

Resources

  1. Embassy RP2040 Documentation
  2. Raspberry Pi Pico Datasheet
  3. RP2040 Technical Reference Manual
  4. mfrc522 crate on crates.io
  5. hd44780-driver crate on crates.io

Inspiration

  1. Takway AI - Mobile Robot Platform
  2. Zeroth W1 - Home Robot with Camera Eyes (DesignBoom)