Skip to content

Commit 95481d2

Browse files
committed
pwm
1 parent 3d5384e commit 95481d2

File tree

3 files changed

+127
-41
lines changed

3 files changed

+127
-41
lines changed

README.md

Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,42 @@
1-
# README
2-
3-
树莓派应该算是目前开源硬件里学习嵌入式Linux系统最好的工具,里面的设计思路和一些工具是很值得借鉴的,这里主要使用Raspberry Pi ZERO W进行系统架构分析。
4-
5-
之前在使用树莓派的过程中有记录一些东西,不过没有进行全面系统性的分析,相对比较零散。
6-
7-
[博客园 - 随笔分类 - Raspberry Pi](https://www.cnblogs.com/zengjfgit/category/783268.html)
8-
9-
## ZERO W接口原理图
10-
11-
![docs/images/RPI_Zero_W_40_Pin.png](docs/images/RPI_Zero_W_40_Pin.png)
12-
13-
## 参考文档
14-
15-
* [Raspberry Pi](https://www.raspberrypi.org/)
16-
* [Raspberry Pi On GitHub](https://github.com/raspberrypi)
17-
* [Raspberry Pi Documentation](https://github.com/raspberrypi/documentation)
18-
* [Raspberry Pi Pinout](https://pinout.xyz/pinout/uart)
19-
* [systemd](https://github.com/systemd/systemd)
20-
21-
## 笔记文档
22-
23-
* [0019_Kernel_Build.md](docs/0019_Kernel_Build.md)
24-
* [0018_Samba.md](docs/0018_Samba.md)
25-
* [0017_Internationalisation_Options.md](docs/0017_Internationalisation_Options.md)
26-
* [0016_Setup_Multiple_WiFi_Networks.md](docs/0016_Setup_Multiple_WiFi_Networks.md)
27-
* [0015_Modify_Default_Route.md](docs/0015_Modify_Default_Route.md)
28-
* [0014_Ethernet_over_USB-Static_IP.md](docs/0014_Ethernet_over_USB-Static_IP.md)
29-
* [0013_dtoverlay.md](docs/0013_dtoverlay.md)
30-
* [0012_Dynamic_Device_Tree.md](docs/0012_Dynamic_Device_Tree.md)
31-
* [0011_SPI.md](docs/0011_SPI.md)
32-
* [0010_I2C_AT24C0x.md](docs/0010_I2C_AT24C0x.md)
33-
* [0009_systemd-sysv-generator.md](docs/0009_systemd-sysv-generator.md)
34-
* [0008_Systemd_Advance.md](docs/0008_Systemd_Advance.md)
35-
* [0007_Systemd_Cron_rc-local.md](docs/0007_Systemd_Cron_rc-local.md)
36-
* [0006_Device_Tree_Overlays.md](docs/0006_Device_Tree_Overlays.md)
37-
* [0005_raspi-config.md](docs/0005_raspi-config.md)
38-
* [0004_Pin_Config.md](docs/0004_Pin_Config.md)
39-
* [0003_BIOS.md](docs/0003_BIOS.md)
40-
* [0002_Boot_Sequence.md](docs/0002_Boot_Sequence.md)
41-
* [0001_OTG_To_Ethernet.md](docs/0001_OTG_To_Ethernet.md)
1+
# README
2+
3+
树莓派应该算是目前开源硬件里学习嵌入式Linux系统最好的工具,里面的设计思路和一些工具是很值得借鉴的,这里主要使用Raspberry Pi ZERO W进行系统架构分析。
4+
5+
之前在使用树莓派的过程中有记录一些东西,不过没有进行全面系统性的分析,相对比较零散。
6+
7+
[博客园 - 随笔分类 - Raspberry Pi](https://www.cnblogs.com/zengjfgit/category/783268.html)
8+
9+
## ZERO W接口原理图
10+
11+
![docs/images/RPI_Zero_W_40_Pin.png](docs/images/RPI_Zero_W_40_Pin.png)
12+
13+
## 参考文档
14+
15+
* [Raspberry Pi](https://www.raspberrypi.org/)
16+
* [Raspberry Pi On GitHub](https://github.com/raspberrypi)
17+
* [Raspberry Pi Documentation](https://github.com/raspberrypi/documentation)
18+
* [Raspberry Pi Pinout](https://pinout.xyz/pinout/uart)
19+
* [systemd](https://github.com/systemd/systemd)
20+
21+
## 笔记文档
22+
23+
* [0020_PWM](https://github.com/ZengjfOS/RPiPWM)
24+
* [0019_Kernel_Build.md](docs/0019_Kernel_Build.md)
25+
* [0018_Samba.md](docs/0018_Samba.md)
26+
* [0017_Internationalisation_Options.md](docs/0017_Internationalisation_Options.md)
27+
* [0016_Setup_Multiple_WiFi_Networks.md](docs/0016_Setup_Multiple_WiFi_Networks.md)
28+
* [0015_Modify_Default_Route.md](docs/0015_Modify_Default_Route.md)
29+
* [0014_Ethernet_over_USB-Static_IP.md](docs/0014_Ethernet_over_USB-Static_IP.md)
30+
* [0013_dtoverlay.md](docs/0013_dtoverlay.md)
31+
* [0012_Dynamic_Device_Tree.md](docs/0012_Dynamic_Device_Tree.md)
32+
* [0011_SPI.md](docs/0011_SPI.md)
33+
* [0010_I2C_AT24C0x.md](docs/0010_I2C_AT24C0x.md)
34+
* [0009_systemd-sysv-generator.md](docs/0009_systemd-sysv-generator.md)
35+
* [0008_Systemd_Advance.md](docs/0008_Systemd_Advance.md)
36+
* [0007_Systemd_Cron_rc-local.md](docs/0007_Systemd_Cron_rc-local.md)
37+
* [0006_Device_Tree_Overlays.md](docs/0006_Device_Tree_Overlays.md)
38+
* [0005_raspi-config.md](docs/0005_raspi-config.md)
39+
* [0004_Pin_Config.md](docs/0004_Pin_Config.md)
40+
* [0003_BIOS.md](docs/0003_BIOS.md)
41+
* [0002_Boot_Sequence.md](docs/0002_Boot_Sequence.md)
42+
* [0001_OTG_To_Ethernet.md](docs/0001_OTG_To_Ethernet.md)

docs/0020_RPiPWM/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# README
2+
3+
[RPiPWM.py](RPiPWM.py)
4+
5+
## Ref
6+
7+
* [Raspberry Pi Pulse Width Modulation (PWM)](https://www.mbtechworks.com/projects/raspberry-pi-pwm.html)

docs/0020_RPiPWM/RPiPWM.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/usr/bin/python3
2+
# -*- coding: utf-8 -*-
3+
4+
import time
5+
import RPi.GPIO as GPIO
6+
7+
GPIOMode = GPIO.BOARD
8+
GPIOPin = 12
9+
GPIOType = GPIO.OUT
10+
GPIOHz = 50
11+
PulseDut = 50
12+
PinRef = None
13+
14+
GPIO.setmode(GPIOMode)
15+
GPIO.setup(GPIOPin, GPIOType)
16+
17+
def help():
18+
print("""
19+
cmd:
20+
1. r-run
21+
2. p-in
22+
3. f-frequency
23+
4. d-dut
24+
""")
25+
26+
def run():
27+
28+
global GPIOMode
29+
global GPIOPin
30+
global GPIOType
31+
global GPIOHz
32+
global PulseDut
33+
34+
GPIO.setmode(GPIOMode)
35+
GPIO.setup(GPIOPin, GPIOType)
36+
PinRef = GPIO.PWM(GPIOPin, GPIOHz)
37+
PinRef.start(0)
38+
PinRef.ChangeDutyCycle(PulseDut)
39+
40+
41+
def PWM():
42+
43+
global GPIOMode
44+
global GPIOPin
45+
global GPIOType
46+
global GPIOHz
47+
global PulseDut
48+
49+
run()
50+
51+
try:
52+
while True:
53+
cmd = input("Enter cmd(r-run, p-in, f-frequency, d-dut: ")
54+
55+
if cmd != "r":
56+
PinRef.stop()
57+
58+
if cmd == "p":
59+
GPIOPin = input("value: ")
60+
61+
if cmd == "f":
62+
GPIOHz = input("value: ")
63+
64+
if cmd == "d":
65+
PulseDut = input("value: ")
66+
67+
if cmd == "r":
68+
run()
69+
70+
except KeyboardInterrupt:
71+
pass
72+
73+
PinRef.stop()
74+
GPIO.cleanup()
75+
76+
if __name__ == '__main__':
77+
help()
78+
PWM()

0 commit comments

Comments
 (0)