ラベル Raspberry PI3 の投稿を表示しています。 すべての投稿を表示
ラベル Raspberry PI3 の投稿を表示しています。 すべての投稿を表示

2016年6月25日土曜日

Raspberry piにAndroid TVを入れる

Raspberry piにAndroid TVを入れる

Ubuntuを使ってRaspberry PI3用のAndroid TVのSDカードの作成方法をメモしておきます。

1.以下からAndroid TVのイメージをダウンロード

http://geektillithertz.com/wordpress/index.php/2016/06/02/android-tv-for-raspberry-pi-3/

2. イメージをSDカードへ書き込み

以下の手順でイメージを解凍して書き込み
システム→設定→ハードウエア→ディスク

3. アプリの追加

作成したSDカードのdataパーティションのappフォルダにapkファイルを置くことで
アプリが追加できる。

2016年6月13日月曜日

RaspberryPI3とMilkCocoaを連携させてみる。

RaspberryPI3とMilkCocoaを連携させてみる。

Raspberry PI3で測定した温度をリアルタイムに表示する手段を探していたところMilkCocoaというサービスがあったので試してみました。

温度はDHT11を使ったので、Adafruit_Python_DHTを使いました。
Adafruit_Python_DHTの使い方は調べればでてくるのでそちらを参照。

MilkCocoaの準備

1.MilkCocoaでユーザー登録し、dashboardから新しいアプリを作るをクリック。

enter image description here

2.App Nameを入力し、新しいアプリを作るをクリック。

enter image description here

3.認証をクリックし、API Key認証新しいAPI KeyとAPI Secretのペアを生成するをクリック

enter image description here

4.データストアをクリックし、名前を入力。
ここではtempとした。
enter image description here

Raspberry PI側のPythonの準備

1.PythonSDKのインストール
 これを参考にインストール

2.APP_ID, API_KEY,SECRET,DB_NAME(datastore名)を以下のようにpythonのコード(dht11_milkcocoa.py)に入れる。
APP_IDは以下に記載のものです。
enter image description here

#! /usr/bin/python3

import Adafruit_DHT
import time
import milkcocoa.milkcocoa as milkcocoa

APP_ID = 'xxxxxx'
API_KEY = 'xxxxxx'
SECRET = 'xxxx'
DB_NAME = 'temp'

def add_count_record(temperature,humidity):
    try:
        mc_client = milkcocoa.Milkcocoa.connectWithApiKey(APP_ID, API_KEY, SECRET, useSSL=False)
        datastore = mc_client.datastore(DB_NAME)
        datastore.push({"temperature": temperature, "humidity": humidity})
    except Exception as e:
        print(e)

def main():
    counter = 0

    while True:
        counter += 1

        # 30秒ごとに検知回数をMilkcocoaに送信
        if counter == 30:
            humidity, temperature = Adafruit_DHT.read_retry(11, 4)
            add_count_record(temperature,humidity)
            print("Temp={0:0.1f}, Hum={1:0.1f}" .format(temperature,humidity))
            counter = 0

        time.sleep(1.0)

if __name__ == '__main__':
    main()

3.pythonを実行

$ sudo python3 ./dht11_milkcocoa.py

4.データストアの確認
リスト表示(更新)を押して以下のようにデータがでればMilkCocoaにデータが送られている。
enter image description here

MilkCocoaでのグラフ化

1.データストアでデータ可視化をクリック

2.DATASOURCESの下のAddをクリックし、以下を入力
 TYPE: Milkcocoa
 NAME: 温度(自由に記載OK)
 DATASTORE: temp
 API: push
enter image description here

3.ADD PANEで以下を追加
TYPE: Sparkline
TITLE: 温度(自由に記載可能)
VALUE: datasource[“Temp”][“value”][“temperature”]
INCLUDE LEGEND: YES
LEGEND: detection temperature/30sec

enter image description here

4.一度に表示する個数の設定。
以下の工具マークをクリックし、Columnsの値を設定することで表示するサンプル数を決められる。
enter image description here

参考
http://yura2.hateblo.jp/entry/2016/02/29/PIR%E3%82%BB%E3%83%B3%E3%82%B5(SB00412A-1)%E3%81%A8Milkcocoa%E3%81%A7%E7%B0%A1%E6%98%93%E8%A6%8B%E5%AE%88%E3%82%8A%E3%82%B7%E3%82%B9%E3%83%86%E3%83%A0%E3%82%92%E6%A7%8B%E7%AF%89

2016年6月11日土曜日

wiringPiをpythonから呼び出す。

wiringPiをpythonから呼び出す。

Raspberry PI3のGPIOを制御するにはwiringpi2を使ったほうがよいらしいので、試してみました。

1.wiringpi2のインストール

$ sudo apt-get update
$ sudo apt-get install python3-dev python3-pip
$ sudo pip3 install wiringpi2

2.wiringPi2-Pythonのインストール

$ git clone https://github.com/Gadgetoid/WiringPi2-Python.git
cd WiringPi2-Python
$ sudo python3 setup.py install

3.動作確認

$ sudo python3
>> import wiringpi2

以下のエラーがでた。

Traceback (most recent call last):
  File "/home/rpi3/Work/WiringPi2-Python/wiringpi2.py", line 18, in swig_import_helper
    fp, pathname, description = imp.find_module('_wiringpi2', [dirname(__file__)])
  File "/usr/lib/python3.5/imp.py", line 296, in find_module
    raise ImportError(_ERR_MSG.format(name), name=name)
ImportError: No module named '_wiringpi2'

解決方法

wiringpi_wrap.cを修正する必要があるらしい。

$ vi wiringpi_wrap.c
PyString_FromStringAndSize(x, len) PyUnicode_FromStringAndSize(x, len)を追加

