本书源码
2】www.wiley.com/go/pythonraspi
第1章:启航
打印内核信息 dmesg
打印系统日志 cat /var/log/syslog
轻量级X11桌面 LXDE
启动命令 startx
修改配置 sudo raspi-config
安装软件
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install synaptic
sudo synaptic
绘图 turtle
第2章:编程指南
python的建议模块 import this
第4章:图形界面
from PySide.QtCore import *
from PySide.QtGui import *
from PySide.QtWebKit import *
第5章:搭建游戏
sudo apt-get install libsdl-dev libsdl-image1.2-dev \
libsdl-mixer1.2-dev libsdl-ttf2.0-dev libsmpeg-dev \
libportmidi-dev libavformat-dev libswscale-dev \
mercurial python3-dev
hg clone https://bitbucket.org/pygame/pygame
cd pygame
python3 setup.py build
sudo python3 setup.py install
import pygame
音乐 import pygame.mixer
物理库 PyMunk
pygame原点在左上角,pymunk在左下角
第6章:OpenGL
wget https://github.com/stephanh42/rpigl
unzip rpigl-master.zip
cd rpigl-master
python3 setup.py build
sudo python3 setup.py install
cd demos
python3 bumpedspere.py
转换mp3成wav
sudo apt-get install mpg123
mpg123 -w out.wav input.mp3
第7章:网络
查看网络 ifconfig
import socket
twitter API:github.com/sizohsix/twitter
天气预报 OpenWeatherMap.org
动态内容(支持模板)
sudo apt-get install python3-tornado
import tornado.ioloop
import tornado.web
subprocess模块
第8章:我的世界
在 http://pi.minecraft.net 下载 minecraft-pi-0.1.1.tar.gz
tar zxvf minecraft-pi-0.1.1.tar.gz
mcpi/minecraft-pi
从本书网站下载 chapter8-minecraft.tar.gz ,tar zxvf
import minecraft
mc = minecraft.Minecraft.create()
mc.player.setPos(10,10,10)
第9章:多媒体
sudo apt-get install libportaudio0 libportaudio2 libportaudiocpp0 \
portaudio19-dev python3-setuptools python3-pip
sudo pip-3.2 install pyaudio
import pyaudio
import wave
摄像头
import pygame.camera
sudo apt-get install python-opencv libopencv-core-dev
raspistill -o test.png
import subprocess
subprocess.call(['raspistill','-o','test.png'])
raspistill -w 200 -h 200 -co 90 -n -t 1 -ifx sketch -o test.png
第10章:脚本
import subprocess
p = subprocess.Popen(['raspistill','-o','test.png'])
text = p.stdout.read().decode()
text.splitlines()
from optparse import OptionParser
ssh-keygn -t rsa
scp location1 usr@192.192.192.192:location2
第11章:硬件接口
sudo pip-3.2 install RPi.GPIO
import RPi.GPIO as GPIO
dir(GPIO)
www.penguintutor.com/electronics/
GPIO.setmode(GPIO.BCM)
SPI:chapter11-spiadc.py
I2C:github.com/quick2wire/quick2wire-python-api
串口:
sudo pip install pyserial
import serial
第12章:测试与调试
import unittest
class Tests(unittest.TestCase):
python3 file.py -v