2014年12月9日 星期二

無線網路設定

  • sudo iwlist wlan0 scan | grep SSID
  • sudo apt-get install wpasupplicant
  • sudo vim /etc/network/interfaces
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp

auto wlan0
allow-hotplug wlan0
iface wlan0 inet dhcp

#wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
#iface default inet dhcp

wpa-conf /etc/wpa.conf
  • sudo vim /etc/wpa.conf
network={  ssid="bitch"  proto=RSN  key_mgmt=WPA-PSK  pairwise=CCMP TKIP  group=CCMP TKIP  psk="lhucinf305"}

2014年10月30日 星期四

thread

import os
import time
import subprocess
import multiprocessing
import thread

def two(c,a,t):
        st = 'sudo python ./'+c+'.py -a '+a+' '+t
        subprocess.call(st.split())



thread.start_new_thread( two, ("c","12.5", "1", ) )
thread.start_new_thread( two, ("b","12.5", "1", ) )
time.sleep(2)
os.system("sudo python ./c.py -a 7.5 1")
os.system("sudo python ./b.py -a 7.5 1")

2014年10月21日 星期二

Pi Control Servo

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)
GPIO.setup(4, GPIO.OUT)
GPIO.setup(17, GPIO.OUT)
GPIO.setup(18, GPIO.OUT)

a=GPIO.PWM(4,50)
a.start(5)

b=GPIO.PWM(17,50)
b.start(5)

c=GPIO.PWM(18,50)
c.start(5)

while True:
        #c.ChangeDutyCycle(2.5)
        a.ChangeDutyCycle(3)
        b.ChangeDutyCycle(3)
        c.ChangeDutyCycle(3)
        print'0'
        time.sleep(1)
        a.ChangeDutyCycle(7.5)
        b.ChangeDutyCycle(7.5)
        c.ChangeDutyCycle(7.5)
        print'90'
        time.sleep(1)
        a.ChangeDutyCycle(10)
        b.ChangeDutyCycle(10)
        c.ChangeDutyCycle(10)
        print'180'
        time.sleep(1)

Pi Use RX/TX

import serial, time
import RPi.GPIO as GPIO


GPIO.setmode(GPIO.BCM)
GPIO.setup(4, GPIO.OUT)

a=GPIO.PWM(4,50)
a.start(5)

piw = serial.Serial('/dev/ttyAMA0', 115200, timeout=1)

piw.open()

try:
        while 1:
                response = 'no'
                response = piw.readline()
                if response == 'pi':
                        a.ChangeDutyCycle(99)
                        print'ON'+response
                else:
                        a.ChangeDutyCycle(0)
                        print'off'+response
except KeyboardInterrupt:
    piw.close()



https://github.com/lurch/rpi-serial-console
sudo rpi-serial-console disable
關掉才能傳輸

參考:
http://pyserial.sourceforge.net/shortintro.html
https://mail.python.org/pipermail/python-list/2009-October/555361.html

2014年10月15日 星期三

The Raspberry Pi Contorl Servo Motors

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)
GPIO.setup(4, GPIO.OUT)
GPIO.setup(18, GPIO.OUT)
GPIO.setup(22, GPIO.OUT)

a=GPIO.PWM(4,50)
a.start(5)

b=GPIO.PWM(18,50)
b.start(5)

c=GPIO.PWM(22,50)
c.start(5)

while True:
        a.ChangeDutyCycle(2.5)
        c.ChangeDutyCycle(2.5)
        print'5'
        time.sleep(2)
        a.ChangeDutyCycle(7.5)
        print'10'
        time.sleep(2)
        a.ChangeDutyCycle(12)
        print'15'
        time.sleep(2)

2014年10月6日 星期一

webcam server

lsusb
sudo apt-get update

cd ~
mkdir tmp
cd tmp
sudo apt-get install subversion
svn co https://svn.code.sf.net/p/mjpg-streamer/code/mjpg-streamer/ mjpg-streamer
cd mjpg-streamer

apt-cache search libjpeg
sudo apt-get install libjpeg8-dev
sudo apt-get install imagemagick

./mjpg_streamer -i "./input_uvc.so" -o "./output_http.so -w ./www"

MJPG Streamer Version: svn rev:
i: Using V4L2 device.: /dev/video0
i: Desired Resolution: 640 x 480
i: Frames Per Second.: 5
i: Format…………: MJPEG
o: HTTP TCP port…..: 8080
o: username:password.: disabled
o: commands……….: enabled

I have seen some good results with this
./mjpg_streamer -i "./input_uvc.so -n -f 15 -r 640x480" -o "./output_http.so -n -w ./www"
but even a much higher resolution didn’t impact the actually observed frame-rate all that much:
./mjpg_streamer -i "./input_uvc.so -n -f 15 -r 1280x960" -o "./output_http.so -n -w ./www"


1
<img alt="" src="http://phobos:8080/?action=stream" width="1280" height="960" />


