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/