顯示具有 raspberry pi 標籤的文章。 顯示所有文章
顯示具有 raspberry pi 標籤的文章。 顯示所有文章

2013年12月19日 星期四

ubuntu networking interface 設定


使用情境:
  • eth0固定網卡 / wlan0無線網卡 各一
  • 配置固定IP (eth0: 192.168.1.XX / wlan0: 192.168.1.YY)
  • private network : 192.168.1.XXX
  • gateway : 192.168.1.1

/etc/network/interfaces 設定檔內容:

auto lo
iface lo inet loopback
iface eth0 inet static
address 192.168.1.XX
netmask 255.255.255.0
gateway 192.168.1.1

allow-hotplug wlan0
iface wlan0 inet static
wpa 2
wpa-ssid <YOUR_SSID>
wpa-psk <YOUR_PASSWORD>
address 192.168.1.YY
netmask 255.255.255.0
gateway 192.168.1.1


*以上也適用 Raspberry Pi / Wheezy 環境

#

2013年9月22日 星期日

Raspberry Pi 安裝USB無線網卡 (Buffalo WLI-UC-GNM)

安裝USB無線網卡


執行lsub確認Raspberry Pi已經抓到USB無線網路卡。範例為Buffalo WLI-UC-GNM無線網卡。

> lsusb

執行結果:
Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 004: ID 0411:01a2 BUFFALO INC. (formerly MelCo., Inc.) WLI-UC-GNM Wireless LAN Adapter [Ralink RT8070]
確實抓到網卡(Ralink RT8070相容驅動程式)。

編輯網路介面設定檔案


> vi /etc/network/interfaces
auto lo
iface lo inet loopback

# 設定Ethernet網卡以DHCP取得IP
iface eth0 inet dhcp

# 設定Ethernet網卡以DHCP取得IP
allow-hotplug wlan0
iface wlan0 inet dhcp

# 強制網卡以WPA2方式與Wi-Fi AP連線
wpa 2

# 設定Wi-Fi AP 之SSID與密碼
wpa-ssid <<YOUR_SSID>>
wpa-psk <<YOUR_WPA2_PSK_PASSWORD>>

重新啟動networking

> service networking restart


確認網卡已配置IP

> ifconfig -a

wlan0     Link encap:Ethernet  HWaddr 10:6f:00:00:00:00
          inet addr:192.168.1.7  Bcast:192.168.255.255  Mask:255.255.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:3458 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2583 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:602575 (588.4 KiB)  TX bytes:1077331 (1.0 MiB)

已經配置 192.168.1.7 給 wlan0 無線網卡介面

#

2013年5月24日 星期五

Raspberry Pi + PIR Sensor (紅外線動作感測器) + mpg321 = 您好歡迎光臨

這範例確實是大材小用,有點拿牛刀殺雞。不過卻也是很實用又能引人注意的應用。

參考前一篇「Raspberry Pi + PIR Sensor (紅外線動作感測器) + Webcam」,只要將

dt = datetime.datetime.now().strftime("%Y%m%d-%H%M%S")
dt_filename = dt+".jpg"
fs_command = "fswebcam --background -d /dev/video0 "+dt_filename
print " ",fs_command
os.system(fs_command)

改成

fs_command = "mpg321 welcome.mp3"
print " ",fs_command
os.system(fs_command)

就能利用mpg321指令來播放歡迎光臨音效的mp3。

找不到音效檔案時,其實只要拿手邊的手機錄下語音備忘錄,就能利用家人的聲音來當作招呼聲囉。以ios錄製下的m4a格式聲音檔為例:

> ffmpeg -i welcome.m4a welcome.mp3

就能將m4a格式再轉成mp3格式來使用。


需要安裝命令列 mpg321 mp3播放器軟體的話,可以另外參考「ubuntu 文字模式下的 mp3 播放軟體」進行安裝。

#

2013年5月13日 星期一

Raspberry Pi + PIR Sensor (紅外線動作感測器) + Webcam

基本上參考 Raspberry Pi Spy的這篇文章 - Cheap PIR Sensors and the Raspberry Pi 。

紅外線動作感測器(PIR Sensor)可以視為是一個輸出 (out) 為 1 或 0的開關。PIR Sensor 的GND接到Raspberry Pi 的Pin 6(GND)、POWER接到Pin 2 (+5V)、OUT則接到Pin 26 (GPIO7)。(Raspberry Pi腳位可參考這裡)

當紅外線動作感測器偵測到有物體(人體)移動時,GPIO7的值可能就會由0轉變成為1,我們可以藉此狀態改變來達成其他應用,例如這次我們就利用紅外線偵測狀態改變,利用fswebcam來擷取一張照片。

1. 修改Raspberry Pi Spy所提供的pir_1.py如下,並記得存檔。
..
import time (新增下列兩行)
import os
import datetime
...
Previous_State=1 (新增下列五行)
dt = datetime.datetime.now().strftime("%Y%m%d-%H%M%S") dt_filename = dt+".jpg" fs_command = "fswebcam --background -d /dev/video0 "+dt_filename
print " ",fs_command os.system(fs_command)
..


