2021-7-24

N_Linux

Raspberry

官页 官页论坛

更换源

官网 所有镜像列表 清华大学开源软件站

编辑 sudo vi /etc/apt/sources.list 文件, 删除原文件所有内容, 用以下内容取代:

deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free
 

编辑sudo vi /etc/apt/sources.list.d/raspi.list文件, 删除原文件所有内容, 用以下内容取代:

deb http://mirrors.tuna.tsinghua.edu.cn/raspberrypi/ buster main ui
deb http://mirrors.tuna.tsinghua.edu.cn/raspberrypi/ bullseye main
 

无公钥问题

following signatures couldn’t be verified because the public key is not available: NO_PUBKEY 9165938D90FDDD2E

更换源之后添加公钥即可, 执行以下命令:

gpg --keyserver  keyserver.ubuntu.com --recv-keys 9165938D90FDDD2E
gpg --export --armor  9165938D90FDDD2E | sudo apt-key add -

默认用户

用户名: pi 密码: raspberry

不接显示器?

咸了个树莓派, 无视频线, 无SD卡, 怎么初始化并连接上?

1. 系统镜像烧录

启动盘制作 - https://www.raspberrypi.com/software/ 系统镜像 - https://www.raspberrypi.com/software/operating-systems/

Install Raspberry Pi OS using Raspberry Pi Imager CHOOSE OS 最下面有个 User custom 可自定义镜像..

2021-05-07-raspios-buster-arm64.zip

2. 烧录配置

  • 开机启用ssh服务 新建一个名称为ssh 空的文件, 表示启用ssh服务 默认用户名密码是: pi:raspberry

  • 自动连接WIFI 添加一个文件名为 wpa_supplicant.conf

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=CN
network={
	ssid="xiaomi"
	scan_ssid=1
	psk="WMS@13719421011"
}
 
network={
	ssid="B5WIFI"
	psk="jk1908B5"
	key_mgmt=WPA-PSK
}

ssid 指定wifi名称, psk 指定wifi密码 priority 是优先级, 数字越大越优先连接 scan_ssid 是扫描网络(隐藏wifi) 系统启动后, 会把这些配置信息写入 /etc/wpa_supplicant/wpa_supplicant.conf

其实可以通过远程桌面, 或者 sudo raspi-config 来设置wifi, 避免出现 ‘Wlan Localion’ 问题

configuration

3. 远程桌面服务

sudo apt install -y xrdp

安装好 xrdp 后, 即可用 mstsc 连接远程桌面

官方支持 VNC 远程服务 https://pidoc.cn/docs/computers/remote-access/#%E4%BD%BF%E7%94%A8-vnc-%E5%85%B1%E4%BA%AB%E5%B1%8F%E5%B9%95

使用 raspi-config 在命令行上启用 VNC 服务器。

  1. 用以下一行打开 raspi-config
sudo raspi-config
  1. 导航至Interfaces。按 Enter 键选择。
  2. 选择 VNC。按 Enter键选择。
  3. 在 Would you like the VNC Server to be enabled?(是否启用 VNC 服务器)下,选择 <Yes>,然后按 Enter
  4. 按 Enter返回菜单。按Esc退出 raspi-config

4. 去掉HDMI 检测

插了HDMI后, 通电时没有HDMI后就不启动了..

新版本 /boot/config.txt 该文件异常到 /boot/firmware/config.txt 且貌似没有该问题了…

sudo vi /boot/config.txt

framebuffer_width=1920
framebuffer_height=1080
hdmi_force_hotplug=1	# 关闭hdmi的检测
hdmi_group=1
hdmi_mode=5
hdmi_ignore_edit=0xa5000080
hdmi_ignore_edid=0xa5000080 # hdmi_ignore_edid 是命令树莓派不检测HDMI设备的任何信息,只按照我们指定的分辨率输出

关于 /boot/config.txt

Vs Code

官页

vscode 官页可下 .deb

