Raspberry Pi3 GPIO 制御

RaspberryPi3で遊んでみるために今まで本を4冊購入してます。

f:id:osadamao:20180114140921j:plain

 

f:id:osadamao:20180114140927j:plain

この本で紹介されていたGPIO制御をテストするための汎用GPIOボードを購入したので、この本で紹介されていた python のプログラムで初めてLチカやスイッチ確認の実験をしました。

 

 

f:id:osadamao:20180114140934j:plain

 

プログラムに多少の違いはあるけれど、Lチカやスイッチの状態読み取りテストプログラムはどれも同じようなもの。なのですが、ふと使っているモジュールが違うことに気が付きました。

これらの書籍では RPi.GPIO を使っており、プログラムの冒頭に

import RPi.GPIO as GPIO

を記述していました。

 

ですが下の書籍では、wiringpi を使っており、冒頭に

import wiringpi as pi

を記述しています。

f:id:osadamao:20180114134907j:plain

なんか気になります。どっちが使いやすいのか考察してみたいと思います。

 

キャラクタディスプレイに文字を表示させたいだけなのに・・・

#!/usr/bin/env python
#coding:utf-8
import serial
import datetime
from time import sleep

##
# str = con.readline();
# if str != "" :
# print (str)
# sleep(0.5)
#
#
#if __name__ == '__main__' :
#    main()


con=serial.Serial('/dev/ttyAMA0',115200,timeout=0)
print (con.portstr)


while True:
    dt=datetime.datetime.now()
    print(dt)
#    print(dt.strftime("%H %M %S"))
#    con.write(dt).encode('utf-8')
#    con.write('AT'+'\r\n')

    str = con.readline();
    if str != "" :
        print (str)
    sleep(1)

 

Raspberry Pi3 の Bluetooth イヤホン接続の謎2

bluetoothのイヤホンをつないでみたくて、今度はここを参考にアップデートをしてみた。

結果:NG。

参考)https://qiita.com/nattof/items/3db73a95e63100d7580a

 

sudo apt install pulseaudio-module-bluetooth

 

ファイルの新規作成

sudo vi /etc/systemd/system/pulseaudio.service
[Unit]
Description=Pulse Audio

[Service]
Type=simple
ExecStart=/usr/bin/pulseaudio --system --disallow-exit --disable-shm

[Install]
WantedBy=multi-user.target

 

ファイルの新規作成

 sudo vi /etc/dbus-1/system.d/pulseaudio-bluetooth.conf
<busconfig>

<policy user="pulse">
<allow send_destination="org.bluez"/>
</policy>

</busconfig>

 

ファイルの末尾に追記

 sudo vi /etc/pulse/system.pa
### Automatically load driver modules for Bluetooth hardware
.ifexists module-bluetooth-policy.so
load-module module-bluetooth-policy
.endif

.ifexists module-bluetooth-discover.so
load-module module-bluetooth-discover
.endif

sudo systemctl start pulseaudio.service

sudo systemctl enable pulseaudio.service

Raspberry Pi3 の Bluetooth イヤホン接続の謎

bluetoothのイヤホンをつないでみたくて、ここを参考にアップデートをしてみた。

結果:NG。

https://qiita.com/Sam/items/5169d9f060aa31080b77


