A comprehensive, production-ready example demonstrating proper button and touch screen interaction on the Arduino Nesso N1 using the M5Unified library.
- ✅ Proper I2C GPIO expander access - Buttons read correctly via M5Unified (not direct GPIO)
- ✅ Capacitive touch screen - FT6336U touch controller with coordinate tracking
- ✅ Buzzer feedback - Audio confirmation for all interactions
- ✅ Visual display - Real-time counter display with improved readability
- Three counters - BTN A, BTN B, and TOUCH press counts
- Large, readable fonts - Optimized text sizes for 1.14" display
- Reset functionality - Press both buttons simultaneously to reset all counters
- Audio feedback - Distinct beep tones for each button/touch type
- Serial logging - Detailed event output for debugging
- 60 FPS display - Smooth visual updates
- Proper debouncing - Clean state management with static variables
- Touch coordinates - X/Y position logging to serial monitor
- Hardware abstraction - Demonstrates correct M5Unified usage
- Arduino Nesso N1 (ESP32-C6)
- Built-in 1.14" IPS LCD display (240×135 pixels)
- Built-in capacitive touchscreen (FT6336U)
- Built-in I2C GPIO expanders (buttons at 0x43/0x44)
- Built-in buzzer (GPIO 11)
All components are integrated into the Nesso N1!
Install via Arduino Library Manager or arduino-cli:
# M5Unified Library (required)
arduino-cli lib install "M5Unified"arduino-cli core install esp32:esp32# Clone repository
git clone https://github.com/rogerguess/nesso-n1.git
cd nesso-n1/button_test_m5unified
# Compile and upload
arduino-cli compile --fqbn esp32:esp32:arduino_nesso_n1 .
arduino-cli upload -p /dev/cu.usbmodem1101 --fqbn esp32:esp32:arduino_nesso_n1 .- Open
button_test_m5unified.inoin Arduino IDE - Select Tools → Board → ESP32 Arduino → Arduino Nesso N1
- Select Tools → Port → [Your Nesso N1 Port]
- Click Upload button
┌─────────────────────────────────┐
│ BUTTON & TOUCH │
├─────────────────────────────────┤
│ BTN A BTN B TOUCH │
├─────────────────────────────────┤
│ 0 0 0 │
│ │
│ Press both to reset │
└─────────────────────────────────┘
| Action | Result |
|---|---|
| Press Button A (left) | Green counter increments, 1000 Hz beep |
| Press Button B (right) | Magenta counter increments, 1200 Hz beep |
| Touch screen anywhere | Cyan counter increments, 1400 Hz beep |
| Press both buttons together | All counters reset to 0, 1500 Hz beep |
Connect at 115200 baud to see detailed logging:
========================================
Nesso N1 BUTTON TEST
Using M5Unified Library
========================================
✅ M5Unified initialized
✅ I2C GPIO expanders ready
✅ Buttons are now accessible
========================================
Ready! Press buttons or touch screen!
========================================
╔════════════════════════════════════╗
║ *** BUTTON A PRESSED *** ║
╚════════════════════════════════════╝
Press count: 1
╔════════════════════════════════════╗
║ *** SCREEN TOUCHED! *** ║
╚════════════════════════════════════╝
Touch position: X=120, Y=67
Touch count: 1
- KEY1 (Button A) and KEY2 (Button B) are controlled via I2C GPIO expander at addresses 0x43/0x44
- Using
pinMode()anddigitalRead()on GPIO 0 or GPIO 9 will NOT work - M5Unified library provides the correct abstraction layer
Correct approach:
M5.begin(); // Initialize I2C expanders
M5.update(); // Read button states from I2C
if (M5.BtnA.wasPressed()) { ... }Incorrect approach (won't work):
pinMode(0, INPUT_PULLUP);
digitalRead(0); // This reads ESP32 GPIO 0, not the button!- Controller: FT6336U capacitive touch via I2C (address 0x38)
- Resolution: Full display resolution (240×135)
- Detection:
M5.Display.getTouch(&tp)returns touch point - Coordinates:
tp.x(0-240),tp.y(0-135)
Symptom: Pressing buttons does nothing
Solution:
- Ensure M5Unified library is installed
- Verify
M5.begin()is called insetup() - Verify
M5.update()is called inloop() - Check Serial Monitor for initialization messages
Symptom: Screen touches not detected
Solution:
- Ensure you're touching the screen, not the bezel
- Try pressing firmer (capacitive touch requires contact)
- Check Serial Monitor for touch coordinates
- Verify M5GFX/M5Unified display initialization
Symptom: Text is hard to read
Solution: This sketch already uses optimized font sizes:
- Labels: size 2 (larger than default)
- Counters: size 3 (maximum readable)
- Instructions: size 2
If still too small, consider increasing text size in code (may require layout adjustments).
button_test_m5unified.ino
├── setup()
│ ├── M5.begin() // Initialize I2C expanders
│ ├── M5.Display.init() // Initialize display
│ ├── drawUI() // Draw static interface
│ └── ledcAttach() // Setup buzzer
│
├── loop()
│ ├── M5.update() // Read button states from I2C
│ ├── Button A handling // M5.BtnA.wasPressed()
│ ├── Button B handling // M5.BtnB.wasPressed()
│ ├── Both buttons reset // M5.BtnA.isPressed() && M5.BtnB.isPressed()
│ └── Touch detection // M5.Display.getTouch()
│
├── drawUI() // Initial screen layout
├── updateDisplay() // Update counter values
└── playTone() // Buzzer feedback
Edit frequencies in loop():
playTone(1000, 50); // Button A: 1000 Hz, 50ms
playTone(1200, 50); // Button B: 1200 Hz, 50ms
playTone(1400, 50); // Touch: 1400 Hz, 50ms
playTone(1500, 100); // Reset: 1500 Hz, 100msEdit in drawUI() and updateDisplay():
M5.Display.setTextSize(2); // Labels (BTN A, BTN B, TOUCH)
M5.Display.setTextSize(3); // Counter numbersModify color constants (RGB565 format):
TFT_CYAN // Title
TFT_YELLOW // Labels
TFT_GREEN // Button A counter
TFT_MAGENTA // Button B counter
TFT_CYAN // Touch counter
TFT_WHITE // InstructionsTested on Arduino Nesso N1 (ESP32-C6 @ 160MHz):
| Metric | Value |
|---|---|
| Memory usage | 18KB RAM (5%) |
| Flash usage | 424KB (13%) |
| Display update | ~10ms per frame |
| Button latency | <20ms |
| Touch latency | <30ms |
This project is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License (CC BY-NC-SA 4.0).
You are free to:
- Share and redistribute
- Modify and build upon this work
Under these terms:
- Attribution - Credit Roger Guess and link to this repository
- NonCommercial - No commercial use without permission
- ShareAlike - Derivatives must use the same license
See LICENSE file for full terms.
For commercial licensing, contact via GitHub.
Author: Roger Guess Repository: https://github.com/rogerguess/nesso-n1 Hardware: Arduino Nesso N1 (Arduino + M5Stack collaboration) Libraries: M5Unified (M5Stack)
Contributions welcome! Please:
- Fork this repository
- Create a feature branch
- Test thoroughly on actual Nesso N1 hardware
- Submit a pull request with clear description
- Issues: https://github.com/rogerguess/nesso-n1/issues
- Discussions: https://github.com/rogerguess/nesso-n1/discussions
⭐ If this helped you, please star the repository!
