Multi-function button interface firmware for ESP32, enabling pets to communicate via button presses with AI-powered intent recognition.
- Multi-function buttons: Detects short/long/very long presses
- RGB LED feedback: Visual confirmation for each interaction
- Audio responses: DFPlayer Mini integration for sound playback
- BLE connectivity: Wireless communication with mobile app
- WiFi support: Optional HTTP API and HomeKit integration
- Local data logging: Persistent storage on ESP32 flash
- Training mode: Special feedback for pet learning sessions
- Power management: Deep sleep support for battery operation
| Component | Specifications | Est. Cost |
|---|---|---|
| ESP32 Dev Board | 240MHz dual-core, WiFi+BLE | $6-10 |
| Arcade Buttons (6x) | 30mm momentary push buttons | $12 |
| RGB LEDs (6x) | WS2812B addressable LEDs | $3 |
| DFPlayer Mini | MP3 audio module | $3 |
| Speaker | 3W 8Ω speaker | $2 |
| MicroSD Card | 1-4GB for audio files | $3 |
| Power Supply | 5V 2A USB or battery | $5 |
| Misc | Wires, resistors, enclosure | $10 |
Total: ~$44-54 (excluding 3D printed enclosure)
ESP32 Device
----- ------
GPIO 4-6, Buttons 1-6 (with pull-up resistors)
18-19,21-22
GPIO 23 WS2812B LED Data In
GPIO 16 DFPlayer TX (connect to DFPlayer RX)
GPIO 17 DFPlayer RX (connect to DFPlayer TX)
GPIO 2 Built-in LED (status indicator)
GPIO 34 Battery voltage monitoring (optional)
3.3V/GND Power distribution
See circuit diagram for complete wiring.
-
Install PlatformIO
# Via pip pip install platformio # Or via VS Code extension # Search "PlatformIO IDE" in VS Code extensions
-
Install USB drivers (if needed)
- CP210x drivers for most ESP32 boards
# Navigate to firmware directory
cd hardware/firmware
# Build firmware
pio run
# Upload to ESP32 (connect via USB)
pio run --target upload
# Monitor serial output
pio device monitor- Power on the ESP32 - You should see startup animation on LEDs
- Open Serial Monitor (115200 baud) to view debug output
- Connect via BLE - Device broadcasts as "PawTalk-Button"
- Test buttons - Press each button to verify functionality
firmware/
├── platformio.ini # PlatformIO configuration
├── include/
│ ├── config.h # Hardware configuration & pin definitions
│ ├── ButtonManager.h # Button input handling
│ ├── LEDController.h # RGB LED control
│ ├── AudioController.h # DFPlayer audio management
│ ├── BLEManager.h # Bluetooth Low Energy
│ └── DataLogger.h # Local data persistence
├── src/
│ ├── main.cpp # Main program entry
│ ├── ButtonManager.cpp # Button implementation
│ ├── LEDController.cpp # LED implementation
│ ├── AudioController.cpp # Audio implementation
│ ├── BLEManager.cpp # BLE implementation
│ └── DataLogger.cpp # Logger implementation
├── test/
│ └── test_main.cpp # Unit tests
└── README.md # This file
Edit include/config.h to customize:
- Pin assignments - Match your wiring
- Button timing - Short/long press thresholds
- LED colors - Customize feedback colors
- Audio volume - DFPlayer volume (0-30)
- BLE settings - Device name, UUIDs
- Power management - Sleep timeouts
// In include/config.h
#define BUTTON_1_PIN 4 // Change to your pin// In include/config.h
#define SHORT_PRESS_MAX_MS 500 // Short press < 500ms
#define LONG_PRESS_MIN_MS 1000 // Long press >= 1000ms| Color | State | RGB Hex |
|---|---|---|
| Off | Idle | 0x000000 |
| Blue | Button pressed | 0x0000FF |
| Green | Confirmed/Success | 0x00FF00 |
| Red | Error | 0xFF0000 |
| Yellow | Learning mode | 0xFFFF00 |
| Orange | Waiting for response | 0xFF8800 |
Place MP3 files on microSD card in root directory:
| File | Number | Description |
|---|---|---|
| 001.mp3 | 1 | Button press sound |
| 002.mp3 | 2 | Confirmation sound |
| 003.mp3 | 3 | Error sound |
| 004.mp3 | 4 | Learning mode sound |
| 005.mp3 | 5 | "Outside" response |
| 006.mp3 | 6 | "Food" response |
| 007.mp3 | 7 | "Water" response |
| 008.mp3 | 8 | "Play" response |
| 009.mp3 | 9 | "Help" response |
Generate custom sounds or use provided samples in audio/samples/.
- Service UUID:
4fafc201-1fb5-459e-8fcc-c5c9c331914b- Button Event Characteristic:
beb5483e-36e1-4688-b7f5-ea07361b26a8(Notify) - Config Characteristic:
1c95d5e3-d8f7-413a-bf3d-7a2e5d7be87e(Read/Write) - Response Characteristic:
d35b1c07-9e5f-4c8a-8c5a-4f7e8d6c9b2a(Write)
- Button Event Characteristic:
{
"event": "button_press",
"buttonId": 0,
"pressType": "short",
"duration": 245,
"timestamp": 1697414400000,
"petProfile": 0
}{
"id": "cmd_123",
"command": "set_training_mode",
"params": {
"enabled": true
}
}# Run unit tests
pio test
# Run specific test
pio test -f test_buttons
# Upload and test on device
pio test --upload-port /dev/cu.usbserial-0001Solution:
- Hold BOOT button on ESP32 while uploading
- Check USB cable (data cable, not charge-only)
- Try different USB port
Solution:
- Verify BLE is enabled in
config.h - Check Serial Monitor for initialization errors
- Reset ESP32 (press EN button)
Solution:
- Verify pin connections match
config.h - Check pull-up resistors (or enable internal pull-up)
- Monitor Serial for button debug messages
Solution:
- Verify DFPlayer connections (TX/RX swapped?)
- Check microSD card is formatted FAT32
- Ensure MP3 files are numbered correctly (001.mp3, etc.)
- Verify speaker connections
Over-the-air firmware updates will be supported in V2:
# Upload via WiFi
pio run --target upload --upload-port pawtalk-button.localMIT License - See LICENSE for details
Questions? See main PawTalk README or open an issue.