0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ラズベリーパイでクレーンを作ってみたよ その1

0
Last updated at Posted at 2026-05-06

ラズベリーパイでクレーンを作ってみました。完成形はこちら。
https://youtube.com/shorts/rZB0FlMQwcg?feature=share

以下のページを参考にさせていただきました。感謝。
https://www.petitmonte.com/robot/make_crane_game.html

作成手順

その1(この回)

1.ラズベリーパイにT字型コネクタを差す。ランプで動作確認

2.モータードライバに電源、モーターを配線して、モーターが回転することを確認

その2

3.滑車を組み立てる

4.アームを組み立てる

その3

5.アームを動かす

6. 動作を確認

7. 用意する部材

1.ラズベリーパイにT字型コネクタを差す。ランプで動作確認

まずはラズベリーパイの動作確認を行う。以下のように配線して、ランプが光るかどうかを確認
image.png

image.png

ソースコード

from gpiozero import LED
import time
led = LED(18)
led.on()
time.sleep(5)
led.off()

ランプが光ったことで、ちゃんとラズベリーパイがT字型コネクタを通じて電気信号を流せることを確認できた。

image.png

2.モータードライバに電源、モーターを配線して、モーターが回転することを確認

image.png

image.png

image.png

正回転

import RPi.GPIO as GPIO
import time
# GPIO番号で指定(BCMモード)
GPIO.setmode(GPIO.BCM)
IN1 = 17
IN2 = 18
# 出力設定
GPIO.setup(IN1, GPIO.OUT)
GPIO.setup(IN2, GPIO.OUT)
def forward():
    GPIO.output(IN2, GPIO.HIGH)
    GPIO.output(IN1, GPIO.LOW)
    print("モーター回転")
def stop():
    GPIO.output(IN1, GPIO.LOW)
    GPIO.output(IN2, GPIO.LOW)
    print("停止")
try:
    forward()
    time.sleep(0.05)  # 3秒正回転
    stop()
finally:
    GPIO.cleanup()

逆回転

import RPi.GPIO as GPIO
import time
# GPIO番号で指定(BCMモード)
GPIO.setmode(GPIO.BCM)
IN1 = 17
IN2 = 18
# 出力設定
GPIO.setup(IN1, GPIO.OUT)
GPIO.setup(IN2, GPIO.OUT)
def forward():
    GPIO.output(IN1, GPIO.HIGH)
    GPIO.output(IN2, GPIO.LOW)
    print("モーター正回転")
def stop():
    GPIO.output(IN1, GPIO.LOW)
    GPIO.output(IN2, GPIO.LOW)
    print("停止")
try:
    forward()
    time.sleep(0.1)  # 3秒正回転
    stop()
finally:
    GPIO.cleanup()

その2へ
https://qiita.com/sguash07/items/42c5ad14b92c9205c444

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?