1.硬件准备
1.1树莓派主机和配件
主机
SD卡8G
HDMI线用于连接显示器
USB鼠标键盘
1.2传感器
2.软件准备
2.1树莓派系统安装
最新系统地址:https://downloads.raspberrypi.org/raspbian_latest
- 推荐使用NOOBS安装系统(有recovery模式) 本文章撰写时的最新镜像
- SD卡格式化软件SDFormatterV4
- 镜像安装软件Win32DiskImager 将镜像写入SD卡,插入树莓派,通电启动,10s后进入系统。树莓派支持HDMI输出到显示器。
连接WIFI。
树莓派的root账户ssh登录设置:
首先,用pi用户登录(默认密码是raspberry)后,执行sudo passwd root命令,修改root密码;
然后,编辑/etc/ssh/sshd_config文件,找到PermitRootLogin一行;
如果之前执行过“sudo passwd –unlock root”的话,这里可能会显示“without-passwd”什么的,把这行修改为“PermitRootLogin yes”,保存退出然后重启系统,root账号应该可以直接登录了。
修改/boot/cmdline.txt
[code]dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2
rootfstype=ext4 elevator=deadline fsck.repair=yes
rootwait quiet splash plymouth.ignore-serial-consoles[/code]
(注意: /dev/mmcblk0p2可能是变动:使用NOOBS安装系统会变成/dev/mmcblk0p7,请查看/dev/目录下mmcblk0p开头的文件)
更新阿里云的镜像源
修改/etc/apt/sources.list (jessie是系统的版本号,自行对应)
[code]deb http://mirrors.aliyun.com/raspbian/raspbian/ jessie main non-free contrib
deb-src http://mirrors.aliyun.com/raspbian/raspbian/ jessie main non-free contrib[/code]
执行更新命令
[bash]sudo apt-get update
sudo apt-get upgrade[/bash]
修正时区
[bash]sudo dpkg-reconfigure tzdata[/bash]
2.2传感器调试
安装WiringPi2和依赖插件python-aqi
[bash]sudo apt-get install python-dev python-pip
sudo pip install wiringpi2
sudo pip install python-aqi[/bash]
检验安装成功(输出2即为成功)
[bash]sudo python
import wiringpi
wiringpi.piBoardRev()[/bash]
3.数据准备
3.1数据监控
安装supervisor
[bash]sudo apt-get install supervisor[/bash]
安装apache mysql php
[bash]sudo apt-get install apache2
sudo apt-get install mysql-server
sudo apt-get install php5 php5-mysql[/bash]
3.2数据上传云端
p.s.
9 遇到unable to determine hardware version. i see hardware bcm2835的解决方法,来自https://github.com/WiringPi/WiringPi-Python/issues/47
9.1手动编译wiringPi
[bash]$ git clone https://github.com/WiringPi/WiringPi-Python.git
$ cd WiringPi-Python
$ rm -rf WiringPi
$ git clone https://github.com/WiringPi/WiringPi.git[/bash]
9.2编辑WiringPi-Python/setup.py
将第7行换成第8、9行
将第14行换成第15行
[python]
— setup.py.orig 2017-03-28 19:53:55.210068570 +0900
+++ setup.py 2017-03-28 19:53:58.190070005 +0900
@@ -12,12 +12,13 @@
_wiringpi = Extension(
‘_wiringpi’,
include_dirs=[‘WiringPi/wiringPi’,’WiringPi/devLib’],
– sources=sources
+ sources=sources,
+ extra_link_args=[‘-lcrypt’, ‘-lrt’]
)
setup(
name = ‘wiringpi’,
– version = ‘2.32.1’,
+ version = ‘2.44’,
author = "Philip Howard",
author_email = "phil@gadgetoid.com",
url = ‘https://github.com/WiringPi/WiringPi-Python/’,
[/python]
9.3继续执行$ cd WiringPi
[bash]$ sudo ./build
$ cd ..
$ swig2.0 -python wiringpi.i
$ sudo python setup.py install[/bash]
连接wifi
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
新建文件
network={
ssid=”mhome”
key_mgmt=WPA-PSK
psk=”xxxx”
}
sudo nano /boot/config.txt
hdmi_group=2
hdmi_mode=16
sudo vim /etc/apt/sources.list
注销原来的内容,新增如下内容
deb http://mirrors.aliyun.com/raspbian/raspbian/ buster main non-free contrib
deb-src http://mirrors.aliyun.com/raspbian/raspbian/ buster main non-free contrib
sudo vim /etc/apt/sources.list.d/raspi.list
注销原来的内容,新增如下内容
deb http://mirrors.aliyun.com/raspbian/raspbian/ buster main
deb-src http://mirrors.aliyun.com/raspbian/raspbian/ buster main
然后更新系统即可
sudo apt-get update && apt-get upgrade -y