Linux raspberrypi 4.9.59-v7+ #1047 SMP Sun Oct 29 12:19:23 GMT 2017 armv7l

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Sat Feb 3 01:00:51 2018
pi@raspberrypi:~ $ sudo apt install pi-bluetooth blueman
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています
状態情報を読み取っています... 完了
pi-bluetooth はすでに最新バージョン (0.1.6) です。
以下の追加パッケージがインストールされます:
bluez-obexd gir1.2-appindicator3-0.1 gir1.2-notify-0.7 libappindicator3-1
libdbusmenu-glib4 libdbusmenu-gtk3-4 libical2 libindicator3-7
libpulse-mainloop-glib0 notification-daemon python3-cairo python3-gi-cairo
以下のパッケージが新たにインストールされます:
blueman bluez-obexd gir1.2-appindicator3-0.1 gir1.2-notify-0.7
libappindicator3-1 libdbusmenu-glib4 libdbusmenu-gtk3-4 libical2
libindicator3-7 libpulse-mainloop-glib0 notification-daemon python3-cairo
python3-gi-cairo
アップグレード: 0 個、新規インストール: 13 個、削除: 0 個、保留: 0 個。
2,819 kB のアーカイブを取得する必要があります。
この操作後に追加で 7,706 kB のディスク容量が消費されます。
続行しますか? [Y/n] Y
取得:1 http://archive.raspberrypi.org/debian stretch/main armhf bluez-obexd armhf 5.43-2+rpt2+deb9u2 [176 kB]
取得:2 http://ftp.jaist.ac.jp/pub/Linux/raspbian-archive/raspbian stretch/main armhf libical2 armhf 2.0.0-0.5+b1 [164 kB]
取得:3 http://ftp.jaist.ac.jp/pub/Linux/raspbian-archive/raspbian stretch/main armhf notification-daemon armhf 3.20.0-1 [55.4 kB]
取得:4 http://ftp.jaist.ac.jp/pub/Linux/raspbian-archive/raspbian stretch/main armhf libpulse-mainloop-glib0 armhf 10.0-1+deb9u1 [43.9 kB]
取得:5 http://ftp.jaist.ac.jp/pub/Linux/raspbian-archive/raspbian stretch/main armhf gir1.2-notify-0.7 armhf 0.7.7-2 [9,740 B]
取得:6 http://ftp.jaist.ac.jp/pub/Linux/raspbian-archive/raspbian stretch/main armhf python3-cairo armhf 1.10.0+dfsg-5 [23.5 kB]
取得:7 http://ftp.jaist.ac.jp/pub/Linux/raspbian-archive/raspbian stretch/main armhf python3-gi-cairo armhf 3.22.0-2 [328 kB]
取得:8 http://ftp.jaist.ac.jp/pub/Linux/raspbian-archive/raspbian stretch/main armhf libdbusmenu-glib4 armhf 12.10.2-2 [96.8 kB]
取得:9 http://ftp.jaist.ac.jp/pub/Linux/raspbian-archive/raspbian stretch/main armhf libdbusmenu-gtk3-4 armhf 12.10.2-2 [85.6 kB]
取得:10 http://ftp.jaist.ac.jp/pub/Linux/raspbian-archive/raspbian stretch/main armhf libindicator3-7 armhf 0.5.0-3 [49.5 kB]
取得:11 http://ftp.jaist.ac.jp/pub/Linux/raspbian-archive/raspbian stretch/main armhf libappindicator3-1 armhf 0.4.92-4+b2 [50.4 kB]
取得:12 http://ftp.jaist.ac.jp/pub/Linux/raspbian-archive/raspbian stretch/main armhf gir1.2-appindicator3-0.1 armhf 0.4.92-4+b2 [38.7 kB]
取得:13 http://ftp.jaist.ac.jp/pub/Linux/raspbian-archive/raspbian stretch/main armhf blueman armhf 2.0.4-1+b4 [1,698 kB]
2,819 kB を 46秒 で取得しました (60.2 kB/s)
以前に未選択のパッケージ libical2:armhf を選択しています。
(データベースを読み込んでいます ... 現在 126542 個のファイルとディレクトリがインストールされています。)
.../00-libical2_2.0.0-0.5+b1_armhf.deb を展開する準備をしています ...
libical2:armhf (2.0.0-0.5+b1) を展開しています...
以前に未選択のパッケージ bluez-obexd を選択しています。
.../01-bluez-obexd_5.43-2+rpt2+deb9u2_armhf.deb を展開する準備をしています ...
bluez-obexd (5.43-2+rpt2+deb9u2) を展開しています...
以前に未選択のパッケージ notification-daemon を選択しています。
.../02-notification-daemon_3.20.0-1_armhf.deb を展開する準備をしています ...
notification-daemon (3.20.0-1) を展開しています...
以前に未選択のパッケージ libpulse-mainloop-glib0:armhf を選択しています。
.../03-libpulse-mainloop-glib0_10.0-1+deb9u1_armhf.deb を展開する準備をしていま す ...
libpulse-mainloop-glib0:armhf (10.0-1+deb9u1) を展開しています...
以前に未選択のパッケージ gir1.2-notify-0.7:armhf を選択しています。
.../04-gir1.2-notify-0.7_0.7.7-2_armhf.deb を展開する準備をしています ...
gir1.2-notify-0.7:armhf (0.7.7-2) を展開しています...
以前に未選択のパッケージ python3-cairo を選択しています。
.../05-python3-cairo_1.10.0+dfsg-5_armhf.deb を展開する準備をしています ...
python3-cairo (1.10.0+dfsg-5) を展開しています...
以前に未選択のパッケージ python3-gi-cairo を選択しています。
.../06-python3-gi-cairo_3.22.0-2_armhf.deb を展開する準備をしています ...
python3-gi-cairo (3.22.0-2) を展開しています...
以前に未選択のパッケージ libdbusmenu-glib4:armhf を選択しています。
.../07-libdbusmenu-glib4_12.10.2-2_armhf.deb を展開する準備をしています ...
libdbusmenu-glib4:armhf (12.10.2-2) を展開しています...
以前に未選択のパッケージ libdbusmenu-gtk3-4:armhf を選択しています。
.../08-libdbusmenu-gtk3-4_12.10.2-2_armhf.deb を展開する準備をしています ...
libdbusmenu-gtk3-4:armhf (12.10.2-2) を展開しています...
以前に未選択のパッケージ libindicator3-7:armhf を選択しています。
.../09-libindicator3-7_0.5.0-3_armhf.deb を展開する準備をしています ...
libindicator3-7:armhf (0.5.0-3) を展開しています...
以前に未選択のパッケージ libappindicator3-1:armhf を選択しています。
.../10-libappindicator3-1_0.4.92-4+b2_armhf.deb を展開する準備をしています ...
libappindicator3-1:armhf (0.4.92-4+b2) を展開しています...
以前に未選択のパッケージ gir1.2-appindicator3-0.1:armhf を選択しています。
.../11-gir1.2-appindicator3-0.1_0.4.92-4+b2_armhf.deb を展開する準備をしています ...
gir1.2-appindicator3-0.1:armhf (0.4.92-4+b2) を展開しています...
以前に未選択のパッケージ blueman を選択しています。
.../12-blueman_2.0.4-1+b4_armhf.deb を展開する準備をしています ...
blueman (2.0.4-1+b4) を展開しています...
libindicator3-7:armhf (0.5.0-3) を設定しています ...
gir1.2-notify-0.7:armhf (0.7.7-2) を設定しています ...
libical2:armhf (2.0.0-0.5+b1) を設定しています ...
libpulse-mainloop-glib0:armhf (10.0-1+deb9u1) を設定しています ...
mime-support (3.60) のトリガを処理しています ...
desktop-file-utils (0.23-1) のトリガを処理しています ...
libglib2.0-0:armhf (2.50.3-2) のトリガを処理しています ...
libdbusmenu-glib4:armhf (12.10.2-2) を設定しています ...
libc-bin (2.24-11+deb9u1) のトリガを処理しています ...
bluez-obexd (5.43-2+rpt2+deb9u2) を設定しています ...
man-db (2.7.6.1-2) のトリガを処理しています ...
python3-cairo (1.10.0+dfsg-5) を設定しています ...
gnome-menus (3.13.3-9) のトリガを処理しています ...
dbus (1.10.24-0+deb9u1) のトリガを処理しています ...
hicolor-icon-theme (0.15-1) のトリガを処理しています ...
notification-daemon (3.20.0-1) を設定しています ...
libdbusmenu-gtk3-4:armhf (12.10.2-2) を設定しています ...
python3-gi-cairo (3.22.0-2) を設定しています ...
libappindicator3-1:armhf (0.4.92-4+b2) を設定しています ...
gir1.2-appindicator3-0.1:armhf (0.4.92-4+b2) を設定しています ...
blueman (2.0.4-1+b4) を設定しています ...
libc-bin (2.24-11+deb9u1) のトリガを処理しています ...
dbus (1.10.24-0+deb9u1) のトリガを処理しています ...
pi@raspberrypi:~ $ sudo apt install pulseaudio pavucontrol pulseaudio-module-bluetooth
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています
状態情報を読み取っています... 完了
以下の追加パッケージがインストールされます:
libasound2-plugins libatkmm-1.6-1v5 libcairomm-1.0-1v5 libglibmm-2.4-1v5
libgtkmm-3.0-1v5 libpangomm-1.4-1v5 libpulsedsp libspeexdsp1
pulseaudio-utils rtkit
提案パッケージ:
pavumeter paman paprefs
以下のパッケージが新たにインストールされます:
libasound2-plugins libatkmm-1.6-1v5 libcairomm-1.0-1v5 libglibmm-2.4-1v5
libgtkmm-3.0-1v5 libpangomm-1.4-1v5 libpulsedsp libspeexdsp1 pavucontrol
pulseaudio pulseaudio-module-bluetooth pulseaudio-utils rtkit
アップグレード: 0 個、新規インストール: 13 個、削除: 0 個、保留: 0 個。
3,152 kB のアーカイブを取得する必要があります。
この操作後に追加で 14.0 MB のディスク容量が消費されます。
続行しますか? [Y/n] Y
取得:1 http://ftp.jaist.ac.jp/pub/Linux/raspbian-archive/raspbian stretch/main armhf libspeexdsp1 armhf 1.2~rc1.2-1 [42.9 kB]
取得:2 http://ftp.jaist.ac.jp/pub/Linux/raspbian-archive/raspbian stretch/main armhf libasound2-plugins armhf 1.1.1-1 [72.9 kB]
取得:3 http://ftp.jaist.ac.jp/pub/Linux/raspbian-archive/raspbian stretch/main armhf libglibmm-2.4-1v5 armhf 2.50.0-1 [593 kB]
取得:4 http://ftp.jaist.ac.jp/pub/Linux/raspbian-archive/raspbian stretch/main armhf libatkmm-1.6-1v5 armhf 2.24.2-2 [57.1 kB]
取得:5 http://ftp.jaist.ac.jp/pub/Linux/raspbian-archive/raspbian stretch/main armhf libcairomm-1.0-1v5 armhf 1.12.0-1 [61.7 kB]
取得:6 http://ftp.jaist.ac.jp/pub/Linux/raspbian-archive/raspbian stretch/main armhf libpangomm-1.4-1v5 armhf 2.40.1-3 [50.1 kB]
取得:7 http://ftp.jaist.ac.jp/pub/Linux/raspbian-archive/raspbian stretch/main armhf libgtkmm-3.0-1v5 armhf 3.22.0-1 [903 kB]
取得:8 http://ftp.jaist.ac.jp/pub/Linux/raspbian-archive/raspbian stretch/main armhf libpulsedsp armhf 10.0-1+deb9u1 [52.0 kB]
取得:9 http://ftp.jaist.ac.jp/pub/Linux/raspbian-archive/raspbian stretch/main armhf pavucontrol armhf 3.0-3.1 [102 kB]
取得:10 http://ftp.jaist.ac.jp/pub/Linux/raspbian-archive/raspbian stretch/main armhf pulseaudio-utils armhf 10.0-1+deb9u1 [82.8 kB]
取得:11 http://ftp.jaist.ac.jp/pub/Linux/raspbian-archive/raspbian stretch/main armhf pulseaudio armhf 10.0-1+deb9u1 [1,020 kB]
取得:12 http://ftp.jaist.ac.jp/pub/Linux/raspbian-archive/raspbian stretch/main armhf rtkit armhf 0.11-4 [31.2 kB]
取得:13 http://ftp.jaist.ac.jp/pub/Linux/raspbian-archive/raspbian stretch/main armhf pulseaudio-module-bluetooth armhf 10.0-1+deb9u1 [83.9 kB]
3,152 kB を 32秒 で取得しました (95.9 kB/s)
以前に未選択のパッケージ libspeexdsp1:armhf を選択しています。
(データベースを読み込んでいます ... 現在 127076 個のファイルとディレクトリがインストールされています。)
.../00-libspeexdsp1_1.2~rc1.2-1_armhf.deb を展開する準備をしています ...
libspeexdsp1:armhf (1.2~rc1.2-1) を展開しています...
以前に未選択のパッケージ libasound2-plugins:armhf を選択しています。
.../01-libasound2-plugins_1.1.1-1_armhf.deb を展開する準備をしています ...
libasound2-plugins:armhf (1.1.1-1) を展開しています...
以前に未選択のパッケージ libglibmm-2.4-1v5:armhf を選択しています。
.../02-libglibmm-2.4-1v5_2.50.0-1_armhf.deb を展開する準備をしています ...
libglibmm-2.4-1v5:armhf (2.50.0-1) を展開しています...
以前に未選択のパッケージ libatkmm-1.6-1v5:armhf を選択しています。
.../03-libatkmm-1.6-1v5_2.24.2-2_armhf.deb を展開する準備をしています ...
libatkmm-1.6-1v5:armhf (2.24.2-2) を展開しています...
以前に未選択のパッケージ libcairomm-1.0-1v5:armhf を選択しています。
.../04-libcairomm-1.0-1v5_1.12.0-1_armhf.deb を展開する準備をしています ...
libcairomm-1.0-1v5:armhf (1.12.0-1) を展開しています...
以前に未選択のパッケージ libpangomm-1.4-1v5:armhf を選択しています。
.../05-libpangomm-1.4-1v5_2.40.1-3_armhf.deb を展開する準備をしています ...
libpangomm-1.4-1v5:armhf (2.40.1-3) を展開しています...
以前に未選択のパッケージ libgtkmm-3.0-1v5:armhf を選択しています。
.../06-libgtkmm-3.0-1v5_3.22.0-1_armhf.deb を展開する準備をしています ...
libgtkmm-3.0-1v5:armhf (3.22.0-1) を展開しています...
以前に未選択のパッケージ libpulsedsp:armhf を選択しています。
.../07-libpulsedsp_10.0-1+deb9u1_armhf.deb を展開する準備をしています ...
libpulsedsp:armhf (10.0-1+deb9u1) を展開しています...
以前に未選択のパッケージ pavucontrol を選択しています。
.../08-pavucontrol_3.0-3.1_armhf.deb を展開する準備をしています ...
pavucontrol (3.0-3.1) を展開しています...
以前に未選択のパッケージ pulseaudio-utils を選択しています。
.../09-pulseaudio-utils_10.0-1+deb9u1_armhf.deb を展開する準備をしています ...
pulseaudio-utils (10.0-1+deb9u1) を展開しています...
以前に未選択のパッケージ pulseaudio を選択しています。
.../10-pulseaudio_10.0-1+deb9u1_armhf.deb を展開する準備をしています ...
pulseaudio (10.0-1+deb9u1) を展開しています...
以前に未選択のパッケージ rtkit を選択しています。
.../11-rtkit_0.11-4_armhf.deb を展開する準備をしています ...
rtkit (0.11-4) を展開しています...
以前に未選択のパッケージ pulseaudio-module-bluetooth を選択しています。
.../12-pulseaudio-module-bluetooth_10.0-1+deb9u1_armhf.deb を展開する準備をして います ...
pulseaudio-module-bluetooth (10.0-1+deb9u1) を展開しています...
libcairomm-1.0-1v5:armhf (1.12.0-1) を設定しています ...
mime-support (3.60) のトリガを処理しています ...
libpulsedsp:armhf (10.0-1+deb9u1) を設定しています ...
desktop-file-utils (0.23-1) のトリガを処理しています ...
pulseaudio-utils (10.0-1+deb9u1) を設定しています ...
libc-bin (2.24-11+deb9u1) のトリガを処理しています ...
rtkit (0.11-4) を設定しています ...
man-db (2.7.6.1-2) のトリガを処理しています ...
gnome-menus (3.13.3-9) のトリガを処理しています ...
libglibmm-2.4-1v5:armhf (2.50.0-1) を設定しています ...
dbus (1.10.24-0+deb9u1) のトリガを処理しています ...
libspeexdsp1:armhf (1.2~rc1.2-1) を設定しています ...
libatkmm-1.6-1v5:armhf (2.24.2-2) を設定しています ...
libasound2-plugins:armhf (1.1.1-1) を設定しています ...
libpangomm-1.4-1v5:armhf (2.40.1-3) を設定しています ...
pulseaudio (10.0-1+deb9u1) を設定しています ...
ユーザ pulse をグループ audio に追加
libgtkmm-3.0-1v5:armhf (3.22.0-1) を設定しています ...
pulseaudio-module-bluetooth (10.0-1+deb9u1) を設定しています ...
pavucontrol (3.0-3.1) を設定しています ...
libc-bin (2.24-11+deb9u1) のトリガを処理しています ...
dbus (1.10.24-0+deb9u1) のトリガを処理しています ...
pi@raspberrypi:~ $ sudo shutdown -r now