2. 修改執行 pir_1.py
> sudo python pir_1.py
PIR Module Test (CTRL-C to exit)
Waiting for PIR to settle ...
  Ready
  Motion detected!
   fswebcam --background -d /dev/video0 20130513-000412.jpg
  Ready
  Motion detected!
   fswebcam --background -d /dev/video0 20130513-000418.jpg
  Ready
  ..

因為紅外線偵測到物體移動之後,才進行fswebcam來進行拍攝,所以時間差延遲可能會拍不到真正想要拍攝的移動物體。應該是不斷進行拍攝或錄影,然後在偵測物體移動發生的第 t 秒時,回頭去存下第 t-1 或 t-2 秒到第 t+1 或 t+2秒的影像,可能較能切合需要。

不過這只是拋磚引玉,一個結合紅外線動作感應器的小應用而已,更多有趣或有用的應用就有勞各位自己再去嘗試囉。

如果真對motion detection應用有興趣的話,其實可以直接參考這篇-Raspberry Pi安裝Webcam和Motion Webcam Server 就能得到不錯的效果囉。

#



2013年5月11日 星期六

Raspberry Pi 安裝 Webcam 和 Motion Webcam Server

Raspberry Pi 已支援不少 Webcam 裝置,如果您手邊的 Webcam 恰在支援名單中,那就先恭喜您。如果不在支援名單中也不用放棄,先嘗試看看再說亦不遲。

本來想要買一部Logitech C310來試看看,一個不小心在住家附近10元商店買了號稱台灣設計的V-Cool YW1210 Webcam , 還有麥克風功能 (賣場價NT$299)來試試。運氣不錯,不但插上Raspberry Pi就抓到Webcam之外,也不用再外接電源。

執行 lsusb 指令,發現了Aveo Technology Corp. 新裝置

> lsusb
Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 007: ID 1871:0142 Aveo Technology Corp.

再看看 /dev/ 下是否有video0裝置
> ls /dev/video0
/dev/video0

安裝 fswebcam 後,試著抓一張圖 test.jpg
> sudo apt-get update
> sudo apt-get upgrade
> sudo apt-get install fswebcam

> fswebcam -d /dev/video0 test.jpg
--- Opening /dev/video0...
Trying source module v4l2...
/dev/video0 opened.
No input was specified, using the first.
Adjusting resolution from 384x288 to 352x288.
--- Capturing frame...
Captured frame in 0.00 seconds.
--- Processing captured image...
Writing JPEG image to 'test.jpg'.


test.jpg
fswebcam擷存test.jpg 












安裝 motion
> sudo apt-get install motion
> mkdir /tmp/motion
> sudo chmod -R 777 /tmp/motion
> sudo chmod -R 777 /etc/motion/motion.conf

安裝成功後,開始修改 motion 相關設定檔案:
將 /etc/default/motion 檔案中的start_motion_daemon參數值改為yes
> vi /etc/default/motion

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

依照需求修改 /etc/motion/motion.conf 檔案內相關參數值
> vi /etc/motion/motion.conf
  ..
  daemon on (預設off, 設定為on時 raspberry pi 啟動自動執行motion servicedaemon)
  ..
  webcam_port 8081 (觀看webcam之listen port)
  webcam_localhost off (預設on, off取消只能從localhost觀看webcam畫面之限制)
  ..
  control_port 8080 (控制設定motion之listen port)
  control_localhost off  (預設on, off取消只能從localhost控制設定motion參數之限制)
  ..

完成相關設定後,就可以準備啟動 motion service 囉
> sudo service motion restart

開啟電腦上的瀏覽器,輸入 http://<IP>:8081/ 看到畫面就算成功囉。

另外還記得先前建立了一個 /tmp/motion 目錄嗎?目錄中儲存 .jpg或.swf就是執行 motion 時,偵測到畫面內有東西移動或光線變化時的,所擷取下來的畫面記錄檔就存在 /tmp/motion 目錄下。



* 備註:Linux UVC driver & tools (可以發現Linux其實支援幾款Aveo Webcam)

#

2013年5月8日 星期三

Raspberry Pi 安裝 USB Bluetooth Dongle

1. 安裝藍芽相關程式

> sudo apt-get update
> sudo apt-get upgrade
> sudo apt-get autoremove
> sudo atp-get install bluetooth bluez-utils blueman


2. 確認藍芽是否正常運作

> lsusb
Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 004: ID 0a5c:200a Broadcom Corp. BCM2035 Bluetooth dongle

> /etc/init.d/bluetooth status
[ ok ] bluetooth is running.


3. 掃描其他藍芽裝置

> hcitool scan

Scanning ...
        78:A3:*:*:*:22       iphone4  (找到開啟藍芽的iPhone4, 您掃描到的裝置MAC Address 78:A3:*:*:*:22應該不同)


4. Ping一下其他藍芽裝置 (本例為iPhone4)

> sudo l2ping -c 3  78:A3:*:*:*:22 
(輸入掃描到的裝置MAC Address 78:A3:*:*:*:22) 

Ping: 78:A3:B4:97:A0:22 from 00:02:*:*:*:D4 (data size 44) ...
44 bytes from 78:A3:*:*:*:22 id 0 time 204.29ms
44 bytes from 78:A3:*:*:*:22 id 1 time 89.52ms
44 bytes from 78:A3:*:*:*:22 id 2 time 80.71ms
3 sent, 3 received, 0% loss

#