关于树莓派
树莓派 是一个只有信用卡大小的计算机。连接显示器、键盘、鼠标、网络后,就是一台完整的计算机。当然性能不好,也不好用,但好玩、可玩。
作为「程序猿要从小培养」这个信条的实践者,树莓派也被应用于儿童编程教育。
去掉几乎所有外设接口的核心板 raspberry-zero 只有完整版的 1/3 大小,适合作为物联网的终端数据采集设备。
快速入门
没有外接显示器、没有键盘、没有鼠标的情况下如何使用树莓派?
至少要有一根网线接入局域网,通过 ssh 远程控制。没有显示器也就无法通过「安装向导」来安装操作系统,所以必须制作一张特殊的启动卡:
制作 boot sdcard 以安装操作系统(针对 MAC)
参考 COMMAND LINE 这一小节。
ssh 远程操作
使用 $ arp -a
命令列出的局域网设备 ?(192.168.0.*)
,并没有看到类似 raspberrypi.home (192.168.1.8)
。既然无法识别树莓派(树莓派的网口灯是绿色,所以应该是已经联网了),只能挨个 IP 测试:
$ arp -a
? (192.168.0.1) at c8:3a:35:5c:ad:c8 on en0 ifscope [ethernet]
? (192.168.0.103) at b8:27:eb:d9:ac:2e on en0 ifscope [ethernet]
$ ssh [email protected]
ssh: connect to host 192.168.0.1 port 22: Network is unreachable
$ ssh [email protected]
The authenticity of host '192.168.0.103 (192.168.0.103)' can't be established.
ECDSA key fingerprint is SHA256:6zCLSeIvX4Cy55dK3mdnWznXfIidzKcCkxJVkuGJHkA.
Are you sure you want to continue connecting (yes/no)? yes
此处输入 yes,继续:
Warning: Permanently added '192.168.0.103' (ECDSA) to the list of known hosts.
[email protected]'s password:
此处输入默认密码 raspberry,成功登录 raspberry ;-))
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Fri Feb 26 02:21:14 2016
[email protected]:~ $ ls
Desktop Documents Downloads Music Pictures Public Templates Videos python_games
虽然安装的是 raspbian-jessie.img,但目前来看和 Ubuntu 某些方面一致,比如包管理工具都是 apt-get
,接下来安装 VNC 和 Camera 时会用到。
https://www.raspberrypi.org/forums/viewtopic.php?f=91&t=74176
为 Raspberry 安装 vnc service
除了命令行,还可以通过 VNC。使用 官网给出的方法 时遇到了如下问题:
[email protected]:~ $ tightvncserver
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LC_CTYPE = "UTF-8",
LANG = "en_GB.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to a fallback locale ("en_GB.UTF-8").
tightvncserver: Could not create /home/pi/.vnc.
$ sudo locale-gen
$ sudo dpkg-reconfigure locales
执行第二条命令时会弹出「Configuring locales」的对话框,勾选需要的,然后「Ok」:
再次启动 tightvncserver 就 OK 了,然后输入密码,正常启动应该会看到 Log file is /root/.vnc/raspberrypi:1.log
:
[email protected]:~ $ sudo tightvncserver
You will require a password to access your desktops.
Password:
Verify:
Would you like to enter a view-only password (y/n)? n
xauth: file /root/.Xauthority does not exist
New 'X' desktop is raspberrypi:1
Creating default startup script /root/.vnc/xstartup
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/raspberrypi:1.log
with full HD resolution:
[email protected]:~ $ sudo vncserver -kill :1
Killing Xtightvnc process ID 2350
[email protected]:~ $ sudo vncserver :1 -geometry 1920x1080 -depth 24
New 'X' desktop is raspberrypi:1
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/raspberrypi:1.log
在 MAC 使用 RealVNC 连接 Raspberry VNC Service
https://www.raspberrypi.org/documentation/remote-access/vnc/mac.md
使用树莓派摄像头模块
https://www.raspberrypi.org/documentation/usage/camera/README.md
拍照
定时拍照
录视频
实时监控
存储空间不够!
[email protected]:~ $ raspistill -o cam.jpg
mmal: Unable to write buffer to file - aborting
[email protected]:~ $ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/root 3.6G 3.5G 0 100% /
[email protected]:~ $ ls /u-bash: cannot create temp file for here-document: No space left on device
-bash: cannot create temp file for here-document: No space left on device
解决办法:sudo raspi-config
,then select “expand_rootfs”。
https://steve0hh.wordpress.com/2013/02/10/raspberry-pis-no-space-left-on-device-error-message/
[email protected]:~ $ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/root 29G 3.5G 24G 13% /