Linux raspberrypi 4.9.59-v7+ #1047 SMP Sun Oct 29 12:19:23 GMT 2017 armv7l

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Sat Feb 3 09:32:36 2018
pi@raspberrypi:~ $ pulseaudio -D
E: [pulseaudio] main.c: デーモン開始に失敗しました。

pi@raspberrypi:~ $ bluetoothctl
[NEW] Controller B8:27:EB:DA:1D:6F raspberrypi [default]
[bluetooth]# scan on
Discovery started
[CHG] Controller B8:27:EB:DA:1D:6F Discovering: yes
[NEW] Device 00:1D:BA:97:A9:B5 00-1D-BA-97-A9-B5
[CHG] Device 00:1D:BA:97:A9:B5 LegacyPairing: no
[CHG] Device 00:1D:BA:97:A9:B5 Name: DRC-BT15
[CHG] Device 00:1D:BA:97:A9:B5 Alias: DRC-BT15
[CHG] Device 00:1D:BA:97:A9:B5 LegacyPairing: yes
[bluetooth]# pair 00:1D:BA:97:A9:B5
Attempting to pair with 00:1D:BA:97:A9:B5
[CHG] Device 00:1D:BA:97:A9:B5 Connected: yes
[CHG] Device 00:1D:BA:97:A9:B5 UUIDs: 00001108-0000-1000-8000-00805f9b34fb
[CHG] Device 00:1D:BA:97:A9:B5 UUIDs: 0000110b-0000-1000-8000-00805f9b34fb
[CHG] Device 00:1D:BA:97:A9:B5 UUIDs: 0000110e-0000-1000-8000-00805f9b34fb
[CHG] Device 00:1D:BA:97:A9:B5 UUIDs: 0000111e-0000-1000-8000-00805f9b34fb
[CHG] Device 00:1D:BA:97:A9:B5 ServicesResolved: yes
[CHG] Device 00:1D:BA:97:A9:B5 Paired: yes
Pairing successful
[CHG] Device 00:1D:BA:97:A9:B5 ServicesResolved: no
[CHG] Device 00:1D:BA:97:A9:B5 Connected: no
[bluetooth]# trust 00:1D:BA:97:A9:B5
[CHG] Device 00:1D:BA:97:A9:B5 Trusted: yes
Changing 00:1D:BA:97:A9:B5 trust succeeded
[bluetooth]# connect 00:1D:BA:97:A9:B5
Attempting to connect to 00:1D:BA:97:A9:B5
[CHG] Device 00:1D:BA:97:A9:B5 Connected: yes
Connection successful
[CHG] Device 00:1D:BA:97:A9:B5 ServicesResolved: yes
[DRC-BT15]# quit
[DEL] Controller B8:27:EB:DA:1D:6F raspberrypi [default]
pi@raspberrypi:~ $ speaker-test -t wav

