树莓派酱の吃灰日常

分割线

无屏幕连接

  • 刚到手的树莓派裸机没屏幕和 Mini-HDMI 线,用 ssh 连接.

  • 首先,用手机或者电脑开热点 (注意只能连 2.4G 频段)

  • 然后在桌面新建文件夹树莓派,存放今后需要的数据文件.

    • 新建文件命名为ssh,注意它没有后缀名和文件数据.
    • 新建文件命名为 wpa_supplicant.conf ,文件数据如下:
    country=GB
    ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
    update_config=1
    network={
    ssid="你的Wifi名称,注意大小写"
    psk="你的Wifi密码"
    }

    文件链接

    20201203110651
  • 用读卡器把树莓派系统 TF 卡插进电脑,把这两个文件复制进内存卡里名叫 boot 的盘符根目录里.

  • 开鸡,等会应该就会发现电脑或者手机连接上了,如下:

    20201203110842 Screenshot20201203112505
  • 然后就可以用 ssh 连接这个 IP 地址了.

分割线

SSH 连接

  • 连接三要素是IP地址 + 用户名 + 密码

  • 树莓派系统默认账号是 pi,密码是 raspberry

可参照 ✨SSH 远程连接.
连接后记得改下密码: 💧 一些常用终端命令


VNC 连接

  • 没屏幕或者没 Mini-HDMI 线时最佳方案.
  • 首先下载 VNC 软件
  • 安装后打开搜索树莓派的内网 ip,输入用户名连接
    20201204103758
    20201204103843

分割线

常用配置

# 树莓派系统设置
sudo raspi-config

Screenfetch

  • 显示系统、主题信息
    sudo apt install screenfetch
    screenfetch

    这里不用 Neofetch 是因为树莓派 Debian8 系统的 repo 地址需要更新,安装还需要其他操作,怪麻烦~

  • 显示 Linux 系统及版本信息,如下:
    20201205143342
    20201203115807

分割线

apt-换源

sudo nano /etc/apt/sources.list

deb http://mirrors.ustc.edu.cn/debian bookworm main contrib non-free non-free-firmware
deb http://mirrors.ustc.edu.cn/debian-security/ bookworm-security main contrib non-free non-free-firmware
deb http://mirrors.ustc.edu.cn/debian bookworm-updates main contrib non-free non-free-firmware

# Uncomment deb-src lines below then 'apt-get update' to enable 'apt-get source'
#deb-src http://mirrors.ustc.edu.cn/debian bookworm main contrib non-free non-free-firmware
#deb-src http://mirrors.ustc.edu.cn/debian-security/ bookworm-security main contrib non-free non-free-firmware
#deb-src http://mirrors.ustc.edu.cn/debian bookworm-updates main contrib non-free non-free-firmware

分割线

内网使用

smb-内网文件共享

安装配置

sudo apt update && sudo apt install exfat-fuse exfatprogs ntfs-3g samba samba-common-bin

dpkg -l | grep -E "exfat|ntfs"
  • sudo nano /etc/fstab

    UUID=749C-1C4F /mnt/storage exfat defaults,auto,users,rw,nofail,uid=1000,gid=1000 0 0
    UUID=026815AC5FEFC0F7 /mnt/stack ntfs defaults,auto,users,rw,nofail,uid=1000,gid=1000 0 0
  • sudo nano /etc/samba/smb.conf

    # 共享 exFAT 硬盘(/dev/sdb1)
    [storage]
    path = /mnt/storage
    browseable = yes
    read only = no
    valid users = weidows
    create mask = 0775
    directory mask = 0775

    # 共享 NTFS 硬盘(/dev/sda1)
    [stack]
    path = /mnt/stack
    browseable = yes
    read only = no
    valid users = weidows
    create mask = 0775
    directory mask = 0775
sudo smbpasswd -a weidows
sudo systemctl restart smbd

连接

windows 直接在资源管理器输入内网地址 \\192.168.xxx.xxx, 不建议用 mac 连, 会出现很多.DS_Store 文件

分割线

局域网-网线连接