dpkg -i code_1.58.2-1626302803_amd64.deb dpkg: error processing archive code_1.58.2-1626302803_amd64.deb (—install): package architecture (amd64) does not match system (arm64)

嗯.. CPU 架构不对arm64 注意名称! dpkg -i code_1.58.2-1626300392_arm64.deb

sudo apt-get install gcc

C 环境

官方教程 Using C++ on Linux in VS Code Using GCC with MinGW

Install the C/C++ extension for VS Code.

关键三个json 配置文件在 ./.vscode/ 目录下:

  • tasks.json (build instructions)
  • launch.json (debugger settings)
  • c_cpp_properties.json (compiler path and IntelliSense settings)

1. tasks.json

(build instructions) build配置文件

{
  "version": "2.0.0",
  "tasks": [
    {
      "type": "shell",
      "label": "g++ build active file",
        //编译器路径 
      "command": "/usr/bin/g++",
      "args": [
          "-g", "${file}", 
          "-o", "${fileDirname}/${fileBasenameNoExtension}.o",
            //编译参数, 这里可以添加 lib库
          "-L /lib/aarch64-linux-gnu/", "-lavutil",
          "-L /lib/aarch64-linux-gnu/", "-lavcodec",
          "-L /lib/aarch64-linux-gnu/", "-lavformat",
          "-L /lib/aarch64-linux-gnu/", "-lavdevice",
          "-L /lib/aarch64-linux-gnu/", "-lavfilter",
          "-L /lib/aarch64-linux-gnu/", "-lswscale"
      ],
      "options": {
        "cwd": "${workspaceFolder}"
      },
      "problemMatcher": ["$gcc"],
      "group": {
        "kind": "build",
        "isDefault": true
      }
    }
  ]
}

To run the build task defined in tasks.json, press Ctrl+Shift+B or from the Terminal main menu choose Run Build Task.

添加lib

主要就是在tasks.json args 中加入动态库路径 “-L”, “/usr/local/opencv3.4/lib/lib*“

{
  "tasks": [
    {
        // ...
      "args": [
        "-g", "${file}", 
        "-o", "${fileDirname}\\${fileBasenameNoExtension}.o",
        "-L /lib/aarch64-linux-gnu/", "-lavutil",
        "-L /lib/aarch64-linux-gnu/", "-lavcodec",
        "-L /lib/aarch64-linux-gnu/", "-lavformat",
        "-L /lib/aarch64-linux-gnu/", "-lavdevice",
        "-L /lib/aarch64-linux-gnu/", "-lavfilter",
        "-L /lib/aarch64-linux-gnu/", "-lswscale"
      ],
}

2. launch.json

(debugger settings) 调试配置文件

{
    "version": "0.2.0",
    "configurations": [
      {
        "name": "g++ build and debug active file",
        "type": "cppdbg",
        "request": "launch",
        //目标程序
        "program": "${fileDirname}/${fileBasenameNoExtension}.o",
        "args": [],
        "stopAtEntry": false,
        "cwd": "${workspaceFolder}",
        //动态库搜索路径. 多个用 ; (分号) 分割
        "additionalSOLibSearchPath":"/lib/aarch64-linux-gnu/",
        "environment": [],
        "externalConsole": false,
        "MIMode": "gdb",
        "setupCommands": [
          {
            "description": "Enable pretty-printing for gdb",
            "text": "-enable-pretty-printing",
            "ignoreFailures": true
          }
        ],
        "preLaunchTask": "g++ build active file",
        //gdb 路径
        "miDebuggerPath": "/usr/bin/gdb"
      }
    ]
  }
 

Press F5 or from the main menu choose Run > Start Debugging.

官方文档

指定so动态库搜索路径

//动态库搜索路径. 多个用 ; (分号) 分割 “additionalSOLibSearchPath”:“/lib/aarch64-linux-gnu/“,

3. c_cpp_properties.json

自定义头文件路径

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**",
                //头文件查找路径
                "/usr/include/aarch64-linux-gnu"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "gnu17",
            "cppStandard": "gnu++14",
            "intelliSenseMode": "linux-gcc-arm64",
            "forcedInclude": []
        }
    ],
    "version": 4
}

