目录

树莓派

树莓派

1 概述

1.1 树莓派zero w

1.2 安装系统

#MAC 给sd卡安装系统
下载系统镜像地址: https://www.raspberrypi.org/downloads/
我选择radpbian最新版
wget http://120.52.51.14/director.downloads.raspberrypi.org/raspbian_lite/images/raspbian_lite-2018-11-15/2018-11-13-raspbian-stretch-lite.zip  ~/download/

unzeip  raspbian_lite-2018-11-15/2018-11-13-raspbian-stretch-lite.zip

-rw-r--r--@ 1    1.7G Nov 13 14:02 2018-11-13-raspbian-stretch-lite.img
查看sd卡底盘分区

-w133

-w924 -w420 -w473

➜  df -h
➜  diskutil unmount /dev/disk2s1
Volume RASPBIAN on disk2s1 unmounted
➜ diskutil list

#使用dd命令将系统镜像写入,需要特别特别注意disk后的数字,不能搞错!
(说明:/dev/disk2s1是分区,/dev/disk2是块设备,/dev/rdisk2是原始字符设备)
# 用dd写系统到sd卡
➜  sudo dd bs=4m if=2018-11-13-raspbian-stretch-lite.img of=/dev/rdisk2
Password:
445+0 records in
445+0 records out
1866465280 bytes transferred in 27.727287 secs (67315106 bytes/sec)

➜ diskutil unmountDisk /dev/disk2

将sd卡接入树莓派这个位置,按进去卡槽卡紧便可

-w761

1.3 usb/以太网方式链接电脑 (mac os)

修改两个配置文件
#1. /Volumes/boot/config.txt 在文件末尾添加一行 dtoverlay=dwc2
#2. /Volumes/boot/cmdline.txt  rootwait,在后面插入 modules-load=dwc2,g_ether
#3. 在根目录创建一个名为 ssh 的目录

ssh pi@raspberrypi.local
Username: pi
Password: raspberry

1.4 无屏模式wifi 配置

首先搜索Realtek驱动:
apt-cache search realtek

默认网络不通,先下载deb,拷贝到树莓派
https://opsx.alibaba.com/mirror/search?q=ras&lang=zh-CN
下载后从宿主机拷贝到树莓派系统里面.
#安装
pi@raspberrypi:~ $ sudo dpkg -i  /tmp/firmware-realtek_20190114-1_all.deb
dpkg: warning: downgrading firmware-realtek from 1:20161130-3+rpt4 to 20190114-1
(Reading database ... 34605 files and directories currently installed.)
Preparing to unpack .../firmware-realtek_20190114-1_all.deb ...
Unpacking firmware-realtek (20190114-1) over (1:20161130-3+rpt4) ...
Setting up firmware-realtek (20190114-1) ...
update-initramfs: deferring update (trigger activated)
Processing triggers for initramfs-tools (0.130) ...

-w1391

pi@raspberrypi:~ $ iwlist wlan0 scan 【扫描附近wifi热点】
#修改配置文件
pi@raspberrypi:~ $ sudo cat /etc/network/interfaces
source-directory /etc/network/interfaces.d
allow-hotplug wlan0
auto wlan0

iface wlan0 inet dhcp
#ssid和pass 可以双引号,也可以不加双引号
wpa-ssid xxxxx
wpa-psk xxxxx

#重启网卡
pi@raspberrypi:~ $ sudo ifdown wlan0
pi@raspberrypi:~ $ sudo ifup wlan0
Internet Systems Consortium DHCP Client 4.3.5
Copyright 2004-2016 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/

Listening on LPF/wlan0/b8:27:eb:1c:78:28
Sending on   LPF/wlan0/b8:27:eb:1c:78:28
Sending on   Socket/fallback
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 8
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 18
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 15
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 15
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 5
No DHCPOFFERS received.
No working leases in persistent database - sleeping.
Internet Systems Consortium DHCP Client 4.3.5
Copyright 2004-2016 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/

