Internet, Windows, Linuxの最新技術をやさしく解説

  • concrete5
  • VirtualBox
  • Bootstrap
  • RaspberryPi
  • Arduino
  • Kindle
  • Pdic

RaspberryPiの実験と話題 > いろいろな技集(Stretch以降)

いろいろな技集(Stretch以降)

2017-11-27日付で、最新のRaspbian Stretchがリリースされました。

+
RaspberryPI Stretchのインストール

以下から、2017-11-29、RASPBIAN STRETCH LITE をダウンロードします。

https://www.raspberrypi.org/downloads/raspbian/

イメージファイル(.img)ですが最初の起動時に、SDカードのサイズに合わせてパーティションが調整されます。

+
swapを無効にする方法

以下のコマンドで無効にします。

$ free
total used free shared buff/cache available
Mem: 949580 27168 610948 12236 311464 861936
Swap: 102396 0 102396

$ sudo dphys-swapfile swapoff
$ free
total used free shared buff/cache available
Mem: 949580 26756 611500 12236 311324 862344
Swap: 0 0 0

サービスの自動起動を止める

$ sudo systemctl disable dphys-swapfile
dphys-swapfile.service is not a native service, redirecting to systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install disable dphys-swapfile

 

+
dhcpを無効にし固定IPを設定する

固定IPで使う場合は、dhcpのサービスは余分なので止めましょう。

以下で止めます。

$ sudo systemctl disable dhcpcd

固定IPを設定する

"/etc/network/interfaces" に以下を追記します。

auto lo
iface lo inet loopback

allow-hotplug wlan0
iface wlan0 inet static
address 192.168.0.xxx
network 255.2555.255.0
gateway 192.168.0.1

allow-hotplug eth0
iface eth0 inet static
address 192.168.0.xxx
netmask 255.255.255.0
gateway 192.168.0.1

 

+
IPV6を止める

"/etc/sysctl.conf" に、以下の1行を追加します。

net.ipv6.conf.all.disable_ipv6=1

+
シリアルコンソールを停止する

シリアルを使って接続しないのであれば止めましょう。

以下のサービスを無効にします。

$ sudo systemctl disable getty@tty1
$ sudo systemctl disable hciuart

"/boot/cmdline.txt" から以下の部分を削除します。

console=serial0.115200 console=tty1

 

+
bluetoothを止める

bluetoothを使わないなら止めましょう。

$ sudo systemctl disable bluetooth

+
CPUクロックを固定化する

まず、現状を確認します。

$ cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
ondemand
ondemand
ondemand
ondemand

ondemandは、自動的に変化する設定であることを示しています。

 

$ cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_cur_freq
600000
600000
600000
600000

コマンド実行時の動作周波数が、600MHzであることを示しています。

設定を変えるには以下のツールをインストールして行います。

$ sudo apt-get install cpufrequtils

"/etc/init.d/cpufrequtils" 内の、GOVERNOR="performance" に変更して以下を実行して有効にします。

$ sudo systemctl daemon-reload
$ sudo service cpufrequtils restart

確認します。以下は、RaspberryPi 3の例で、最高パフォーマンス(1,200MHz)に固定されました。

$ cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
performance
performance
performance
performance
$ cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_cur_freq
1200000
1200000
1200000
1200000
$

+
motionのインストール

Stretch Liteだといきなりmotionがインストールできません。

まず以下を実行します。

$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install ffmpeg
$ sudo apt-get install v4l-utils
$ sudo apt-get install libcurl4-openssl-dev
$ sudo apt-get install libmariadbclient18 libpq5

これでできるはずです。

$ sudo apt-get install motion

+
motionの設定

ネットワーク経由でアクセスするために、設定をします。

$ sudo vi /etc/motion/motion.conf


「Live Stream Server」のセクションではネットワーク経由でアクセスを許可します。

私は、on を off にして許可しました。

# Restrict stream connections to localhost only (default: on)
stream_localhost
off

 

デーモンで起動させる設定をします。