也可以通过Ctrl + P 快捷键执行 C/C++: Edit Configurations 通过界面的方式执行

指定头文件 搜索路径

includePath 属性配置头文件查找路径 “includePath”: [ ”${workspaceFolder}/**”, //头文件查找路径 “/usr/include/aarch64-linux-gnu” ],

问题 tasks.json: file format not recognized;

tasks.json: file format not recognized; 注意这个变量 ${file},是当前打开的文件!!! 把它c文件处理了, 要打开是入口文件

ffmpeg 环境项目归档

树莓派 ffmpeg 环境 vscode项目

SSH 远程开发扩展 Remote - SSH

Remote - SSH

可以让 Vs Code 基于ssh远程开发~

The absolute file path to a custom SSH config file. 设置配置存放路径: F:/config/vscode_ssh.cnf

右边的 Remote Expolorer + ssh pi@192.168.2.200 -A

ssh 用户名@IP -A

配置文件结果 vscode_ssh.cnf

Host 192.168.2.200
  HostName 192.168.2.200
  User pi
  ForwardAgent yes

内存占用太高?

主要是 Pylance 插件默认会尝试分析工作区内的所有文件。你需要告诉它忽略不必要的文件夹

创建项目根目录下的 .vscode/settings.json

{
    "python.analysis.exclude": [
        "**/node_modules",
        "**/__pycache__",
        "**/.*", 
        "**/venv",
        "**/env",
        "**/.venv",
        "**/data", 
        "**/datasets", 
        "**/models", 
        "**/*.log"
    ],
    "files.exclude": {
        "**/node_modules": true,
        "**/__pycache__": true,
        "**/.*": true,
        "**/venv": true,
        "**/env": true,
        "**/.venv": true,
        "**/data": true,
        "**/datasets": true,
        "**/models": true
    },
    "files.watcherExclude": {
        "**/node_modules/**": true,
        "**/__pycache__/**": true,
        "**/venv/**": true,
        "**/env/**": true,
        "**/.venv/**": true,
        "**/data/**": true,
        "**/datasets/**": true,
        "**/models/**": true
    },
       "python.analysis.typeCheckingMode": "basic", 
    "python.analysis.autoImportCompletions": false,
    "python.analysis.indexing": false 
}

设置 new file 的语言模式

You can now set the default language at either the user or workspace settings level using files.defaultLanguage: “files.defaultLanguage”: “html” https://stackoverflow.com/questions/35904221/change-vscode-default-language-for-new-files

一个语音识别库

https://alphacephei.com/vosk/models

环境

安装 ffmpeg-dev

其实 debian 有适合树莓版本 ffmpeg lib的开发包 packages.debian ffmpeg;

不用自己编译, 但是一个模块一个包名…

开发库 development files sudo apt -y install libavcodec-dev libavdevice-dev libavformat-dev libavutil-dev libswscale-dev

执行完后 头文件在: /usr/include/aarch64-linux-gnu/ lib 库在: /lib/aarch64-linux-gnu/

对应的 runtime files sudo apt -y install libavcodec58 libavdevice58 libavformat58 libavutil56 libswscale5

安装 mariadb

sudo apt-get install mariadb-server -y

初始化

sudo mysql 
alter user 'root'@'localhost' IDENTIFIED BY 'abc123.com';

CREATE USER 'yang'@'%' IDENTIFIED BY 'yang.abc.com';
GRANT ALL PRIVILEGES ON *.* TO 'yang'@'%';
flush privileges; 

配置文件

sudo vi /etc/mysql/mariadb.conf.d/50-server.cnf

重启服务

service mariadb restart