speaker-test 1.1.3

再生デバイス: default
ストリームパラメータ: 48000Hz, S16_LE, 1 チャネル
WAV ファイル
レート 48000Hz (要求値 48000Hz)
バッファサイズ範囲 192 ~ 2097152
ピリオドサイズ範囲 64 ~ 699051
最大バッファサイズ 2097152 を使用
ピリオド数 = 4
period_size = 524288 で設定
buffer_size = 2097152 で設定
0 - Front Left
ピリオド時間 = 1.522633
0 - Front Left
ピリオド時間 = 30.037529
0 - Front Left
ピリオド時間 = 1.522920
0 - Front Left
ピリオド時間 = 1.518963
0 - Front Left
ピリオド時間 = 30.037717
0 - Front Left
ピリオド時間 = 1.521129
0 - Front Left
ピリオド時間 = 30.034256
0 - Front Left
ピリオド時間 = 1.506060
0 - Front Left
ピリオド時間 = 30.035904
0 - Front Left
ピリオド時間 = 1.521735
0 - Front Left
ピリオド時間 = 1.520872
0 - Front Left
ピリオド時間 = 30.034088
0 - Front Left
ピリオド時間 = 1.525179
0 - Front Left
ピリオド時間 = 30.037619
0 - Front Left
ピリオド時間 = 1.522189
0 - Front Left
ピリオド時間 = 30.038107
0 - Front Left
ピリオド時間 = 1.507516
0 - Front Left
ピリオド時間 = 1.511926
0 - Front Left
ピリオド時間 = 30.039014
pi@raspberrypi:~ $

 


