Servo pan-tilt mount ・ 舵机云台
I2C ハブ経由で 2 つのサーボを制御し、カメラを上下左右に動かします。
この構成をエディタで開く・編集する →| 部品 | 役割 | ポート | リンク・価格 |
|---|---|---|---|
| M5Stack Core2 | Controller | grove_i2c, grove_analog, grove_uart, mbus | official page — $46.9 |
| Unit PaHub2 | I2C Hub (1→6) | grove_i2c | official page — $7.95 |
| Unit 8Servos | Pan Servo | grove_i2c | official page — $6.95 |
| Unit 8Servos | Tilt Servo | grove_i2c | official page — $6.95 |
M5Stack Core2と2つのサーボユニット(Unit 8Servos)を使って、カメラのパン・チルトを制御するシステムです。I2Cハブ(Unit PaHub2)を介してCore2から2つのサーボユニットを制御し、それぞれにサーボモーターを接続してカメラの向きを変えます。
# M5Stack Core2 + PaHub2 + 2x Unit 8Servos (camera pan/tilt)
# Wiring: Core2 Port.A (red) -> PaHub2 IN
# PaHub2 OUT1 -> Servo Unit 1 (pan)
# PaHub2 OUT2 -> Servo Unit 2 (tilt)
# Servos connected to CH1 of each Unit 8Servos
import time
from machine import Pin, I2C
# I2C setup on Core2 Port.A (sda=21, scl=22)
i2c = I2C(0, sda=Pin(21), scl=Pin(22), freq=400000)
# TCA9548A address (PaHub2)
TCA_ADDR = 0x70
# Unit 8Servos I2C address (default 0x40)
SERVO_ADDR = 0x40
def select_channel(channel):
"""Select PaHub2 channel (0-5)."""
i2c.writeto(TCA_ADDR, bytes([1 << channel]))
def set_servo_angle(channel, angle):
"""Set servo angle (0-180) on the currently selected Unit 8Servos, channel 1."""
# Convert angle to pulse width (500-2500 us)
pulse = 500 + (angle / 180) * 2000
# Unit 8Servos command format: [channel, pulse_low, pulse_high]
# pulse in 0.1us steps, so multiply by 10
pulse_ticks = int(pulse * 10)
low_byte = pulse_ticks & 0xFF
high_byte = (pulse_ticks >> 8) & 0xFF
# Channel 0 corresponds to CH1 on the unit
i2c.writeto(SERVO_ADDR, bytes([0, low_byte, high_byte]))
# Initialize: set all channels to 90 degrees (neutral)
for ch in range(2):
select_channel(ch)
set_servo_angle(0, 90)
time.sleep(1)
# Test sequence: pan 0->180, tilt 90->0
while True:
# Pan servo (channel 0 on PaHub2)
select_channel(0)
for angle in range(0, 181, 10):
set_servo_angle(0, angle)
time.sleep_ms(50)
time.sleep(1)
# Tilt servo (channel 1 on PaHub2)
select_channel(1)
for angle in range(90, -1, -10):
set_servo_angle(0, angle)
time.sleep_ms(50)
time.sleep(1)
この作り方はAIが構成から生成したものです(未検証)。通電前に配線とコードをご確認ください。
この構成はAIが実在するM5Stack部品から設計し、ポート互換をサーバで検証したものです。編集・共有できます。
エディタで開く →UnitKit は M5Stack® 製品向けの非公式ツール。作りたいものを書くと、部品リストと配線図が出ます。