树莓派入坑指南

树莓派入坑指南,自己踩过的一些坑,在此处记录分享一下,并附上处理方法。不定期更新

0.初始化相关
 1./boot/config.txt --显示初始化相关
 2./etc/lightdm/lightdm.conf    --屏保睡眠设置
 3./etc/network/interfaces  --网络设置
 4./etc/resolv.conf --DNS设置
 5./etc/rc.local    --自启动脚本执行
 6.~/.config  --自定义图形化应用程序自动启动
 7./etc/resolvconf.conf --自定义DNS服务器

0.初始化相关

1.系统安装:官网现在推荐使用noobs这个工具,是树莓派官方推荐的系统安装方式,使用非常简单,下载后是一个压缩包,解压后放在格式化好的tf卡内即可启动,图形化的界面,选择需要安装的系统即可,或者是用磁盘映像,直接写入到tf卡也是一样的.都非常简单需要用的工具:SD Formatter,NOOBS,Win32 Disk Imager.


2.系统初始化:进入系统后默认是英国英文,键盘布局之类都和国内不同,需要修改配置,然后系统默认没有中文支持,需要配置和安装字体。

sudo passwd

设置su的密码。设置后, 可以运行

sudo raspi-config

进行配置,可以设置的项目都比较简单基本可以直接看懂,包括树莓派的超频以及显存分配都可以直接在这里配置,这里介绍一下语言配置Internationalisation Options,可以设置地区,时区以及键盘布局。这里需要增加美国英语的支持以及中文支持,需要加选,

 en_US.UTF-8 UTF-8
 zh_CN GB2312
 zh_CN.GBK GBK
 zh_CN.UTF-8 UTF-8

随后会提示设置系统的默认语言,推荐选择en_US,然后保存退出,然后设置时区以及键盘布局,键盘布局需要设置成en_US

然后重启

sudo reboot

重启后,树莓派不会默认安装设定语言的字体,需要自己安装:

sudo apt-get install ttf-wqy-zenhei

如果需要安装中文输入法:

sudo apt-get install scim-pinyin

1.config.txt

配置树莓派基本的显示和初始化相关的基本配置,包括分辨率,屏幕旋转,HDMI输出边界检测,和睡眠时间等等.
display_rotate配置表示屏幕顺时针旋转如display_rotate=3表示顺时针旋转3*90度
overscan_left|top|righrt|buttom分别表示树莓派使用HDMI输出的时候个方向屏幕防越边界检测

# For more options and information see
# http://www.raspberrypi.org/documentation/configuration/config-txt.md
# Some settings may impact device functionality. See link above for details

# uncomment if you get no picture on HDMI for a default "safe" mode
#hdmi_safe=1

# uncomment this if your display has a black border of unused pixels visible
# and your display can output without overscan
#disable_overscan=1

# uncomment the following to adjust overscan. Use positive numbers if console
# goes off screen, and negative if there is too much border
#overscan_left=16
#overscan_right=16
#overscan_top=16
#overscan_bottom=16

# uncomment to force a console size. By default it will be display's size minus
# overscan.
#framebuffer_width=1920
#framebuffer_height=1080

# uncomment if hdmi display is not detected and composite is being output
#hdmi_force_hotplug=1

# uncomment to force a specific HDMI mode (this will force VGA)
#hdmi_group=1
#hdmi_mode=1

# uncomment to force a HDMI mode rather than DVI. This can make audio work in
# DMT (computer monitor) modes
#hdmi_drive=2

# uncomment to increase signal to HDMI, if you have interference, blanking, or
# no display
#config_hdmi_boost=4

# uncomment for composite PAL
#sdtv_mode=2

#uncomment to overclock the arm. 700 MHz is the default.
#arm_freq=800

# Uncomment some or all of these to enable the optional hardware interfaces
#dtparam=i2c_arm=on
#dtparam=i2s=on
#dtparam=spi=on

# Uncomment this to enable the lirc-rpi module
#dtoverlay=lirc-rpi

# Additional overlays and parameters are documented /boot/overlays/README

# Enable audio (loads snd_bcm2835)
dtparam=audio=on

# NOOBS Auto-generated Settings:
#display_rotate=3
display_rotate=0
hdmi_force_hotplug=1
config_hdmi_boost=4
#overscan_left=24
#overscan_right=24
#overscan_top=16
#overscan_bottom=16
disable_overscan=1
#disable_overscan=0

2./etc/lightdm/lightdm.conf

xserver-command=X -s 0 dpms

禁用屏保和休眠


3./etc/network/interfaces

树莓派的网络配置文件其中包含有线网络和wlan网络,理论上可以在此处配置IP地址和DNS服务器,但是DNS配置后从未生效过,待问题解决后更新

/etc/network/interfaces
#默认的配置文件

# interfaces(5) file used by ifup(8) and ifdown(8)

# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'

# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d

auto lo
iface lo inet loopback

iface eth0 inet manual

allow-hotplug wlan0
iface wlan0 inet manual
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

allow-hotplug wlan1
iface wlan1 inet manual
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf


设置有限网络为静态ip地址
auto ethiface eth0 inet static 
address 10.52.91.222            ## 设定的静态IP地址
netmask 255.255.255.0           ## 网络掩码
gateway 10.52.91.1              ## 网关

4./etc/resolv.conf --DNS设置

resolv.conf文件每次重新启动会重新根据配置文件初始化,所以手动设置后只会在本地系统未重启动时生效,一旦系统重启,需要重新设置。本来这个文件是不需要自己手动设置的,只是因为在/etc/network/interfaces文件中手动配置DNS服务器不生效,所以设置此文件临时起效,待问题解决后更新.
设置DNS的方式:

sudo echo "nameserver xxx.xxx.xxx.xxx" > /etc/resolv.conf

5./etc/rc.local

根据官方的文档资料,如果想要配置自定义的自启动的服务或者脚本,那么就是写在/etc/rc.local中 ,如果是python脚本需要在执行命令前指定python,例如:

python /home/pi/myscript.py &

6.~/.config

使用树莓派的时候遇到了这样的一个需求:需要桌面启动之后自动运行一个图形化的应用程序(我们是使用了nw.js来做轻客户端的),在这里使用/etc/rc.local是无效的,图形化程序是需要桌面启动之后才能够运行的,所以这里使用~/.config目录来达到目的,这是一个隐藏目录,需要使用ls -al来显示出来.进入后先创建一个目录:

mkdir autostart

进入目录,创建我们的自启动应用程序脚本:

sudo vi my.desktop(或sudo nano my.desktop 文件名可自定义)

写入以下内容:

[Desktop Entry]
Type=Application
Exec=你的程序启动脚本

6./etc/resolvconf.conf

使用很多种方式设置树莓派的DNS地址,但是每次系统重启之后都会被重新指定到网关地址。后来发现DNS地址可以在这个文件里手动指定:

name_servers=202.98.0.68

设置后,不会在系统重启之后重置。



作者:Eric_
链接:https://www.jianshu.com/p/68af9e3239ea
來源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值