admin管理员组

文章数量:1291223

树莓派基本配置

文章目录

  • 树莓派基本配置
    • 前言
    • 硬件准备
    • 树莓派刷机
    • 串口方式登录树莓派
    • 接入网络
    • ssh方式登录树莓派
    • 更换国内源
    • xrdp界面登录树莓派
    • 远程文件传输FileZilla

前言

树莓派是一款功能强大且价格实惠的小型计算机,非常适合作为学习编程、物联网项目、家庭自动化等领域的开发平台。本文将详细介绍如何从零开始配置一台树莓派3B+,包括硬件准备、刷机、串口登录、网络接入、更换国内源、SSH登录以及通过XRDP进行图形界面登录。

硬件准备

  • 树莓派3B+:具备四核CPU、1GB RAM和板载Wi-Fi及蓝牙功能。
  • SD卡:建议使用品牌如闪迪,容量至少8GB,用于存储树莓派的操作系统。
  • 读卡器:用于将SD卡连接到电脑进行刷写操作。
  • CH340 USB转串口模块(可选):如果你的电脑没有串口,或者想要更稳定的串口通信,可以考虑使用CH340模块。
  • 电源适配器:为树莓派提供稳定的5V/2A电源。
  • HDMI线(可选):用于连接显示器进行初始配置。
  • USB键盘和鼠标(可选):同样用于初始配置。## 树莓派刷机

树莓派刷机

  1. 下载镜像
    下载镜像可以选择去官网下载:https://raspberrypi/software/operating-systems/
    如果想带界面就下载带界面的,
  2. 写入镜像
    先使用SD format软件,格式化你的sd卡。再使用树莓派的烧录软件进行烧录。地址:https://www.raspberrypi/software/
  3. 配置
    打开镜像烧录工具,选择要安装的镜像,再配置WiFi信息(用来查看树莓派的IP;可以是家里的WiFi,电脑热点…)和用户信息,如图。

    配置wifi:

    开启SSH服务:

按道理这么配置没什么问题,到时候开启树莓派就可以连接到网络。
那么如果你照着做了,那么不出意外的话就要出意外了。
他并没有按照你的想法,连接上了wifi,打开了ssh服务,还是需要手动来开启。

串口方式登录树莓派

由于树莓派串口默认的是蓝牙连接的,所以我们需要断开蓝牙,打开串口连接。
将烧录完的SD卡,插回电脑。修改以下文件

cmdline.txt文件的内容修改为

dwc_otg.lpm_enable=0 console=tty1 console=serial0,115200 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait

config.txt文件内容修改为

# For more options and information see
# http://rpf.io/configtxt
# 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=1280
#framebuffer_height=720

# 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

dtoverlay=pi3-disable-bt
start_x=1
gpu_mem=128

此后将SD卡取出插到树莓派上,使用串口转ttl就可以串口登录。
连接电脑使用Moba进行串口连接。

接入网络

树莓派连接网络,你可以通过用HDMI线连接显示屏后,通过鼠标键盘的方式对其进行网络配置。可以通过以下方法进行。

 sudo nano /etc/wpa_supplicant//wpa_supplicant.conf

输入内容:
保存

ssh方式登录树莓派

我们键入命令sudo raspi-config,通过选择interlacing Options.。打开SSH服务。
之后我们就可以使用Moba进行SSH连接了。

如果没有连上网,说明没有开启射频

rfkill list

需要打开网卡

rfkill unblock all
sudo ifconfig wlan0 up

系统已经存在打开的多个wpa_supplicant实例,执行killall wpa_supplicant杀死所有wpa_supplicant即可。

固定IP地址
可以修改/etc/rc.local中的内容达到效果

sudo nano /etc/rc.local

这个是操作系统初始话时会调用的shell脚本



至此配置完闭

更换国内源

1, 默认的源是国外的,apt-get 安装的时候失败,我们更新成国内的源
2,使用命令

sudo nano /etc/apt/sources.list


把原本的用#注释了加上中国的源

xrdp界面登录树莓派

进行界面登录树莓派我们需要使用开源软件xrdp
使用命令

  1. 下载xrdp
    sudo apt-get install xrdp
  2. 使用远程桌面连接

    使用电脑自带软件,进行连接。
    当连接成功则能进入画面,跟用HDMI线进行连接显示的画面一致。

远程文件传输FileZilla

在虚拟机中,我们常使用的是共享文件夹,在树莓派中,当然我们也可以使用moba工具进行传输文件,但是我们常用的工具还是FileZilla。

连接上后,左边为windows文件,右边为树莓派文件。

本文标签: 基本配置基础树莓派