简书链接:树莓派4B初探
文章字数:1692,阅读全文大约需要6分钟
刷入后默认密码是pi pwd 12345678
默认是个pi的热点 ,ip 192.168.1.1 如果再把网线连上去,那么连上这个热点是可以上网的。

ssh默认开启的,密码是Raspberry

关于热点关闭问题,

网上说是在/etc/rc.local注释相关代码,而我的没有。
网上说
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

我纳闷卖家提供刷入的怎么默认有wifi,我怀疑我的被人改乱了

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=CN

network={
ssid="XX_PAY"
psk="11111"
}

network={
ssid="zhulin-huawei"
psk="111116271239"
}

network={
ssid="TP-LINK_5619"
psk="12345678"
key_mgmt=WPA-PSK
disabled=1
}

经过测试我配置上我的wifi没效果。
etc/network/interfaces配置 wifi

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# interfaces(5) file used by ifup(8) and ifdown(8)

# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'

# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
auto wlan0
iface wlan0 inet static
address 192.168.2.244
netmask 255.255.255.0
gateway 192.168.2.1
wpa-ssid XX_PAY
wpa-passphrase WIFI密码
wireless-channel 11

测试后发现可以244联网了,之前192.168.1.1的远程地址连不上了,说明是生效了,但是纳闷的是图形界面显示的是X,而且我ping baidu是不通的。
ok,注释掉。
另外附加上本地lan的,不过我这都没效果,如果全部配置上,那wifi是脸上的,我能内网远程连上,但是ping不通,lan也不行,如果只配置lan,我发现并没有连上lan,wifi热点还在,但是,然后。。

1
2
3
4
5
6
7
auto lo
iface lo inet loopback

iface eth0 inet static
address 192.168.1.1
netmask 255.255.255.0
gateway 192.168.1.1

继续探索etc/dhcpd.conf方案
文件内容如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# A sample configuration for dhcpcd.
# See dhcpcd.conf(5) for details.

# Allow users of this group to interact with dhcpcd via the control socket.
#controlgroup wheel

# Inform the DHCP server of our hostname for DDNS.
hostname

# Use the hardware address of the interface for the Client ID.
clientid
# or
# Use the same DUID + IAID as set in DHCPv6 for DHCPv4 ClientID as per RFC4361.
# Some non-RFC compliant DHCP servers do not reply with this set.
# In this case, comment out duid and enable clientid above.
#duid

# Persist interface configuration when dhcpcd exits.
persistent

# Rapid commit support.
# Safe to enable by default because it requires the equivalent option set
# on the server to actually work.
option rapid_commit

# A list of options to request from the DHCP server.
option domain_name_servers, domain_name, domain_search, host_name
option classless_static_routes
# Respect the network MTU. This is applied to DHCP routes.
option interface_mtu

# Most distributions have NTP support.
#option ntp_servers

# A ServerID is required by RFC2131.
require dhcp_server_identifier

# Generate SLAAC address using the Hardware Address of the interface
#slaac hwaddr
# OR generate Stable Private IPv6 Addresses based from the DUID
slaac private

# Example static IP configuration:
interface lan0
static ip_address=192.168.2.245/24
#static ip6_address=fd51:42f8:caae:d92e::ff/64
static routers=192.168.2.1
static domain_name_servers=192.168.2.1 8.8.8.8 fd51:42f8:caae:d92e::1

# It is possible to fall back to a static IP if DHCP fails:
# define static profile
#profile static_eth0
#static ip_address=192.168.1.23/24
#static routers=192.168.1.1
#static domain_name_servers=192.168.1.1

# fallback to static profile on eth0
#interface eth0
#fallback static_eth0
interface wlan0
static ip_address=192.168.1.1/24
nohook wpa_supplicant

其中lan0是我放开的,发现并没有连接上,我不配置他还连接上了,是默认的动态的,固定ip这么难的吗?我感觉要刷官方的系统,这都被改乱了
这里192.168.1.1/24大概就是这里产生热点的地方

总之,玩死了研究串口救砖还是usb转hdpi我感觉我还是重装吧

https://downloads.raspberrypi.org/raspios_arm64/images/
参考文章
https://blog.csdn.net/Naiva/article/details/105197196?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_baidulandingword~default-0-105197196-blog-106721491.235^v38^pc_relevant_sort_base1&spm=1001.2101.3001.4242.1&utm_relevant_index=3
https://blog.csdn.net/taw19960426/article/details/106721491
https://blog.csdn.net/zhf_sy/article/details/108873788
https://blog.csdn.net/SoftwarerRJY/article/details/95877052
https://www.cnblogs.com/keygle/archive/2013/04/27/3048273.html
https://zhuanlan.zhihu.com/p/458102755
https://blog.csdn.net/Edwinwzy/article/details/129140494
https://blog.csdn.net/ziqifeinv/article/details/79036452
https://www.jianshu.com/p/bd918ef98a4d

2023-11-8 19:16:49
今天我用我的pve 工控机插上 了usb读卡器,然后看到了设备
image.png

1
2
3
4
5
6
fdisk -l
Device Boot Start End Sectors Size Id Type
/dev/sda1 8192 532479 524288 256M c W95 FAT32 (LBA)
/dev/sda2 532480 31116287 30583808 14.6G 83 Linux
root@pve:/mnt/test/etc/network#

直接进入 /dev/sda2是进不去的
所以 mkdir /mnt/test
然后mount /dev/sda2 /mnt/test
然后df -m /dev/sda2 可以看到挂载点了
image.png

ok,不需要hdmi线和开启串口也可以了。

nanolink
1
2
3
4

![image.png](https://upload-images.jianshu.io/upload_images/2815884-2e80303c3314c6cb.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
最后我的配置如下 dhcpcd.conf

Allow users of this group to interact with dhcpcd via the control socket.

#controlgroup wheel

Inform the DHCP server of our hostname for DDNS.

hostname

Use the hardware address of the interface for the Client ID.

clientid

or

Use the same DUID + IAID as set in DHCPv6 for DHCPv4 ClientID as per RFC4361.

Some non-RFC compliant DHCP servers do not reply with this set.

In this case, comment out duid and enable clientid above.

#duid

Persist interface configuration when dhcpcd exits.

persistent

Rapid commit support.

Safe to enable by default because it requires the equivalent option set

on the server to actually work.

option rapid_commit

A list of options to request from the DHCP server.

option domain_name_servers, domain_name, domain_search, host_name
option classless_static_routes

Respect the network MTU. This is applied to DHCP routes.

option interface_mtu

Most distributions have NTP support.

#option ntp_servers

A ServerID is required by RFC2131.

require dhcp_server_identifier

Generate SLAAC address using the Hardware Address of the interface

#slaac hwaddr

OR generate Stable Private IPv6 Addresses based from the DUID

slaac private
interface wlan0
static ip_address=192.168.2.244/24
static routers=192.168.2.1
static domain_name_servers=192.168.2.1 8.8.8.8

1
2
识别wpa_文件
/etc/network/interfaces 中编辑

#auto wlan0
allow-hotplug wlan0
iface wlan0 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
至于直接设置密码的上面已经提到了,没有网的问题,关闭热点,设置了dns
就解决了
resolve.conf可以配置多个dns地址比如路由器地址 以及8.8.8.8之类


创建热点的原理大概也理解了
在etc/dhcpcd.conf中添加

![image.png](https://upload-images.jianshu.io/upload_images/2815884-5f9fa8ca2b912a00.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
在etc/hostapd/hostapd.conf中添加
![image.png](https://upload-images.jianshu.io/upload_images/2815884-22b1e21a19326ea4.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
那么热点就有了。
至于lan口无法固定的问题不太懂,难道是上面执行了if 后面又wifi if把它覆盖了?
我发现在好几个地方配置 分别配置不同ip都没生效,不过自动分配了一个ip我直接路由器给他固定得了

编程
home目录具备权限,因此 ssh连接直接创建文件

#include <wiringPi.h>
#include <stdio.h>

#define LEDPin 21
int main(){

printf(“hello”);
wiringPiSetup();
pinMode(LEDPin,OUTPUT);
int i=0;
for(;;){
digitalWrite(LEDPin,1);//ON
delay(500);
digitalWrite(LEDPin,0);
delay(500);
if(i>5){
break;
}
i++;
}
;
}

1
2
3
4
5
6
7
8
9
![F((M~JNTD4U@$JKBJAU4}$D_tmb.jpg](https://upload-images.jianshu.io/upload_images/2815884-27ab246399f9f332.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
输入```gcc led.c -o led -lwiringPi```
然后```./led```就发现灯闪烁了,直接ctrl+z可以直接结束程序,
![image.png](https://upload-images.jianshu.io/upload_images/2815884-2f5f027f1ab1e836.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)


![image.png](https://upload-images.jianshu.io/upload_images/2815884-5b1aeb14d313ecd5.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

PYTHON

#!/usr/bin/env python
import RPi.GPIO as GPIO
import time
LEDPin=29# FROM 5—-HEAD 29
GPIO.setmode(GPIO.BOARD)
GPIO.setup(LEDPin,GPIO.OUT)
GPIO.output(LEDPin,GPIO.HIGH)
try:
while True:
print ‘led on’
GPIO.output(LEDPin,GPIO.LOW)
time.sleep(0.5)
print ‘led off’
GPIO.output(LEDPin,GPIO.HIGH)
time.sleep(0.5)
except KeyboardInterrupt:
GPIO.output(LEDPin,GPIO.HIGH)
GPIO.cleanup()

1
2
3
4
5
这里是python2, t同样,执行即可,会发现灯一闪一闪
上面5 则模式为GPIO.BCM
这里的led是控制扩展版自带的灯

bcm

#!/usr/bin/env python
import RPi.GPIO as GPIO
import time
LEDPin=5
GPIO.setmode(GPIO.BCM)
GPIO.setup(LEDPin,GPIO.OUT)
GPIO.output(LEDPin,GPIO.HIGH)
if GPIO.input(LEDPin) == GPIO.HIGH:
print(‘HEIGHT’)
else:
print(‘LOW’)
try:
while True:
print ‘led on’
GPIO.output(LEDPin,GPIO.LOW)

time.sleep(0.5)
print 'led off'
GPIO.output(LEDPin,GPIO.HIGH)
time.sleep(0.5)

except KeyboardInterrupt:
GPIO.output(LEDPin,GPIO.HIGH)
GPIO.cleanup()


![image.png](https://upload-images.jianshu.io/upload_images/2815884-00dae45e7b7fbe2e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
扩展板GPIO17对应的是这下面的GPIO0
扩展板是bcm牌子的 ,因此上面的读数GPIO17就是bcm的17 

![image.png](https://upload-images.jianshu.io/upload_images/2815884-37c7ec7f41df135a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

最后我的笔记

![image.png](https://upload-images.jianshu.io/upload_images/2815884-c1cf7b873cbb0b3f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)