sudo apt update
sudo apt install dhcpcd5
sudo systemctl enable dhcpcd
sudo systemctl start dhcpcd
sudo systemctl restart dhcpcd

# 在电脑上看好DHCP掩码网段, 一般是255.255.0.0, 所以前两位需要跟电脑上显示一致

sudo nano /etc/dhcpcd.conf

interface enxb827ebeb0a18
static ip_address=169.254.135.223/16
nohook wpa_supplicant

sudo nano /etc/sysctl.conf
net.ipv4.ip_forward=1

sudo sysctl -p

分割线

彩色灯带

硬件连接

本人用的 pi 3B/4B, WS2812B 型号灯带, 分三根线(颜色可能并不一致,红黑绿白)

淘宝买条杜邦共对母口线, 直接拿小刀豁开绝缘皮插也行

  • 这里只是做的临时序号,GPIO 并不是这么排的, 此处只用第一行

    _____________________
    | 1 2 3 4 5 6 7 ....
    | 1 2 3 4 5 6 7 ....
    |
    | CPU
    |
    _____________________
  • 接线

    一般都有红线,+5V, 接 2

    中间的线是信号线,接 6

    另一根是 GND,接 3


安装工具链

sudo apt-get -y install python3-pip git
sudo pip install rpi-ws281x --break-system-packages

sudo apt -y install scons swig

安装驱动

sudo pip install rpi-ws281x
  • 很有可能并不能生效 (ModuleNotFoundError: No module named ‘rpi_ws281x’),需要下载编译源码

    git clone https://github.com/jgarff/rpi_ws281x.git
    cd rpi_ws281x
    scons
    cd ./python/
    sudo python3 ./setup.py install

    • 上面不要这样写,会报错 : sudo python ./python/setup.py install

      running install
      running bdist_egg
      running egg_info
      creating rpi_ws281x.egg-info
      writing rpi_ws281x.egg-info/PKG-INFO
      writing top-level names to rpi_ws281x.egg-info/top_level.txt
      writing dependency_links to rpi_ws281x.egg-info/dependency_links.txt
      writing manifest file 'rpi_ws281x.egg-info/SOURCES.txt'
      file neopixel.py (for module neopixel) not found
      reading manifest file 'rpi_ws281x.egg-info/SOURCES.txt'
      writing manifest file 'rpi_ws281x.egg-info/SOURCES.txt'
      installing library code to build/bdist.linux-armv7l/egg
      running install_lib
      running build_py
      file neopixel.py (for module neopixel) not found
      file neopixel.py (for module neopixel) not found
      running build_ext
      building '_rpi_ws281x' extension
      swigging rpi_ws281x.i to rpi_ws281x_wrap.c
      swig -python -o rpi_ws281x_wrap.c rpi_ws281x.i
      Unable to find file 'rpi_ws281x.i'.
      error: command 'swig' failed with exit status 1

修改配置文件

  • 用 nano/vim 或者 Kate 打开修改

    sudo nano ./examples/strandtest.py

    需要改两处:

    1. 依赖 import 处添加
    from neopixel import *
    1. LED 灯珠数(根据灯带实际数量)

  • 把这个文件复制出来 (不然不能运行)

    sudo cp ./examples/strandtest.py .

测试运行

sudo python3 ./strandtest.py
  • 在公司第一次跑起来的样子

    1632587136736

增强-音乐频谱

首先搞一下硬件: 树莓派没有板载输入声卡,需要 USB 免驱声卡 + 3.5mm有线可录音耳机 (调查了一番没有替代方案)

可以去买一个拓展坞,有的会附带 (当时我都缺,正好可以一刀切)

装环境

sudo apt-get install portaudio19-dev libatlas-base-dev
// 一定注意是pip3安装! 不是pip; 运行时也必须是 python3
sudo pip3 install numpy scipy pyqtgraph pyaudio

测试运行

git clone https://github.com/scottlawsonbc/audio-reactive-led-strip.git
sudo python3 audio-reactive-led-strip/python/visualization.py

灯带检测

灯带是否损坏可以一头接上+5V + GND, 在另一头短接试试

如果树莓派重启,则说明灯带电源没问题,要是不能亮的话就是信号线有问题或者电压不足