人文生活玩转树莓派树莓派

树莓派学习资源汇总

2017-11-09  本文已影响243人  afbbcde7fa3e

软件与工具资源

树莓派操作使用

[USB]
path=/media/NAS
comment= NAS driver
valid users=xxx
writeable=yes
browseable=yes
create mask=0777
public=yes

samba restart

树莓派硬件

树莓派快速使用

sudo vim /etc/motion/motion.conf
#将 daemon off改为on
#webcam_localhost=on改为off
sudo vim /etc/default/motion 
#将sart_motion_daemon=no 改为yes

Linux命令参考

sudo chmod +x /etc/init.d/my_server (为文件添加运行权限)

Python机器视觉

sudo apt-get update
sudo apt-get install ipython python-opencv python-scipy
sudo apt-get install python-numpy python-setuptools python-pip
sudo pip install svgwrite
sudo pip install https://github.com/sightmachine/SimpleCV/zipball/master
运行simpleCV

import picamera
from SimpleCV import *

def get_camera_image():
    with picamera.PiCamera() as camera:
        camera.resolution=(1024,768)
        camera.awb_mode='off'
        camera.capture('tmp.jpg')
    return Image('tmp.jpg')

SimpleCV:1>c=Camera()
SimpleCV:2>i=c.getImage()
SimpleCV:3>i.show()
SimpleCV:4>i2=i.invert()
SimpleCV:5>i2.show()
SimpleCV:6>coins=i2.findCircle(canny=100,thresh=70,distance=15)
SimpleCV:7>coins
SimpleCV:8>coins.draw(width=4)
SimpleCV:9>coins.show()
from SimpleCV import *
c=Camera()
while True:
    i=c.getImage().invert()
    coins=i.findCircle(canny=100,thresh=70,distance=1)
    print(len(coins))

python 控制树莓派硬件

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)
GPIO.setup(18,GPIO.OUT)
try:
    while(True):
        GPIO.output(18,True)
        time.sleep(0.5)
        GPIO.output(18,False)
        time.sleep(0.5)
finally:
    GPIO.cleanup() #安全模式,使GPIO端口处于输入状态以避免短路
import RPi.GPIO as GPIO

led_pin=18
GPIO.setmode(GPIO.BCM)
GPIO.setup(led_pin,GPIO.OUT)

pwm_led=GPIO.PWM(led_pin,500)
pwm_led.start(100)

while True:
    duty_s=input("Brightness input (0-100):")
    duty=int(duty_s)
    pwm_led.ChangeDutyCycle(duty)

from tkinter import *
import RPi.GPIO as GPIO
import time

led_pin=18

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

class App:
    def __init__(self,master):
        frame=Frame(master)
        frame.pack()
        self.check_var=BooleanVar()
        check=Checkbutton(frame,text='Pin 18',
            command=self.update,variable=self.check_var,
            onvalue=True,offvalue=False)
        check.grid(row=1)
    def update(self):
        GPIO.output(led_pin,self.check_var.get())

root=Tk()
root.wm_title('On/Off Switch')
app=App(root)
root.geometry("200x50+0+0")
root.mainloop()

import RPi.GPIO as GPIO
import time

led_pin=18

GPIO.setmode(GPIO.BCM)

#回调函数
def my_callback(channel):
    print('You pressed the button')

GPIO.setup(led_pin,GPIO.IN,pull_up_down=GPIO.PUD_UP)
#bounce time是GPIO库内置的防抖功能
GPIO.add_event_detect(led_pin,GPIO.FALLING,callback=my_callback,bouncetime=100)

i=0
while True:
    i=i+1
    print(i)
    time.sleep(1)

from rrb3 import *
import time

rr=RRB3(12.0,12.0) # battery,motor

try:
    while True:
        delay=input("Delay milliseconds between steps:")
        steps=input("How many steps forward?")
        rr.step_forward(int(delay)/1000.0,int(steps))
        steps=input("How many steps backward?")
        rr.step_reverse(int(delay)/1000.0,int(steps))
finally:
    GPIO.cleanup()
import pygame
import sys
from pygame.locals import *

pygame.init()
screen=pygame.display.set_mode((640,480))
pygame.mouse.set_visible(0)

while True:
    for event in pygame.event.get():
        if event.type==QUIT:
            sys.exit()
        if event.type==KEYDOWN:
            if chr(event.key)=='q':
                sys.exit()
            else:
                print("Code: "+str(event.key)+ " Char: "+chr(event.key)+"\n")
        if event.type==MOUSEMOTION:
            print("Mouse:(%d,%d)"%event.pos)

物联网与程序示例

上一篇 下一篇

猜你喜欢

热点阅读