1. 基本安装(树莓官网下载镜像)
1).格式化内存卡
2).使用 win32diskimager.exe 将系统写入内存卡
3).默认用户及密码为 pi
4).系统配置 sudo raspi-config
配置用户、开机自动登录、键盘、中文、时区、ssh 等
键盘配置:
raspberry
1.sudo raspi-config
2.Localiscation Options
3.Change keyboard Layout
4.Generic 105-key(Intl)pc
5.other
6.English(US)
7.English(US)-English(US,alternative international)
8.The default for the keyboard layout
9.No compose key
10.No
中文需要安装汉化包支持
sudo apt-get -y install ttf-wqy-zenhei
2. 命令行配置网络
sudo iwlist wlan0 scan
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf 在文件底部加入
network={
扫描可用无线网络
ssid="testing"
psk="testingPassword"
}
sudo wpa_cli -i wlan0 reconfigure 重启网络接口
3. 配置静态 ip , sudo vi /etc/dhcpcd.conf 加入如下内容,reboot
#网线
interface eth0
static ip_address=192.168.8.200
static routers=192.168.8.1
static domian_name_servers=192.168.8.1
#无线
interface wlan0
static ip_address=192.168.8.200
static routers=192.168.8.1
static domian_name_servers=192.168.8.1
4. 安装 pi4j
https://git.drogon.net/?p=wiringPi;a=summary
1). Pi4j 是依赖 wiringpi 封装而成的,安装之前,需要 jdk 及 wiringpi
wiringpi 地址:
解压后进入目录 执行 ./build
验证 wiringPi 的是否安装成功,输入 gpio -v
会在终端中输出相关 wiringPi 的信息。否则安装失败。
2). 安装 Pi4j 执行以下命令
curl -s get.pi4j.com | sudo bash
安装的库在/opt/pi4j/lib 目录,官方 demo 在/opt/pi4j/examples
可以编译源码 ./build
执行某个示例 ./run BlinkGpioExample
&&
java
-jar
5. 开机自启动脚本或命令
第一种方式:
sudo vi /etc/rc.local 在文件 exit 之前加入
cd
/home/pi/app/sensor_collector-0.0.1-SNAPSHOT
sensor_collector-0.0.1-SNAPSHOT.jar
第二种方式(推荐):
在/etc/init.d 加入应用脚本文件(例:sensor),赋予 755 权限
示例脚本内容可模仿下页
测试脚本文件(测试成功后请关闭应用)
sudo /etc/init.d/sensor start
加入开机自启动
cd /etc/init.d
sudo update-rc.d sensor defaults
取消开机启动
sudo update-rc.d -f sensor remove
6. 笔记本使用远程桌面连接树莓派(树莓派安装 xrdp)
sudo apt-get -y install xrdp
7. …
8. …
示例脚本:
#!/bin/sh -e
### BEGIN INIT INFO
# Provides:
# Required-Start:
# Required-Stop:
# Default-Start:
# Default-Stop:
# Short-Description: autostartup of sensor for RaspberryPi
### END INIT INFO
sensor
$network $remote_fs $local_fs
$network $remote_fs $local_fs
2 3 4 5
0 1 6
NAME=sensor
case "$1" in
start)
echo "Starting $NAME..."
cd
/home/pi/app/sensor_collector-0.0.1-SNAPSHOT && java
-jar
sensor_collector-0.0.1-SNAPSHOT.jar &
echo "."
;;
stop)
;;
restart)
echo "Stoping $NAME..."
pkill -f $NAME
echo "."
$0 stop && sleep 2 && $0 start
;;
echo "Usage: $0 {start|stop|restart}"
exit 1
;;
*)
esac
exit 0