$ sudo vi /etc/default/motion

以下のようにyesにします。

# set to 'yes' to enable the motion daemon
start_motion_daemon=yes

取得画像の保存場所のアクセス権を設定する。

 

再起動するとデーモンで起動されます。

+
Bluetoothスピーカを鳴らす

 

Bluetooth関係のパッケージのインストールをします

$ sudo apt-get install pi-bluetooth blueman

サウンド関係のパッケージをインストールします

$ sudo apt-get install pulseaudio pavucontrol 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.targetb

 

bluezのプロファイルの設定を追加します

$ sudo vi /etc/dbus-1/system.d/pulseaudio-bluetooth.conf

以下の内容で作成します。

 

bluetoothモジュールの読み込み設定を追加します

$ 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

 

再起動します。

pulseaudioサービスの起動

$ sudo systemctl start pulseaudio
$ sudo systemctl status pulseaudio
$ sudo systemctl enable pulseaudio

スピーカー(Marsboy)に接続する

$ sudo bluetoothctl
[NEW] Controller B8:27:EB:44:0A:FB raspberrypi [default]
[NEW] Device FC:58:FA:CC:45:9C Marsboy

[bluetooth]# agent on
Agent registered

[bluetooth]# default-agent
Default agent request successful

[bluetooth]# scan on
Discovery started
   :

[bluetooth]# pair FF:88:AA:CC:44:99
Attempting to pair with FF:88:AA:CC:44:99
     :

[bluetooth]# connect FF:88:AA:CC:44:99
Attempting to connect to FC:58:FA:CC:45:9C
    :
Connection successful

[bluetooth]# quit

 

動作テストします


$ sudo paplay /usr/share/sounds/alsa/Front_Center.wav

スピーカーから音が出れば成功です。

 

多くのサイトはここで解説は終わりですが、Bluetoothのプロトコルのことを知らないと、毎回上記のコマンドを手動でしないといけないのかと、でも手動で行ってもうまくいきません。

実は、このページに書いてある内容で、以降再起動して自動的に接続できるようになります。

 

まず、RaspberryPiを起動します。

起動後、少し待ってから、スピーカの電源を入れます。

わたしのスピーカの場合、電源が入ると「ぴぽっ!」と音がします。

さらに待っていると、接続が成功し「ぽっ!」と音がします。

すると音が出るようになります。

 

 

 

+
WindowsPCからRaspberryPiにリモートデスクトップ接続する

RaspberryPi側

xrdpをインストールします。

$ sudo apt-get install xrdp

xrdpを起動します。

$ sudo service xrdp restart

 

WindowsPC側

WindowsPCの「ファイル名を指定して実行」で、"mstsc" を実行し、ユーザ名 "pi"でパスワードを入れるとデスクトップの画面になります。

+
CPUの制限温度を設定する

RaspberryPiにはCPUの最大制限温度が設定されています。

超えるとCPUの速度を落とすとかで制限温度を超えないように動作するそうです。

デフォルトでは、85(―5度の80度から温度制御が始まる)に設定されていました。

以下で確認できます。

$ vcgencmd get_config temp_limit

/boot/config.txt に、"temp_limit=85" のように記述すれば制限温度を変更できます。

+
CPUの動作速度をいじくる

パッケージをインストールする

$ sudo apt-get install cpufrequtils

現在の状態を見る

$ cpufreq-info -p
700000 1000000 ondemand

負荷に応じて速度を上げる設定のようです。省電力設定にしてみます。

$ sudo cpufreq-set -g powersave

確認します。

$ cpufreq-info -p
700000 1000000 powersave

+
HALT(poweroff,shutdown)から電源はそのまま起動させる方法

シャットダウン(shutdown -h または poweroff)で停止した状態から、起動させるとき電源を抜いて差し込むという操作でなくても起動させることができます。

GPIO3(5番ピン、1番ピンの3.3Vから2番目)をGNDに触れさせると、起動します。

