树莓派Zero 使用

Posted by on Mon, May 30, 2022

折腾数莓派Zero W

上手

  • 使用Rufus烧录raspbian固件

  • SD卡不要拔出, 在boot盘根目录新建ssh文件, 使能ssh功能

  • 同样在SD卡根目录新建wpa_supplicant.conf文件, 内容如下:

    1
    2
    3
    4
    5
    6
    7
    8
    
    country=CN
    ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
    update_config=1
    network={
        ssid="MyWiFiNetwork"
        psk="aVeryStrongPassword"
        key_mgmt=WPA-PSK
    }
    
  • 上电

  • 主机名: raspberrypi, 默认用户名: pi, 密码: raspberry

    1
    
    ssh pi@raspberrypi
    

设置USB g_serial

使用USB OTG模拟串口, 接入命令行. 具体参考了 Adafruit 的教程.

  • 向SD卡boot盘根目录config.txt文件末尾写入dtoverlay=dwc2

  • 向SD卡boot盘根目录cmdline.txt文件rootwait后添加 modules-load=dwc2,g_serial

  • USB接USB口, 不是PWR口, 重启, 查看dmesg, g_serial成功加载

    1
    2
    3
    4
    5
    6
    
    pi@raspberrypi:~ $ dmesg | grep g_serial
    [    0.000000] Kernel command line: coherent_pool=1M 8250.nr_uarts=0 snd_bcm2835.enable_compat_alsa=0 snd_bcm2835.enable_hdmi=1 snd_bcm2835.enable_headphones=1 bcm2708_fb.fbwidth=656 bcm2708_fb.fbheight=416 bcm2708_fb.fbswap=1 smsc95xx.macaddr=B8:27:EB:DA:D1:BD vc_mem.mem_base=0x1ec00000 vc_mem.mem_size=0x20000000  console=tty1 root=PARTUUID=efeb3060-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait modules-load=dwc2,g_serial
    [    6.408972] g_serial gadget: Gadget Serial v2.4
    [    6.411873] g_serial gadget: g_serial ready
    [    6.414652] dwc2 20980000.usb: bound driver g_serial
    [    6.653992] g_serial gadget: high-speed config #2: CDC ACM config
    
  • 绑定命令行到串口, 可能要再重启一下才会生效

    1
    2
    
    sudo systemctl enable getty@ttyGS0.service
    sudo systemctl is-active getty@ttyGS0.service
    

软件设置

  • 换源

    1
    2
    3
    4
    5
    6
    
    # 编辑 `/etc/apt/sources.list` 文件,删除原文件所有内容,用以下内容取代:
    deb http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ buster main non-free contrib rpi
    deb-src http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ buster main non-free contrib rpi
    
    # 编辑 `/etc/apt/sources.list.d/raspi.list` 文件,删除原文件所有内容,用以下内容取代:
    deb http://mirrors.tuna.tsinghua.edu.cn/raspberrypi/ buster main ui
    
  • sudo apt update && sudo apt upgrade -y

  • sudo apt install screen git network-manager w3m linuxlogo -y

Debug

  • nmtui的一个bug
    1
    2
    3
    
    sudo systemctl disable dhcpcd
    sudo systemctl stop dhcpcd
    sudo service NetworkManager restart