http://wolfpaulus.com/jounal/embedded/raspberrypi_webcam/
http://rexkingworld.blogspot.tw/2013/12/raspberry-pi-webcam-mjpeg2-webcam-server.html

Raspberry Pi Cluster

How To Make A Cluster Computer (Part 1)

https://www.youtube.com/watch?v=1R0UgIgcb5g

How To Make A Cluster Computer (Part 2)

https://www.youtube.com/watch?v=lHmFRlETTcQ


The RPiCluster


https://www.youtube.com/watch?v=i_r3z1jYHAc

raspberry pi cluster Methods 

==>>http://likemagicappears.com/projects/raspberry-pi-cluster/
------------------------------------------------------------------------------------------------------------
http://my.oschina.net/jobinson99/blog/229421
http://www.southampton.ac.uk/~sjc/raspberrypi/pi_supercomputer_southampton.htm
http://raspberrywebserver.com/raspberrypicluster/raspberry-pi-cluster.html
http://raspberrywebserver.com/raspberrypicluster/raspberry-pi-server-cluster-tests.html
https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/distributed-computing/

2014年9月30日 星期二

pyserial 連線 USB and GPIO

安裝
sudo wget https://raw.githubusercontent.com/lurch/rpi-serial-console/master/rpi-serial-console -O /usr/bin/rpi-serial-console && sudo chmod +x /usr/bin/rpi-serial-console

查看狀態
rpi-serial-console status

pi與外面溝通
sudo rpi-serial-console disable

putty登入pi
sudo rpi-serial-console enable




http://pyserial.sourceforge.net/

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 046e:52c2 Behavior Tech. Computer Corp.
Bus 001 Device 005: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port

dmesg
[    3.918608] usb 1-1.3: Manufacturer: Prolific Technology Inc.
[    4.381888] udevd[156]: starting version 175
[    5.663024] usbcore: registered new interface driver usbserial
[    5.849718] usbcore: registered new interface driver usbserial_generic
[    6.011840] usbserial: USB Serial support registered for generic
[    6.144607] usbcore: registered new interface driver pl2303
[    6.369701] usbserial: USB Serial support registered for pl2303
[    6.576284] pl2303 1-1.3:1.0: pl2303 converter detected
[    6.804671] bcm2708-i2s bcm2708-i2s.0: Failed to create debugfs directory
[    6.845768] usb 1-1.3: pl2303 converter now attached to ttyUSB0
[   10.238043] EXT4-fs (mmcblk0p2): re-mounted. Opts: (null)
[   10.734688] EXT4-fs (mmcblk0p2): re-mounted. Opts: (null)

>>> import serial
>>> device=serial.Serial()
>>> device.timeout=500
>>> device.baudrate=115200
>>> device.port=1
>>> device.open()
>>>
>>> while(1):
>>>     x=device.read(1)
>>>     print ord(x[0])
>>>

>>> device.close()


  apt-get install minicom
# minicom -s
   Serial port setup [Enter]
    +-------------------------------------------------------------+
    | A -    Serial Device      : /dev/ttyUSB0                    |
    | B - Lockfile Location     : /var/lock                       |
    | C -   Callin Program      :                                 |
    | D - Callout Program      -:                                 |
    | E -    Bps/Par/Bits       : 115200 8N1                      |
    | F - Hardware Flow Control : No                              |
    | G - Software Flow Control : No                              |
    |                                                             |
    |    Change which setting?                                    |
    +-------------------------------------------------------------+
   Save setup as dfl
   Exit from Minicom

ctrl + a
q(退出)

//USB
minicom -b 115200 -o -D /dev/ttyUSB0

//GPIO
minicom -b 115200 -o -D /dev/ttyAMA0

2014年9月29日 星期一

Rpi 顯示問題與設定

config.txt
http://elinux.org/RPi_config.txt#Video_mode_options

hdmi_drive=2     #Normal HDMI mode (Sound will be sent if supported and enabled)
hdmi_group=2
hdmi_mode=16   #1024x768  60Hz  和 1080P
hdmi_force_hotplug=1

raspi-config 
info:系統設置工具的信息
expand-rootfs:擴大Linux系統root分區的大小
overscan:使能overscan
configure_keyboard:選擇鍵盤佈局(Raspberry Pi鍵盤佈局默認英式,這裡可以調整)
change_pass:修改用戶密碼(Raspbian默認用戶名為pi,密碼raspberry)
change_local:修改輸入法(可以修改成中文輸入,不過先要安裝字體,暫時不修改)
change_timezone:修改系統時區(Raspberry Pi沒有實時時鐘,靠網絡同步時間)
memory_split:修改內存劃分(一共256MB內存,修改ARM處理器和圖形加速器的分配)
ssh:使能ssh服務器(建議開啟,這樣可以通過ssh訪問Raspberry Pi)
boot_behaviour:設置系統啟動進入命令行界面還是圖形界面(在命令行模式輸入startx可以進入圖形界面)

update:可以在線升級