pi@raspberrypi:~ $ cat /etc/debian_version
9.3
pi@raspberrypi:~ $

 

Raspberry Pi3 GPIO 出力2PWM

GPIO2,3,4の状態書き込み試行としてPWMでフルカラーLEDを点灯してみる

#ライブラリの読み込み
import RPi.GPIO as GPIO
from time import sleep

#初期化
GPIO.setmode(GPIO.BCM) #GPIO番号指定
GPIO.setwarnings(False)

#出力モード設定
GPIO.setup (2,GPIO.OUT,initial =GPIO.LOW) #初期状態LOW
GPIO.setup (3,GPIO.OUT,initial =GPIO.LOW) #初期状態LOW
GPIO.setup (4,GPIO.OUT,initial =GPIO.LOW) #初期状態LOW

#出力設定
p2 = GPIO.PWM(2,200)
p2.start(0)
p3 = GPIO.PWM(3,200)
p3.start(0)
p4 = GPIO.PWM(4,200)
p4.start(0)

try:
    while True:
        for dc2 in range(0,101,10):
            p2.ChangeDutyCycle(dc2)
            for dc3 in range(0,101,10):
                p3.ChangeDutyCycle(dc3)
                for dc4 in range(0,101,10):
                    p4.ChangeDutyCycle(dc4)
                    print(dc2,dc3,dc4)
                    sleep(0.3)

        for dc2 in range(100,-1,-10):
            p2.ChangeDutyCycle(dc2)
            for dc3 in range(100,-1,-10):
                p3.ChangeDutyCycle(dc3)
                for dc4 in range(100,-1,-10):
                    p4.ChangeDutyCycle(dc4)
                    print(dc2,dc3,dc4)
                    sleep(0.3)

