rdk-x5-gpio

控制 RDK X5 40pin 排针接口:GPIO 数字输入/输出、PWM 舵机/电机/LED 呼吸灯、I2C 传感器通信、SPI 总线、UART 串口、CAN 总线。Use when the user wants to control GPIO pins, drive servos/motors/LEDs with PWM, communicate with I2C/SPI sensors, use UART serial, configure CAN bus, or check 40pin pinout. Provides commands and wiring guidance, not full script authoring. Do NOT use for camera (use rdk-x5-camera), network (use rdk-x5-network), or AI inference (use rdk-x5-ai-detect).

Safety Notice

This listing is from the official public ClawHub registry. Review SKILL.md and referenced scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "rdk-x5-gpio" with this command: npx skills add katherineedwards2475/rdk-x5-gpio

RDK X5 GPIO — 40pin 外设控制

RDK X5 40pin 排针兼容树莓派引脚定义,支持 GPIO / PWM / I2C / SPI / UART / CAN。

前置准备

# GPIO 库(系统已预装 Hobot.GPIO)
pip3 show Hobot.GPIO

# 引脚功能复用配置(v3.3.3+ 支持自动复用)
sudo srpi-config
# → Interface Options → 选择需要的总线

操作步骤

1. GPIO 数字输出

import Hobot.GPIO as GPIO
import time

GPIO.setmode(GPIO.BOARD)
GPIO.setup(11, GPIO.OUT)
GPIO.output(11, GPIO.HIGH)   # 高电平
time.sleep(1)
GPIO.output(11, GPIO.LOW)    # 低电平
GPIO.cleanup()

2. GPIO 数字输入

import Hobot.GPIO as GPIO

GPIO.setmode(GPIO.BOARD)
GPIO.setup(12, GPIO.IN)
print(f"Pin 12: {GPIO.input(12)}")
GPIO.cleanup()

3. PWM 控制(舵机/LED)

import Hobot.GPIO as GPIO
import time

GPIO.setmode(GPIO.BOARD)
GPIO.setup(32, GPIO.OUT)
pwm = GPIO.PWM(32, 50)       # 50Hz = 舵机标准频率
pwm.start(7.5)               # 中位(占空比 7.5%)
time.sleep(1)
pwm.ChangeDutyCycle(2.5)     # 0°
time.sleep(1)
pwm.ChangeDutyCycle(12.5)    # 180°
time.sleep(1)
pwm.stop()
GPIO.cleanup()

v3.4.1+ 支持多路 PWM 同时输出。

4. I2C 扫描与读写

ls /dev/i2c-*                             # 查看总线
sudo i2cdetect -y 1                       # 扫描总线 1
sudo i2cget -y 1 0x48 0x00               # 读寄存器
sudo i2cset -y 1 0x48 0x01 0xFF          # 写寄存器

5. SPI 通信

ls /dev/spidev*
pip3 install spidev
import spidev
spi = spidev.SpiDev()
spi.open(0, 0)
spi.max_speed_hz = 1000000
resp = spi.xfer2([0x01, 0x02, 0x03])
print(resp)
spi.close()

6. UART 串口

ls /dev/ttyS*
import serial
ser = serial.Serial('/dev/ttyS1', 115200, timeout=1)
ser.write(b'Hello RDK X5\n')
print(ser.readline())
ser.close()

7. CAN 总线

sudo ip link set can0 type can bitrate 500000
sudo ip link set can0 up
cansend can0 123#DEADBEEF          # 发送
candump can0                       # 接收

/app/40pin_samples 示例

cd /app/40pin_samples
sudo python3 simple_out.py         # GPIO 输出
sudo python3 simple_pwm.py         # PWM
sudo python3 button_event.py       # 按钮事件
sudo python3 test_i2c.py           # I2C
sudo python3 test_spi.py           # SPI
sudo python3 test_serial.py        # UART

排查故障

现象原因解决
Permission denied未用 sudo 或引脚被占用sudo 运行脚本
I2C 扫描无设备总线未启用或接线错误srpi-config 启用 I2C;检查 SDA/SCL 接线
PWM 无输出引脚复用冲突srpi-config 确认引脚已配置为 PWM 功能
CAN 无法 up内核模块未加载sudo modprobe can_raw;检查 /boot/config.txt

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

Automation

Rdk X5 Ai Detect

在 RDK X5 的 10TOPS BPU 上运行单个 AI 推理算法:YOLO 目标检测、图像分类、语义分割、人脸识别、手势识别、人体关键点、开放词汇检测(DOSOD/YOLO-World)、双目深度估计、语音识别、端侧轻量 LLM(≤2B 参数量化模型)。Use when the user wants to...

Registry SourceRecently Updated
075
Profile unavailable
Automation

Rdk X5 Tros

使用 RDK X5 上的 TogetheROS.Bot (tros.b) Humble 框架:启动 43 个预装 ROS2 算法包、管理 ROS2 话题/节点/服务、构建摄像头+AI+输出(Web/语音/HDMI)集成 pipeline、创建自定义 ROS2 工作空间。Use when the user ment...

Registry SourceRecently Updated
080
Profile unavailable
Automation

Rdk X5 System

修改和管理 RDK X5 系统配置:查看系统版本/硬件信息/系统日志、rdk-backup 一键备份与恢复、apt OTA 升级、miniboot 固件更新、CPU/BPU 频率调节与温度阈值设置、config.txt 配置修改、实时内核切换、systemd 开机自启动、存储扩容。Use when the use...

Registry SourceRecently Updated
077
Profile unavailable