+
RaspberryPiの赤と緑のLEDの挙動を変えたり、GPIOの状態に割り付けたり

緑LEDの挙動を見ます。

# cat /sys/class/leds/led0/trigger
none kbd-scrolllock kbd-numlock kbd-capslock kbd-kanalock kbd-shiftlock kbd-altgrlock kbd-ctrllock kbd-altlock kbd-shiftllock kbd-shiftrlock kbd-ctrlllock kbd-ctrlrlock timer oneshot heartbeat backlight gpio cpu0 cpu1 cpu2 cpu3 default-on input panic [mmc0] mmc1 rfkill0 rfkill1

mmc0 に設定されています。これはSDカードのアクセスで点滅する設定だそうです。

赤LEDのデフォルトの挙動を見ます。

# cat /sys/class/leds/led1/trigger
none kbd-scrolllock kbd-numlock kbd-capslock kbd-kanalock kbd-shiftlock kbd-altgrlock kbd-ctrllock kbd-altlock kbd-shiftllock kbd-shiftrlock kbd-ctrlllock kbd-ctrlrlock timer oneshot heartbeat backlight gpio cpu0 cpu1 cpu2 cpu3 default-on [input] panic mmc0 mmc1 rfkill0 rfkill1

input に設定されています。これは、電源電圧が正常な場合に点灯する設定のようです。

 

チカチカさせるには

heartbeat に設定します。

$ sudo echo heartbeat | sudo tee /sys/class/leds/led0/trigger

 

ON/OFFの時間を設定してチカチカさせるには

$ sudo echo timer | sudo tee /sys/class/leds/led0/trigger
$ sudo echo 500 | sudo tee /sys/class/leds/led0/delay_on
$ sudo echo 500 | sudo tee /sys/class/leds/led0/delay_off

 

一定時間点灯させるには

まず以下を設定します。するとLED消えます。

$ sudo echo oneshot | sudo tee /sys/class/leds/led0/trigger
$ sudo echo 500 | sudo tee /sys/class/leds/led0/delay_on

何か書くと、500msec 点灯します。

$ sudo echo 1 | sudo tee /sys/class/leds/led0/shot


GPIOの状態と連動させるには

GPIO23と連動した例です。

$ sudo echo 6 | sudo tee /sys/class/gpio/export
$ sudo echo in | sudo tee /sys/class/gpio/gpio6/direction
$ sudo echo gpio | sudo tee /sys/class/leds/led0/trigger
$ sudo echo 6 | sudo tee /sys/class/leds/led0/gpio

 

赤いLEDを消灯させるには

$ sudo echo none | sudo tee /sys/class/leds/led1/trigger

起動時に設定をするには、"/boot/confug.txt" に以下の一行を加えます。

dtparam=pwr_led_trigger=none,pwr_led_activelow=off

 

 

以下から引用しました。
http://blog.livedoor.jp/victory7com/archives/43512294.html

 

+
RasberryPi CameraのLEDをOFFにする方法

"/boot/config.txt" に以下を追加して、リブートします。

disable_camera_led=1

+
google-home-notifierのインストール

以下の手順でインストールできます。

$ curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -

$ sudo apt-get install nodejs

$ sudo apt-get install git-core libnss-mdns libavahi-compat-libdnssd-dev

$ git clone https://github.com/noelportugal/google-home-notifier

$ cd google-home-notifier

$ npm install

 

 

 

(参考)
https://qiita.com/azipinsyan/items/db4606aaa51426ac8dac

+
node.jpのインストールの方法

$ sudo apt-get install node.js npm

$ sudo npm cache clean

$ sudo npm install n -g

$ sudo n stable

$ node -v

v9.10.1

$

2018-04-05現在、9.10.1 でした。

RaspberryPiの実験と話題 > いろいろな技集(Stretch以降)

ツイート
このエントリーをはてなブックマークに追加
  

Theme Made by Enrique Ramírez for Smashing Magazine. Powered by Concrete5
© 2019 tomoのconcrete5. All rights reserved. ログイン