#例外処理
except KeyboardInterrupt:
    print ( 'CTRL + C' )
    pass

 

p2.stop()
p3.stop()
p4.stop()

 

#GPIOリセット終了
GPIO.cleanup()

 

 

Raspberry Pi3 GPIO 出力1

GPIO2,3,4の状態書き込み試行としてフルカラーLEDを点灯してみる

 

#ライブラリの読み込み
import RPi.GPIO as GPIO
from time import sleep

#初期化
GPIO.setmode(GPIO.BCM) #GPIO番号指定
GPIO.setwarnings(False)

#出力モード設定
GPIO.setup (2,GPIO.OUT,initial =GPIO.LOW) #初期状態LOW
GPIO.setup (3,GPIO.OUT,initial =GPIO.LOW) #初期状態LOW
GPIO.setup (4,GPIO.OUT,initial =GPIO.LOW) #初期状態LOW

#出力設定
LOWHIGH = [GPIO.LOW,GPIO.HIGH]
HIGHLOW = [GPIO.HIGH,GPIO.LOW]

try:
    for o1 in LOWHIGH:
       GPIO.output (2,o1)
       sleep(1)

       for o2 in LOWHIGH:
          GPIO.output (3,o2)
          sleep(1)

          for o3 in LOWHIGH:
             GPIO.output (4,o3)
             sleep(1)

    for o1 in HIGHLOW:
       GPIO.output (2,o1)
       sleep(1)

       for o2 in HIGHLOW:
          GPIO.output (3,o2)
          sleep(1)

          for o3 in HIGHLOW:
             GPIO.output (4,o3)
             sleep(1)

except KeyboardInterrupt:
    print ( 'CTRL + C' )
    pass

 

#GPIOリセット終了
GPIO.cleanup()

Raspberry Pi3 GPIO 入力3

Raspberry Pi3 で GPIO ポートからの入力実験その3

「PICと楽しむRaspberryPi活用ガイドブック」の汎用GPIOテストボードを使ってGPIO17に接続されているスイッチが押されている事をポーリングで確認する
 

File:gpioin17-3.py

#ライブラリの読み込み
import RPi.GPIO as GPIO
from time import sleep

#初期化
GPIO.setmode(GPIO.BCM) #GPIO番号指定
GPIO.setwarnings(False)

#入力モード設定
GPIO.setup (17,GPIO.IN,pull_up_down=GPIO.PUD_UP)

#コントロールCが押されるまでループ
try:
    while True:
        print ( 'wait' )
        channel = GPIO.wait_for_edge(17, GPIO.FALLING, bouncetime = 300)
        print ( channel , 'SW3:GPIO17 FALLING' )
        sleep (1)
#例外は無効?
except KeyboardInterrupt:
    print ( 'CTRL + C' )
    pass


#GPIOのリセット終了
GPIO.cleanup()