質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
SSH

SSH(Secure Shell)は、セキュアチャネルを通してデータを交換するためのネットワークプロトコルです。リモートサーバーへのコマンド実行やファイル転送を行う時に一般的に使用されます。

Raspberry Pi

Raspberry Piは、ラズベリーパイ財団が開発した、名刺サイズのLinuxコンピュータです。 学校で基本的なコンピュータ科学の教育を促進することを意図しています。

Q&A

解決済

1回答

4959閲覧

Raspberrypi3、PCA9685でサーボモータがうまく回りません。

snoopy_robot

総合スコア8

SSH

SSH(Secure Shell)は、セキュアチャネルを通してデータを交換するためのネットワークプロトコルです。リモートサーバーへのコマンド実行やファイル転送を行う時に一般的に使用されます。

Raspberry Pi

Raspberry Piは、ラズベリーパイ財団が開発した、名刺サイズのLinuxコンピュータです。 学校で基本的なコンピュータ科学の教育を促進することを意図しています。

0グッド

0クリップ

投稿2017/12/03 08:42

###前提・実現したいこと
PCA9685でサーボモータを回したいのですがうまくいきません。
Raspberrypi3modelBを使っています。
sshでmacと繋いで実行しています。
PCA9685とRaspberrypiは繋いでいます。
また、i2cはON、

sudo apt-get install python-smbus

も試しましたがダメでした。
https://github.com/adafruit/Adafruit_Python_PureIO.git
https://github.com/adafruit/Adafruit_Python_GPIO.git
も入れてあります。

よろしくお願いします。

###発生している問題・エラーメッセージ

pi@raspberrypi:~/Adafruit_Python_PCA9685/examples $ python simpletest.py Traceback (most recent call last): File "simpletest.py", line 17, in <module> pwm = Adafruit_PCA9685.PCA9685() File "build/bdist.linux-armv7l/egg/Adafruit_PCA9685/PCA9685.py", line 75, in __init__ File "build/bdist.linux-armv7l/egg/Adafruit_PCA9685/PCA9685.py", line 111, in set_all_pwm File "build/bdist.linux-armv7l/egg/Adafruit_GPIO/I2C.py", line 115, in write8 File "build/bdist.linux-armv7l/egg/Adafruit_PureIO/smbus.py", line 236, in write_byte_data IOError: [Errno 121] Remote I/O error

###該当のソースコード

https://github.com/adafruit/Adafruit_Python_PCA9685
のサンプルコードを使っています。

python

1# Simple demo of of the PCA9685 PWM servo/LED controller library. 2# This will move channel 0 from min to max position repeatedly. 3# Author: Tony DiCola 4# License: Public Domain 5from __future__ import division 6import time 7 8# Import the PCA9685 module. 9import Adafruit_PCA9685 10 11 12# Uncomment to enable debug output. 13#import logging 14#logging.basicConfig(level=logging.DEBUG) 15 16# Initialise the PCA9685 using the default address (0x40). 17pwm = Adafruit_PCA9685.PCA9685() 18 19# Alternatively specify a different address and/or bus: 20#pwm = Adafruit_PCA9685.PCA9685(address=0x41, busnum=2) 21 22# Configure min and max servo pulse lengths 23servo_min = 150 # Min pulse length out of 4096 24servo_max = 600 # Max pulse length out of 4096 25 26# Helper function to make setting a servo pulse width simpler. 27def set_servo_pulse(channel, pulse): 28 pulse_length = 1000000 # 1,000,000 us per second 29 pulse_length //= 60 # 60 Hz 30 print('{0}us per period'.format(pulse_length)) 31 pulse_length //= 4096 # 12 bits of resolution 32 print('{0}us per bit'.format(pulse_length)) 33 pulse *= 1000 34 pulse //= pulse_length 35 pwm.set_pwm(channel, 0, pulse) 36 37# Set frequency to 60hz, good for servos. 38pwm.set_pwm_freq(60) 39 40print('Moving servo on channel 0, press Ctrl-C to quit...') 41while True: 42 # Move servo on channel O between extremes. 43 pwm.set_pwm(0, 0, servo_min) 44 time.sleep(1) 45 pwm.set_pwm(0, 0, servo_max) 46 time.sleep(1)

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

I2Cが有効になってないのでは?

$ sudo i2cdetect -y 1

でI2Cが有効かどうか確認ができるようです。

また、GPIOの設定は行われていますか?
ソース上では行われてないようですが・・・。

グーグル先生に聞いたら参考になるかもしれない記事を見つけたので参考までに張っておきます。
Raspberry Pi 3でPCA9685を使う

投稿2017/12/03 14:32

TaroToyotomi

総合スコア1430

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問