ESP ZeroCode AI · Community

Wiring diagram for 桌宠

桌宠

请基于乐鑫 Mosaico 制作面向10~12岁孩子的「口袋异星宠物」。画风奇趣可爱,不设死亡或惩罚。 一、属性与作息 首次领养可起名。饱食度、精力、亲密度范围0~100,初始均为60,显示成长进度。 清醒时每分钟饱食度减5、精力减3;睡眠时每分钟精力加15、饱食度减2;亲密度不自动下降,属性不越界。 二、网页互动与硬件逐项对应 1. 光敏感知睡觉还是醒来。 2. 轻摇设备:清醒时轻摇自动开始10秒运动挑战。 3. 实体按键:清醒时按一次饱食度加10,上限100;达到90后拒绝继续喂食并提示吃饱。按键消抖,间隔3秒,运动中也可喂食,显示咀嚼表情。 4. 拖动抚摸→触摸安抚:清醒且非运动时,持续触摸2秒,亲密度加5,显示眯眼、蹭手;每10秒最多生效一次,再次触发需先松手。 三、成长与保存 成功运动、实际增加饱食度的喂食或增加亲密度的安抚,各计一次照顾。每10次按本轮最多类型变为活力型、圆滚型或黏人型;并列取并列类型最 近发生的一项。清空本轮计数,保留图鉴,形态无优劣。 他用的是 MOS,增加了一个套装的拓展板。这个拓展板上面有共鸣电阻、按键,还有 LED 灯

ESP32-S31 display
Download the firmware Open-source licences Fork it in the studio

What it does

Manual

Device Type
A pocket alien pet (电子宠物 / virtual pet) for 10–12 year olds, built on an ESP-Mosaico board with the ESP-Mosaico 多功能交互模块 (multi-function interaction module, board type 0x16) in its right-hand module slot. A small, strange-but-friendly alien lives on the 480x480 round touch screen: fed with the board's A button, petted with a single tap, and played with in a 15-second tapping game started by two quick taps, where every tap fills its energy bar by one point. It notices the room going dark and curls up to sleep, its energy refilling overnight. Companionship with no failure state: nothing dies, nothing is punished, there is no score to lose and no randomness anywhere. The toy is entirely offline — no Wi-Fi, no cloud, no phone app, no pairing — so the screen, one button and a light sensor are the whole interface.

Hardware
chip: esp32s31 — board: esp-mosaico (ESP-Mosaico V1.2: 16 MB SPI NOR + 1 Gbit SPI NAND, 16 MB in-package PSRAM, 480x480 CO5300 QSPI screen with CST9220 touch, BMI270 IMU, ES8311 codec + NS4150B amp + speaker + mic, vibration motor, 65 mAh Li-ion cell with BQ27220 fuel gauge, TP4057 charger, SAM8108 power switch with POWER button, A/function button, BOOT button, USB-C) — expansion: ESP-Mosaico 多功能交互模块 in the RIGHT slot (H1, EEPROM 0x51, mounted rotated 180°). It carries a GL5506 photoresistor on ADC, an AS312 PIR, an AO3400A-driven IR emitter, 6x WS2812 RGB LEDs (4 on top, 2 under the key pads) and two pads that can be a mechanical key or a capacitive touch pad. This product uses the photoresistor and the six RGB LEDs. — gpios: GPIO46: GL5506 photoresistor analog output from the interaction module (right slot), sampled as ADC and normalised to a 0–100 brightness value. — GPIO38: WS2812 data line for the module's 6 RGB LEDs (right slot). Requires a 10 kΩ pull-up to 3V3 so this boot-strapping pad sits at its normal-boot level before the LED driver takes over. — GPIO7: On-board A (function) button, active low — feeds, and a 5-second hold is the factory reset. Nothing else. — GPIO61: On-board BOOT button — no product function; holding it at power-up still enters ROM download mode. — GPIO57: POWER switch request line, driven by the board's power block (untouched by product code). — GPIO60: VCC_3V3 gate, low = on. The board's power-control device holds it low so the screen and the module's 3.3 V supply stay alive; the module gets no power otherwise. — GPIO8: Vibration motor (high = on) — the per-tap tick and the round-end buzz. — GPIO6: Touch interrupt from the CST9220. — GPIO2: IMU / magnetometer interrupt line — unused; shaking and the ball game are both gone. — unusable_module_pins: The module's key pads (GPIO11 / GPIO10 in the right slot), its PIR (GPIO5) and its IR emitter (GPIO47) are deliberately not claimed: GPIO10, GPIO11 and GPIO5 are marked reserved (flash/system) by the platform's ESP32-S31 chip model, and the IR emitter has no role in a pet toy. The product therefore uses the board's own A button. — wiring: Nothing to solder: the interaction module clicks into the right 2×10P slot (rotated 180° relative to the left slot) and the board reads its EEPROM at 0x51. The only modification is a 10 kΩ resistor from GPIO38 to 3V3 to hold the WS2812 data line at the safe boot level. Every other part (screen, touch, speaker, vibration motor, fuel gauge, buttons) is already on the Mosaico board. In the LEFT slot the module's photoresistor would land on GPIO53 and its LEDs on GPIO15 — camera/flash pins — so a left-slot module would lose light sensing and the mood LEDs entirely.

