- Add 'fix' command to diagnose CEC connection issues - Add detailed troubleshooting section for common errors - Fix handles errno=16 (device busy) by checking processes and trying sudo - Document solutions for CEC permission and connection issues Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
112 lines
3.0 KiB
Markdown
112 lines
3.0 KiB
Markdown
# CEC Control for Raspberry Pi 4
|
|
|
|
Control HDMI-connected devices (TVs, receivers, etc.) from your Raspberry Pi 4 using CEC (Consumer Electronics Control).
|
|
|
|
## Installation
|
|
|
|
1. Install the required CEC utilities:
|
|
```bash
|
|
sudo apt-get update
|
|
sudo apt-get install cec-utils
|
|
```
|
|
|
|
2. Make the script executable (already done):
|
|
```bash
|
|
chmod +x cec-control.sh
|
|
```
|
|
|
|
## Usage
|
|
|
|
```bash
|
|
./cec-control.sh <command> [options]
|
|
```
|
|
|
|
## Available Commands
|
|
|
|
| Command | Description | Example |
|
|
|---------|-------------|---------|
|
|
| `tv-on` | Turn on the TV | `./cec-control.sh tv-on` |
|
|
| `tv-off` | Turn off the TV | `./cec-control.sh tv-off` |
|
|
| `standby` | Put TV in standby | `./cec-control.sh standby` |
|
|
| `wake` | Wake TV from standby | `./cec-control.sh wake` |
|
|
| `vol-up` | Increase volume | `./cec-control.sh vol-up` |
|
|
| `vol-down` | Decrease volume | `./cec-control.sh vol-down` |
|
|
| `mute` | Mute audio | `./cec-control.sh mute` |
|
|
| `input <port>` | Switch HDMI input (0-15) | `./cec-control.sh input 1` |
|
|
| `source <device>` | Switch source device (0-15) | `./cec-control.sh source 2` |
|
|
| `scan` | Scan for CEC devices | `./cec-control.sh scan` |
|
|
| `status` | Show CEC adapter status | `./cec-control.sh status` |
|
|
| `info` | Show TV information | `./cec-control.sh info` |
|
|
| `fix` | Troubleshoot connection issues | `./cec-control.sh fix` |
|
|
| `raw <command>` | Send raw CEC command | `./cec-control.sh raw 4f:82:10:00` |
|
|
| `help` | Show help message | `./cec-control.sh help` |
|
|
|
|
## Quick Start
|
|
|
|
1. Connect your Raspberry Pi to your TV via HDMI
|
|
2. Enable CEC on your TV (usually in settings)
|
|
3. Test the connection:
|
|
```bash
|
|
./cec-control.sh scan
|
|
```
|
|
4. Turn on your TV:
|
|
```bash
|
|
./cec-control.sh tv-on
|
|
```
|
|
|
|
## Troubleshooting
|
|
|
|
### Common Issues
|
|
|
|
**ioctl CEC_S_MODE failed - errno=16 (Device or resource busy)**
|
|
|
|
This error means something else is using the CEC device. Try these solutions:
|
|
|
|
1. Run the built-in fix command:
|
|
```bash
|
|
./cec-control.sh fix
|
|
```
|
|
|
|
2. Kill any existing CEC processes:
|
|
```bash
|
|
sudo killall cec-client
|
|
```
|
|
|
|
3. Check what's using the device:
|
|
```bash
|
|
sudo lsof /dev/cec0
|
|
```
|
|
|
|
4. Try running with sudo:
|
|
```bash
|
|
sudo ./cec-control.sh scan
|
|
```
|
|
|
|
5. If using Kodi or LibreELEC, CEC may be enabled in the application. Disable it or stop the application first.
|
|
|
|
**CEC not working**
|
|
- Make sure CEC is enabled in your TV settings (often called "HDMI Control", "CEC Control", or branded names like "Bravia Link", "Anynet+", etc.)
|
|
- Try a different HDMI port on your TV
|
|
- Check that the HDMI cable is properly connected
|
|
|
|
**Permission denied**
|
|
- Add your user to the `video` group: `sudo usermod -aG video $USER`
|
|
- Then log out and back in
|
|
- Or run with `sudo`
|
|
|
|
**Device not found**
|
|
- Check if `/dev/cec0` exists: `ls -l /dev/cec0`
|
|
- Ensure `cec-utils` is installed
|
|
- Try rebooting the Pi
|
|
|
|
## Advanced Usage
|
|
|
|
You can integrate this script into your own automation:
|
|
```bash
|
|
# Turn on TV and switch to input 1
|
|
./cec-control.sh tv-on && sleep 2 && ./cec-control.sh input 1
|
|
|
|
# Use in cron jobs or other scripts
|
|
@reboot /path/to/cec-control.sh tv-on
|
|
```
|