Listening on LPF/wlan0/b8:27:eb:1c:78:28
Sending on   LPF/wlan0/b8:27:eb:1c:78:28
Sending on   Socket/fallback
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 5
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 14
DHCPREQUEST of 10.111.161.210 on wlan0 to 255.255.255.255 port 67
DHCPOFFER of 10.111.161.210 from 10.111.160.1
DHCPACK of 10.111.161.210 from 10.111.160.1
Too few arguments.
Too few arguments.
bound to 10.111.161.210 -- renewal in 37422 seconds.


pi@raspberrypi:~ $ ping baidu.com
PING baidu.com (123.125.115.110) 56(84) bytes of data.
64 bytes from 123.125.115.110 (123.125.115.110): icmp_seq=1 ttl=51 time=52.7 ms
64 bytes from 123.125.115.110 (123.125.115.110): icmp_seq=2 ttl=51 time=8.41 ms
64 bytes from 123.125.115.110 (123.125.115.110): icmp_seq=3 ttl=51 time=8.37 ms

1.5 修改时区

pi@raspberrypi:~ $ sudo mv /etc/localtime /etc/localtime.bak
pi@raspberrypi:~ $ sudo ln -s  /usr/share/zoneinfo/Asia/Shanghai  /etc/localtime
pi@raspberrypi:~ $ sudo ls -al /etc/localtime
lrwxrwxrwx 1 root root 33 Mar 18 21:06 /etc/localtime -> /usr/share/zoneinfo/Asia/Shanghai
pi@raspberrypi:~ $ date
Mon 18 Mar 21:07:06 CST 2019

1.5 提升swap

pi@raspberrypi:/var $ sudo swapoff /var/swap
pi@raspberrypi:/var $ free
              total        used        free      shared  buff/cache   available
Mem:         443872       32012      119500        5920      292360      354264
Swap:             0           0           0
 
pi@raspberrypi:/var $ sudo dd if=/dev/zero of=swap bs=1M count=10240
10240+0 records in
10240+0 records out
10737418240 bytes (11 GB, 10 GiB) copied, 553.609 s, 19.4 MB/s

pi@raspberrypi:/var $ sudo mkswap swap
Setting up swapspace version 1, size = 10 GiB (10737414144 bytes)
no label, UUID=f05f671a-8650-4b43-8ac4-3de93b712695

pi@raspberrypi:/var $ sudo swapon /var/swap

pi@raspberrypi:/var $ swapon -s
Filename				Type		Size	Used	Priority
/var/swap                              	file    	10485756	0	-2

pi@raspberrypi:/var $ free -g
              total        used        free      shared  buff/cache   available
Mem:              0           0           0           0           0           0
Swap:             9           0           9


pi@raspberrypi:/var $ sudo cat /etc/fstab
...
#添加swap开启自挂载
/var/swap    swap     swap    defaults      0 1

1.6 创建内存盘

#将频繁读写的缓存等小文件放到内存,减少对SD卡的寿命消耗
mkdir /ram
mount -t tmpfs -o size=10m,mode=0777 tmpfs /ram

1.7 查找局域网树莓派的ip地址

方法一
➜  ~ ping raspberrypi.local
PING raspberrypi.local (10.111.161.210): 56 data bytes
64 bytes from 10.111.161.210: icmp_seq=0 ttl=64 time=86.265 ms
64 bytes from 10.111.161.210: icmp_seq=1 ttl=64 time=171.123 ms
64 bytes from 10.111.161.210: icmp_seq=2 ttl=64 time=7.914 ms

ssh pi@10.111.161.210

方法二:
sudo nmap -sP 192.168.1.0/24 | awk '/^Nmap/{ip=$NF}/B8:27:EB/{print ip}'

1.8 vnc

sudo raspi-config
#选择5

-w561

-w562

-w424

-w422

-w560

-w415

下载vnc客户端:
#https://www.realvnc.com/en/connect/download/vnc/macos/

vncserver

-w1149

-w593 -w123 -w893

输入用户名密码,便可登录

2

2.1 type-c

2.2 usb