2017年1月30日月曜日

Raspberry Pi 起動時に ターミナルを開いて Python スクリプトを自動実行させる


Raspberry Pi 起動時に、自動的にターミナルをデスクトップに立ち上げてPythonスクリプトを実行させる方法。
ターミナルを立ち上げずにバックグラウンドで実行する場合は、
/etc/rc.local
を編集すれば良い。

やっていることは同じかもしれないが、以前とはやや手法が異なる。

http://mogen-hogen.blogspot.jp/2015/09/raspberry-pi-python.html

今回使用したRaspberry Piは
Raspberry Pi 2 Model B V1.1
OSは
  Raspbian Jessie with PIXEL
  Version: January 2017
  Release date: 2017-01-11
  Kernel version: 4.4


/home/pi/.config/autostart
フォルダに行く。すでにautostartフォルダは存在していた。
.configフォルダが見えないときは [Ctrl]+[H] とすると隠しフォルダが現れる。

autostartフォルダの中に、

hogehoge.desktop

という名前のファイルを作成し、中に

*******はじまり*******
[Desktop Entry]
Name=hogehoge
Exec=lxterminal –e “python /home/pi/hogehoge.py
Type=Application

*******おわり*******

と記述。
再起動させると自動的にターミナルの画面が立上り、Pythonのプログラムが実行される。

参考URL
https://neverbenever.wordpress.com/2015/02/11/how-to-autostart-a-program-in-raspberry-pi-or-linux/



0 件のコメント: