Daimon Blog

山在那里

树莓派学习笔记

树莓派是非常好的IOT中控端。这里把我常用的命令,随着学习,随着记录下。

修改安装源

vi /etc/apt/sources.list

如果安装过程中提示 源 error,可以使用以下归档源

deb http://archive.raspbian.org/raspbian wheezy main
deb-src http://archive.raspbian.org/raspbian wheezy main

参见

https://www.raspberrypi.org/forums/viewtopic.php?t=8839#p104296

连接wifi与开通ssh

http://shumeipai.nxez.com/2017/09/13/raspberry-pi-network-configuration-before-boot.html

用户可以在未启动树莓派的状态下单独修改 /boot/wpa_supplicant.conf 文件配置 WiFi 的 SSID 和密码,这样树莓派启动后会自行读取 wpa_supplicant.conf 配置文件连接 WiFi 设备。

country=CN
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
ssid="WiFi-A"
psk="12345678"
key_mgmt=WPA-PSK
priority=1
}

network={
ssid="WiFi-B"
psk="12345678"
key_mgmt=WPA-PSK
priority=2
scan_ssid=1
}

说明以及不同安全性的 WiFi 配置示例:

  • ssid:网络的ssid
  • psk:密码
  • priority:连接优先级,数字越大优先级越高(不可以是负数)
  • scan_ssid:连接隐藏WiFi时需要指定该值为1

开启ssh,只需要touch ssh即可。

开启vnc

先ip扫下,看看ip

sudo nmap   -sS 192.168.1.1/24

然后ssh连接上, 运行配置命令行

sudo raspi-config

配置下vnc。注意顺手改下pi的默认密码。再改下分辨率

然后就可以用vncviewer连接上了。端口是5900。 注意mac默认的finder中的vnc是连不了的,协议不兼容。要用vncviewer。可以用chrome带的那个Vncviewer。

安装lcd

直接看官网

http://www.waveshare.net/wiki/3.5inch_RPi_LCD_(C)#.E8.AE.BE.E7.BD.AE.E6.98.BE.E7.A4.BA.E6.96.B9.E5.90.91

校准是个麻烦事。按官网做,根本就调不准。还要参考下面两个文章,理解校准原理。

https://github.com/swkim01/waveshare-dtoverlays https://raspberrypi.stackexchange.com/questions/60872/inverted-gpio-touchscreen-using-99-calibration-conf

安装校准软件

apt-get install xinput-calibrator

我是这么调整的:

vi /boot/config.txt

dtoverlay=waveshare35a:rotate=270,swapxy=1^

上面是在调整屏幕的方向。这个是基准。你想调成哪个方向,就调成哪个方向。 哪个方向顺手,你就调整到哪个方向。

然后再调整输入的x/y方向。 按上面的文章来。我是这样的

vi /usr/share/X11/xorg.conf.d/40-libinput.conf

Section "InputClass"
        Identifier "libinput touchscreen catchall"
        MatchIsTouchscreen "on"
        MatchDevicePath "/dev/input/event*"
        Driver "libinput"
        Option "TransformationMatrix" "1 0 0 0 -1 1 0 0 1"
EndSection

这个在实验的时候,可以用

xinput set-prop 'ADS7846 Touchscreen' 'Coordinate Transformation Matrix' 1 0 0 0 -1 1 0 0 1

来快速验证。

最后在校准度度坐标

vi /usr/share/X11/xorg.conf.d/99-calibration.conf

Section "InputClass"
    Identifier    "calibration"
    MatchProduct    "ADS7846 Touchscreen"
    Option    "MinX"    "3413"
    Option    "MaxX"    "62941"
    Option    "MinY"    "3226"
    Option    "MaxY"    "62617"
    Option    "SwapXY"    "0" # unless it was already set to 1
    Option    "InvertX"    "0"  # unless it was already set
    Option    "InvertY"    "0"  # unless it was already set
EndSection

经过这三步,屏幕的坐标系就正确了。Enjoy it!

安装 usb转串口驱动

http://www.wch.cn/download/CH341SER_LINUX_ZIP.html https://github.com/juliagoda/CH341SER

下载第一个文章的驱动,按第二个文章说明编译安装即可。

apt-get install raspberrypi-kernel-headers
make
make load

成功之后,插入 usb2serial 设备,会有 /dev/ttyUSB0 的端口号出现。

安装python3.7

https://gist.github.com/SeppPenner/6a5a30ebc8f79936fa136c524417761d https://www.scivision.co/compile-install-python-beta-raspberry-pi/

装telegraf

  1. https://portal.influxdata.com/downloads
  2. tar xf telegraf-1.9.0_linux_armhf.tar.gz && rsync avr telegraf/ /
  3. useradd telegraf -s /bin/false
  4. ln /usr/lib/telegraf/scripts/telegraf.servicepwd/telegraf.service
  5. systemctl start telegraf && systemctl status telegraf

文章分类目录