Inputs
kind: touch — label: Tap gestures — the one way the screen is used — hardware: CST9220 capacitive panel covering the whole face of the device. — behavior: Taps are counted in bursts: taps less than 300 ms apart belong to the same burst, and the count is decided 400 ms after the last tap. The count has a different meaning depending on whether the pet is awake or asleep. AWAKE and on the pet's own screen: one tap = petting; two quick taps = start the game; three taps = nothing more than a blink (it is already awake). ASLEEP: one tap and two taps do nothing at all; three quick taps wake the pet. Because the count must be decided, a single-tap petting takes effect about 0.4 s after the tap — the cost of telling one tap from two. INSIDE THE GAME the counting rules are suspended: every tap is a scoring tap (see the next entry), and on the result card a single tap returns to the pet. · kind: touch — label: The game — tapping for energy — hardware: The same panel, read as individual taps rather than as a position or a drag. — behavior: While a round runs, each accepted tap adds +1 energy (clamped at 100) and nothing else: an accepted tap is followed by a 250 ms cooldown, so at most 4 taps per second can score, and any tap arriving inside that cooldown is ignored completely — no score, no sound, no visual. There is no target to hit, no ball, no paddle and no miss: the child just taps the pet as fast as the cooldown allows and watches the energy bar climb. The round ends when its 15 seconds are up. · kind: touch — label: Petting — one tap outside the game — hardware: The same panel; the whole face counts. — behavior: While awake and on the pet's own screen, one tap gives +5 affection with the squint-and-nuzzle animation, a purr-like warble and a soft buzz. At most one petting counts per 10 seconds, and a tap during the cooldown is simply ignored (no refusal face). A single tap never gives energy — the '+1' belongs to the game only. · kind: touch — label: Wake by hand — three taps — hardware: The same panel. — behavior: Three quick taps while asleep wake the pet with a stretch and a greeting chirp. In a dark room the light sensor would put it straight back, so a hand-wake suspends light-driven sleep for 60 seconds; after that, if the room is still dark, the pet settles back to sleep on its own. · kind: touch — label: Challenge — two quick taps — hardware: The same panel. — behavior: Two quick taps while awake and idle start the game: the pet counts 3-2-1 and its body switches into the game state — excited, bouncing, arms up, eyes wide — with the three attribute bars visible so the child can watch energy climb. Two taps while asleep do nothing. Two taps while a round or the result card is showing are ignored. · kind: button — label: A button — feed and factory reset — hardware: The board's own A/function button on GPIO7, active low, 30 ms debounce. — behavior: A short press feeds: +10 satiety, capped at 100, refused at 90 or above with an 'I'm full' face and a hoot, and a 3-second cooldown after each accepted feed. A 5-second hold is the factory reset, with the module LEDs going solid blue as feedback. It does nothing during a game round — feeding is unavailable there, and no tap of any button scores anything. · kind: button — label: BOOT button — hardware: The board's own BOOT button on GPIO61, active low. — behavior: No product function at all, in or out of the game. Holding it during power-up still enters the ROM download mode, which is harmless. · kind: light — label: Room light — GL5506 on GPIO46 — hardware: Photoresistor on the interaction module, read as an analog value on GPIO46 and normalised to 0–100 brightness. — behavior: Decides awake or asleep. Bright for 8 consecutive seconds → the pet wakes with a stretch and a greeting chirp. Dark for 8 consecutive seconds → it curls up asleep with a descending yawn. Hysteresis plus the 8-second confirmation keeps a passing shadow from flipping the state. Thresholds are gentle and low, so a dimly lit bedroom counts as dark. A round interrupted by the light going dark ends there, and the energy already earned is kept.