追加する場所は以下の「+」のところです。

 #define PyString_FromString(x) PyUnicode_FromString(x)
+#define PyString_FromStringAndSize(x, len) PyUnicode_FromStringAndSize(x, len)
#define PyString_Format(fmt, args)  PyUnicode_Format(fmt, args)

再度、インストールし、実行することでうまくいきました。
結構、調べてるとpython2.xとpython3.xでだいぶ違う。。。

$ sudo python3 setup.py install
$ sudo python3
>> import wiringpi2
エラーがでなくなった!
>> wiringpi2.piBoardRev()

これでpythonからGPIOが制御できるようになったので少し遊んでみようかと思います。

2016年5月2日月曜日

Raspberry PI3にubuntu mateを入れてみる

Raspberry PI3にubuntu mateを入れてみる

Raspberry Pi3にUbuntu Mateを入れてみました。(Ubuntu 14.04を使用)
環境を準備するまでの一通りをメモっておきます。

1.インストール
2.黒枠対策
3.日本語入力
4.フォルダの英語表記化
5.SSHを有効にする
6.VNC接続
7.lighttpd(サーバー)のインストール

インストール

  1. 以下からubuntu-mate-16.04-desktop-armhf-raspberry-pi.img.xzをダウンロード
    https://ubuntu-mate.org/raspberry-pi/

  2. 以下を実行

$ sudo apt-get install gddrescue xz-utils
$ unxz --verbose ubuntu-mate-16.04-desktop-armhf-raspberry-pi.img.xz
$ sudo ddrescue -D --force ubuntu-mate-16.04-desktop-armhf-raspberry-pi.img /dev/mmcblk0

~2016/6/5 追記~
コマンドでなくてもディスクで初期化した後に上記イメージをリストアでもいけます。

http://desktop-linux.namakemono345.com/raspberry-pi3-wifi/

黒枠対策

画面のまわりに黒枠ができて小さい状態になってました。
config.txtで以下の2つを実施することで回避できました。

$ sudo vi /boot/config.txt

①hdmi_group, hdmi_mode の先頭の ”#” を外して、
  hdmi_group=2
  hdmi_mode=82

②以下の4つがコメントアウトになっていたのではずす     
  overscan_left=0
  overscan_right=0
  overscan_top=0
  overscan_bottom=0

[参考]
http://edgewalk.wp.xdomain.jp/?p=370

キーボードの日本語化

配列が日本語キーボードではなかったので”キーボードの設定”
でレイアウトで”日本語”を追加し、型式を”PC-98xxシリーズ”に変更。
これで再起動したら”半角”を押すことで日本語入力もできた。

設定->ユーザー向け->言語サポート
インストールがでてきたらインストールする。
システム全体に適応“をクリックし再起動。
キーボード入力に使うIMシステムがfcixになっていれば再起動

システム->その他->fcixの入力メソッドを確認し、”Mozc“の記載がなければ再起動する。

キーボードの設定のレイアウトでキーボードの形式を”日本語(PC-98xxシリース)にする。

フォルダの英語表記化

$ LANG=C xdg-user-dirs-gtk-update

※Bluetoothのローカルサービスの転送のフォルダは自動で変わらないので、
 自分でDownloadに変更が必要。

Raspberry Pi Information

・Resize
WelcomeのRaspberry Pi InformationでResizeをクリック。
これによりSDカードの空領域も使えるようになる。

・X11をEnable

$ sudo graphical enable

・kernel update

sud rpi-update

SSHを有効にする

$ sudo apt-get install raspi-config
$ sudo raspi-config
メニューから"Advanced Options" を選択し、
SSHを選択し、Enable。
これでSSHで繋がるようになった。

VNC接続

$ sudo apt-get install tightvncserver
$ tightvncserver
 password: raspberry
$ sudo vi /etc/init.d/vncboot
$ sudo chmod 755 /etc/init.d/vncboot
$ sudo update-rc.d vncboot defaults
$ sudo reboot
$ ps -ef | grep tightvnc | grep -v grep
// ポートがListenしているかの確認
$ netstat -nlt
// 5901でLISTENしている。

ホスト側からRemminaでIP:5901で接続する。
すでにターミナルが立ち上がっているのでRaspberry PI側にて自動起動するプログラムにてTildaのチェックを外しておく。

vncbootは以下。

#! /bin/sh
# /etc/init.d/vncboot

USER=pi
HOME=/home/pi

export USER HOME

case "$1" in
 start)
 echo "Starting VNC Server"
 #Insert your favoured settings for a VNC session
 su $USER -c '/usr/bin/vncserver :1 -geometry 1920x1080 -depth 24'
 ;;

 stop)
 echo "Stopping VNC Server"
 su $USER -c '/usr/bin/vncserver -kill :1'
 ;;

 *)
 echo "Usage: /etc/init.d/vncboot {start|stop}"
 exit 1
 ;;
esac

exit 0

lighttpdのインストール

$ sudo apt-get -y install lighttpd
// ドキュメントルートやポートを変える場合は以下のファイルを編集
$ sudo vi /etc/lighttpd/lighttpd.conf
// lighttpdが起動しているかの確認
$ ps aux | grep [l]ighttpd
www-data  9905  0.1  0.3   5472  3212 ?        Ss   21:06   0:00 /usr/sbin/lighttpd -D -f /etc/lighttpd/lighttpd.conf

とlighttpd.confがプロセスであれば起動している。
別のPCから[http://IPアドレス:80]でアクセスでき、以下の画面が表示されればOK。
念のため、再起動し、同様にアクセスできるかを確認しておく。
(とりあえず何も設定しなくても自動起動してます。)

enter image description here
“`