---
name: unihiker-k10-arduino
description: Use when programming Unihiker K10 board with Arduino/C++, uploading code, or accessing K10 Arduino APIs (screen, sensors, RGB, audio)
---

# Unihiker K10 - Arduino

## Overview

CLI toolkit for Unihiker K10 board Arduino programming. **Core principle:** Follow reference docs exactly—no improvisation.

## When to Use

- Uploading Arduino/C++ code to K10
- Looking up K10 Arduino APIs (screen, canvas, sensors, RGB, audio)
- Port detection or connectivity issues

## Commands

| Command | Description |
|---------|-------------|
| `k10-arduino upload <file.ino>` | Compile & upload Arduino sketch |
| `k10-arduino ports` | List serial ports |
| `k10-arduino doctor` | Environment diagnostic |

## Coding

### Basic Template

```cpp
#include "unihiker_k10.h"

UNIHIKER_K10 k10;

void setup() {
  k10.begin();
  k10.initScreen(2);           // Screen direction: 0-3
  k10.creatCanvas();           // Create canvas object
  k10.setScreenBackground(0x000000);  // Background color (black)

  // Canvas drawing methods (use k10.canvas->)
  k10.canvas->canvasSetLineWidth(3);
  k10.canvas->canvasLine(0, 0, 100, 100, 0xFFFF00);
  k10.canvas->canvasCircle(80, 80, 40, 0x00FF00, 0x0000FF, false);
  k10.canvas->updateCanvas();   // Update display
}

void loop() {
  // Your code here
}
```

**Important:**
- **File structure**: `.ino` file must be in a directory with the same name (e.g., `star/star.ino`)
- **Canvas API**: All canvas methods use `k10.canvas->`, not `k10.`
- **FQBN**: `UNIHIKER:esp32:k10`
- **Reference**: [`references/arduino-api.md`](references/arduino-api.md)

## Common Issues

| Issue | Solution |
|-------|----------|
| **Can't open sketch: main file missing** | Put `.ino` file in a directory with the same name (e.g., `star/star.ino`) |
| **Platform 'unihiker:k10' not found** | Use correct FQBN: `UNIHIKER:esp32:k10` |
| **Class has no member named 'canvasLine'** | Canvas methods use `k10.canvas->`, not `k10.` |
| Port not found | `k10-arduino ports` or hold BOOT while connecting |
| Screen flicker | Partial fill, not full clear |

## Files

```
unihiker-k10-arduino/
├── SKILL.md                 # This file
└── references/            # Arduino API docs
    ├── arduino-api.md     # Arduino C++ API reference
    └── arduino-examples.md # Arduino code examples
```

**Manual usage without CLI:**
```bash
# Upload Arduino
bash path/to/unihiker-k10-arduino/scripts/upload-arduino.sh sketch.ino /dev/cu.usbmodem2201 UNIHIKER:esp32:k10
```

## Quick Development Workflow

```bash
# 1. Create Arduino sketch in project directory
your_project/
└── your_sketch/
    └── your_sketch.ino

# 2. Upload sketch
k10-arduino upload your_project/your_sketch/your_sketch.ino
```

## Key Features

**Screen & Canvas:**
- Screen initialization and direction control
- Canvas drawing: text, lines, circles, rectangles, images
- Background color management

**Sensors:**
- Buttons A/B (pressed callback and polling)
- Accelerometer (X, Y, Z axes)
- Temperature & humidity (AHT20)
- Light sensor (ALS)
- Pedometer (step counting)
- Microphone (recording and playback)

**RGB LED Control:**
- Individual LED control (0, 1, 2)
- All LEDs control (-1)
- Brightness control (0-9)

**Audio:**
- Buzzer control (playTone, playMusic)
- Microphone recording to TF card
- Audio playback from TF card

**Examples Available:**

1. **Display Examples** (`arduino-examples.md`)
   - Background color cycling
   - Drawing points, lines, circles, rectangles
   - QR code generation
   - Electronic photo album

2. **Sensor Examples**
   - Button A/B control (interrupt and polling)
   - Accelerometer ball movement
   - Pedometer display
   - All sensors display on screen

3. **RGB LED Examples**
   - Rainbow cycle (7 colors)
   - Brightness breathing effect

4. **Audio Examples**
   - Built-in music playback
   - Audio recording to TF card
   - Audio playback from TF card

5. **GPIO Examples**
   - Digital input/output on P0/P1
   - Analog input/PWM output on P0

6. **Combined Examples**
   - Sensor data display (temperature, humidity, light, acceleration, steps)
   - TTS (Text-to-Speech) examples