Outputs
kind: display — label: 480x480 touch screen — the pet and the tapping game — hardware: CO5300 QSPI panel, always on, backlight at a fixed comfortable brightness. — behavior: PET SCREEN: the alien drawn large and centred in a hand-drawn, strange-but-cute style with a slow idle breath. Expressions: idle (curious blinking, antennae swaying), eating (chewing, cheeks bulging), petting (eyes squeezed shut, leaning into the hand), full (turned away, mouth shut), hungry (satiety < 20), sleepy (energy < 20), sleeping (curled up, slow breathing, floating z's), low-battery yawn, growth (a two-second burst of light and a new silhouette). GAME: the pet's body switches into its game state — excited, bouncing, arms up, eyes wide — with the energy bar along the bottom filling one point per accepted tap. Each accepted tap pops a '+1' at the exact point the finger touched, which floats upward about a tenth of the screen and fades out over roughly half a second; the pet grins and bounces a little harder with each one. When the 15 seconds are up a result card shows the energy gained and a 'one more time?' face, then returns to the pet after a few seconds. The three attribute bars sit in a strip along the bottom, the pet's name at the top, a ring under the bars shows progress to the next form, and the collection badges line up in the top corner. The screen never blanks, day or night. · kind: led — label: Mood lighting — 6x WS2812 RGB — hardware: The interaction module's six addressable RGB LEDs on GPIO38, brightness limited to about 20% so the toy never glares in a dark room. — behavior: Calm green while awake and content; deep breathing blue while asleep; while a round runs the six LEDs flare gold and light up one after another with the taps, so the row pulses faster the faster the child taps; orange pulse on an accepted feed; a brief white flash on petting; red only when satiety is near 0 or the battery is below 15%; all six solid blue during a factory-reset hold. Always an echo of the screen, never the only source of information. · kind: speaker — label: Chirps — hardware: ES8311 into the NS4150B amp and the board speaker; fixed low volume suitable for a child's toy, no mute exposed. — behavior: Short synthesized chirps: a rising two-note greeting on waking, a soft crunching loop while eating, a bright short 'pop' on each accepted tap (rising in pitch as a streak builds), a short ending jingle when the round finishes, a purr-like warble while petted, a low hoot when refused for being full, a descending yawn on falling asleep, and a fanfare on growing into a new form. · kind: haptics — label: Ticks and buzzes — hardware: On-board vibration motor on GPIO8. — behavior: A tiny 60 ms tick on each accepted tap, a longer soft buzz (~400 ms) when the round ends, and a short soft buzz while petted. Never an alarm. · kind: led — label: Charge indicator — hardware: The board's TP4057 charge LED. — behavior: Orange while charging, white when full — hardware only, nothing in firmware.

Commissioning
method: on-device and offline — nothing to pair, nothing to install, no account — instructions: Slide the interaction module into the right-hand 2×10P slot (rotated 180°, LEDs facing the same way as the screen) and switch on with POWER. First boot shows a welcome animation, then a grid of eight preset alien names (咕噜, 喵星, 豆豆, 泡泡, 闪闪, 团子, 呱呱, 皮皮). The child taps one; it is written to NVS immediately and the pet hatches. Short hint bubbles then appear once each for the three skills: tap once to pet, tap twice to start the tapping game, and tap three times to wake the pet. In a dark room the pet hatches asleep and three taps wake it. The module is optional: without it the pet feeds, plays and grows, it just never notices the light and shows no mood colour.

Business Logic
powerOnBehavior: Load the saved state from NVS (name, three attributes, care counters, collection). If no name is stored, run adoption. Read the photoresistor for a second: bright → wake with a stretch and a greeting, dark → start asleep. Then run the 1 Hz tick that drives everything. — automationRules: Attribute tick at 1 Hz. Awake: satiety −5 and energy −3 per minute (applied in sixtieths so the bars glide). Asleep: satiety −2 and energy +15 per minute. Affection never changes by itself. Everything is clamped to 0–100. The tick keeps running during a round, so a long session awake still costs energy. · Light → state: 8 consecutive seconds of bright wakes the pet, 8 consecutive seconds of dark puts it to sleep, with separate on/off thresholds (hysteresis). A hand-wake (three taps) vetoes the dark rule for 60 seconds. Falling asleep ends any running round or result card. · Tap gestures on the pet's own screen: bursts of taps separated by under 300 ms; the count is decided 400 ms after the last tap. Awake: 1 → pet, 2 → start the game, 3 → ignored. Asleep: 1 and 2 → ignored, 3 → wake by hand. On the result card a tap only dismisses it. · Petting: awake, on the pet's screen, +5 affection, at most once per 10 seconds, extra taps inside the cooldown silently ignored. · Feed: accepted when awake and satiety ≤ 89; adds exactly 10; 3-second cooldown after an accepted press; presses inside the cooldown are ignored rather than refused. A press during a game round does nothing at all. · The game: two taps while awake and idle start a round with a 3-2-1 countdown. From the first moment of play the tap-counting rules are suspended and every tap is scored: an accepted tap adds exactly +1 energy (clamped at 100), spawns the floating '+1' at the touch point, plays the pop and the vibration tick, and starts a 250 ms cooldown during which further taps are discarded entirely. The round runs 15 seconds and ends on the clock, with no miss counter and no early failure. Worst case a very fast child scores roughly 60 taps in a round, i.e. +60 energy before the 100 cap — the clock is the only brake. · Round result: the energy gained and a 'one more time?' face stay on screen for about 4 seconds, or until any tap or button press returns to the pet. A round counts as care only if at least one tap scored, so rapid double-taps just to farm growth cannot work; it counts exactly once however many taps landed. · Care counting and growth: an accepted feed, an accepted petting and a finished round each increment a counter (feeding → round form, play → energetic form, petting → clingy form). When the three counters sum to 10 the form of the highest counter is taken (ties go to the type that happened most recently), the form joins the collection if new, a growth animation plays and all counters reset. Growing never changes attributes. · Persistence: dirty-flagged flush to NVS at most once a minute, plus immediately on any accepted care action, on a form change, on adoption and before a low-battery shutdown. Atomic writes, so a power cut costs at most the last minute of decay. · Nothing integrates over elapsed wall-clock time: a device left switched off does not catch up on decay. — dayToDayOperation: The pet sits on a desk or the edge of a bed, mostly on USB. By day it is awake, blinking and slowly getting hungry; a press of the A button feeds it, and if it is nearly full it turns away and hoots. A single tap on its face makes it squeeze its eyes shut and purr. When the child wants to play, two quick taps put it into its game mood and a slow countdown starts a 15-second tapping round: each tap pops a '+1' under the finger, ticks the motor, pushes the energy bar up a point and makes the LEDs pulse gold. When the time is up the pet shows the energy it earned, and the round adds one step of growth progress. As the room darkens in the evening the LEDs sink to deep blue and the pet curls up, refilling energy overnight while satiety drifts down; three taps wake it if the child wants to play after dark. Every ten acts of care it grows — a badge joins the row in the corner — and the count begins again, so the thing to collect is all three forms rather than staying alive.

Factory Reset
trigger: Hold the A button for 5 seconds. The six module LEDs go solid blue as soon as the hold is recognised and return to normal if released early, so it cancels cleanly. The USB console command factory_reset does the same. — effect: Erases the name, the three attributes, the care counters and the collection, then reboots into adoption so the child can start a new pet. Nothing else to erase: no credentials, no keys, no personal data.

Failure Modes
scenario: Battery reaches 15% — behavior: The pet yawns and the module LEDs turn red; the state is flushed to NVS immediately. A round in progress is cut short and its energy kept. · scenario: Battery critically low (~5%) — behavior: The state is saved and the toy plays a sleepy goodnight animation before cutting out, rather than brown-out resetting mid-write. On the next charge it returns exactly as it was, with no offline decay. · scenario: Interaction module missing or its EEPROM not detected — behavior: The pet runs fully awake with no light sensing and a default LED colour; feeding, the tapping game, petting, growth and sound all still work — only the day/night cycle and mood colour are gone. · scenario: Photoresistor covered or permanently dark — behavior: The pet sleeps endlessly, energy pins at 100 and satiety grinds to 0 where it looks hungry but is never harmed. Three taps wake it for 60 seconds of play, repeatable at will. · scenario: Photoresistor permanently bright — behavior: The pet never sleeps, energy sinks to 0 and it naps on the spot with a 'so sleepy' face. Feeding and the game still work. · scenario: Touch panel dead or unresponsive — behavior: The pet stays in whatever state the light puts it in and cannot be petted or started into a game; feeding, sleeping and growing still happen through the A button, so it is not bricked. · scenario: Child taps much faster than 4 per second — behavior: Only the taps at least 250 ms apart score; the rest are discarded with no sound, no '+1' and no fraction of a point — the round simply pays a maximum of 4 energy per second. · scenario: Energy is already 100 when a round starts — behavior: Taps still pop their '+1' and still tick, but the bar does not move; the round still counts as the round it is and the child sees a full bar. · scenario: Child mashes the screen on the pet screen — behavior: A burst of many taps resolves to three taps — wake if asleep, nothing if awake — so mashing never starts a game and never pets several times at once. · scenario: Speaker or codec failure — behavior: The toy runs silently; every piece of feedback also exists on screen (the '+1', the bar) and in the LEDs and the motor tick. · scenario: Occasional boot failure caused by the WS2812 data line — behavior: Fixed by the 10 kΩ pull-up on GPIO38 to 3V3. If it still refuses to start, hold BOOT while pressing POWER to force download mode; the saved pet is untouched. · scenario: Power lost mid-save — behavior: Atomic NVS writes return the last complete state — at worst the last minute of decay is replayed, never the pet's identity. · scenario: Firmware hang or frozen screen — behavior: POWER off and on. If it recurs, hold the A button 5 s for a factory reset or use the USB console. No reachable state is unrecoverable, because nothing can die.

Power Management
batteryPowered: true — battery: 3.7 V / 65 mAh Li-ion cell on the base board, charged over USB-C (65 mA charge current), percentage from the on-board BQ27220 fuel gauge; the board's TP4057 charge LED turns orange then white when full. — sleepMode: none — by design the screen, its backlight and the mood LEDs stay on at all times, so the toy draws current whenever it is switched on and a full cell lasts well under an hour — note: The pet is expected to live plugged into USB; the cell exists so it can be carried to another room for a while. Because it never deep-sleeps there is no wake-source configuration and no stale-state-on-wake problem, but battery run time is short — a deliberate trade for an always-lit pet.

Custom Behavior
tappingIsTheWholeGame: The game is nothing but tapping: no falling objects, no catcher, no paddle, no aim, no miss counter, and no button input. Two taps start a timed round, and inside it every tap that clears the 250 ms cooldown converts directly into one point of energy with a floating '+1' at the fingertip. The spec deliberately carries no geometry — a rebuild must not resurrect balls, a paddle or a score to chase. — tapCountVsTapping: Two different tap regimes exist and must not bleed into each other. On the pet's own screen taps are counted in bursts (1 = pet, 2 = start game, 3 = wake) and a single tap gives affection. Inside a round the burst counter is switched off and every individual tap is a scoring tap. A single tap on the pet screen still gives no energy, and a tap inside the round gives no affection. — deterministicRewards: There is no randomness anywhere: feeding is +10, petting is +5, and each accepted game tap is exactly +1 energy. The child can predict every gain. — noFailurePhilosophy: No death, no illness, no penalty and no score that can be lost. Attributes bottom out at 0 with a visibly sad-but-recoverable pet and always climb back. A round is just fifteen seconds of fun that pays what it pays; every form is equally good and the collection is a keepsake, not a leaderboard. — growthMechanic: Whichever care type happens most over each set of ten actions decides the next form — energetic (play: finished rounds), round (feeding), clingy (petting). A tie goes to the type that happened most recently. Counters clear at the start of each round; badges never clear except on a factory reset. — offlineByDesign: No Wi-Fi stack, no cloud, no accounts, no pairing and no data leaves the device — an explicit choice so the toy works anywhere and asks nothing of a parent's phone. — clockFree: The product never uses the time of day: no timezone and no RTC. The day/night cycle comes entirely from the photoresistor and decay is counted in ticks while the device is running.

Published 23 Nov 2026
Firmware and source licensed Apache-2.0; photos and text CC-BY-4.0.
The firmware includes open-source software — open-source licences and notices; some components may be used only with Espressif chips.
Built with ESP ZeroCode AI — describe a device, get production firmware.
Terms of Service · Privacy Policy