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

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

RaspberryPiの実験と話題 > 定点カメラを作る実験

定点カメラを作る実験

+
fswebcamで意図的に撮影する

fswebcam をインストールする

$ sudo apt-get install fswebcam

実行してみます。

$ fswebcam -F 100 -r 1024x800 /tmp/test.jpg

--- Opening /dev/video0...
Trying source module v4l2...
/dev/video0 opened.
No input was specified, using the first.
Adjusting resolution from 1024x800 to 960x720.
--- Capturing 100 frames...
Captured 100 frames in 14.97 seconds. (6 fps)
--- Processing captured image...
Writing JPEG image to '/tmp/test.jpg'.

オプションがいっぱいありますが、ひとまずこれで。

+
Dropboxにアップロードする

Dropbox Uploaderをインストールします。

$ git clone https://github.com/andreafabrizi/Dropbox-Uploader/

Cloning into 'Dropbox-Uploader'...
remote: Counting objects: 851, done.
remote: Total 851 (delta 0), reused 0 (delta 0), pack-reused 851
Receiving objects: 100% (851/851), 294.21 KiB | 253.00 KiB/s, done.
Resolving deltas: 100% (444/444), done.
Checking connectivity... done.
$

自分だけがアップロードできるようにするためのTokenを取得します。

以下を開き「Create App」ボタンをクリックします。

https://www.dropbox.com/developers/apps

以下のようにこのTokenの名前を決めて設定し、「Create App」ボタンをクリックします。

2017-09-02_080548.png

出てきた画面の下のほうにある「Generated access token」のところのボタンをクリックするとTokenが表示されます。

 

Dropbox Uploaderを起動し、Access tokenにTokenをコピペします。

$ ./dropbox_uploader.sh

This is the first time you run this script, please follow the instructions:

1) Open the following URL in your Browser, and log in using your account: https://www.dropbox.com/developers/apps
2) Click on "Create App", then select "Dropbox API app"
3) Now go on with the configuration, choosing the app permissions and access restrictions to your DropBox folder
4) Enter the "App Name" that you prefer (e.g. MyUploader2464125022416)

Now, click on the "Create App" button.

When your new App is successfully created, please click on the Generate button
under the 'Generated access token' section, then copy and paste the new access token here:

# Access token: Hke1errCirkAAAAAAALxxxxxxxxxxv1ziy1pOVIDEEsmeJVINkPZe4Uq

Looks ok? [y/N]: y
The configuration has been saved.
$

以下のコマンドでアップロードできます。

$ ./dropbox_uploader.sh upload /tmp/test.jpg test.jpg
> Uploading "/tmp/test.jpg" to "/test.jpg"... DONE
$

どこにアップロードされたか?

Dropboxの「アプリ」というフォルダに、Appの名前のフォルダができていて、そこに保存されています。

+
起動時に自動実行させる

ホームディレクトリ(通常は、/home/pi)にある ".config/lxsession/LXDE-pi/autostart" に自動実行させるシェルスクリプトを登録します。

@lxpanel --profile LXDE-pi
@pcmanfm --desktop --profile LXDE-pi
@xscreensaver -no-splash
@point-rpi
@/home/pi/take_picture_DboxUpload.sh

最後の行に追加すると、起動時に、"pi"のユーザにて自動実行されます。

 

+
GPIOの端子の状態で挙動を変える

gpioの端子の状態を得るには、以下のコマンドで読めます。

まず、gpio(GPIO18)を入力端子に設定します。

gpio -g mode 18 IN

読み込みます。

status=$(gpio -g read 18)

HIGHレベルなら"1".LOWレベルなら"0"です。
以下の判定で、HIGHレベルならシャットダウンする処理となります。

if test $status -eq 1 ; then
  /sbin/poweroff
fi

+
起動時に自動実行で一枚写真撮影してDropboxにアップロードしてシャットダウンする

このページで解説しているコマンドを組み合わせて作ります。

以下が、一つの例です。

 #!/bin/sh

FILENAME=raspi`date +%Y%m%d%H%M`.jpg
FILE=/tmp/${FILENAME}
XPOSURE=100

# take a picture
fswebcam -F ${EXPOSURE} -r 1024x800 ${FILE}

# upload to Dropbox
if [ -f $FILE -a -s $FILE ]; then
    /home/pi/Dropbox-Uploader/dropbox_uploader.sh upload $FILE $FILENAME
else
    exit 1
fi

# remove temporaly file
rm -f $FILE

# check action state
gpio -g mode 18 IN
status=$(gpio -g read 18)
if test $status -eq 1 ; then
    /sbin/reboot
fi

exit 0
+
リアルタイムクロック(ZS-042,DS3231)をつないで時刻を設定する

Raspberry pi に、ZS-042を接続する

時刻を設定するには、SDA, SCL, Vcc, GND の4つを接続します。

SDAは、3番ピン
VCCは、4番ピン
SCLは、5番ピン
GNDは、6番ピン

まず、接続を確認します。以下のように、57と68が見えればOKです。

$ sudo i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- 57 -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- 68 -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

RaspberryPiにRTCの存在を知らせて登録する。

$ echo ds3231 0x68 | sudo tee /sys/class/i2c-adapter/i2c-1/new_device
ds3231 0x68

まず読み出してみます。

$ sudo hwclock -r
Sat 01 Jan 2000 09:59:29 AM JST  -0.997721 seconds

設定してないのでズレズレですので、これからあわせます。

$ date
Wed Sep 27 17:39:20 JST 2017
$ sudo hwclock -w

再度読みだしてみます。

$ sudo hwclock -r
Wed 27 Sep 2017 05:39:35 PM JST  -0.667000 seconds

以上で、設定完了です。

RaspberryPiの実験と話題 > 定点カメラを作る実験

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

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