Skip to content

Commit 9cb3254

Browse files
Added Source Code
1 parent 486746f commit 9cb3254

File tree

9 files changed

+284
-6
lines changed

9 files changed

+284
-6
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "Raspberry-Pi5-PWM-Fan-Control"]
2+
path = Raspberry-Pi5-PWM-Fan-Control
3+
url = https://github.com/franganghi/Raspberry-Pi5-PWM-Fan-Control.git

LEDs/LEDsV2.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import RPi.GPIO as GPIO
2+
import time
3+
4+
# BCM Number of LED indicators
5+
leds = [5, 6, 13, 19]
6+
pwms = []
7+
8+
GPIO.setmode(GPIO.BCM)
9+
GPIO.setwarnings(False)
10+
11+
for l in leds:
12+
GPIO.setup(l, GPIO.OUT)
13+
pwms.append(GPIO.PWM(l, 50))
14+
15+
for p in pwms:
16+
p.start(0)
17+
18+
try:
19+
while True:
20+
for dc in range(0, 101, 5):
21+
for p in pwms:
22+
p.ChangeDutyCycle(dc)
23+
time.sleep(0.1)
24+
for dc in range(100, -1, -5):
25+
for p in pwms:
26+
p.ChangeDutyCycle(dc)
27+
time.sleep(0.1)
28+
except KeyboardInterrupt:
29+
pass
30+
31+
for p in pwms:
32+
p.stop()
33+
GPIO.cleanup()
34+
print("BYE")
35+

LEDs/LEDsV2.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
source /opt/EP-0152/bin/activate
4+
python3 /opt/EP-0152/LEDs/LEDsV2.py
5+

LEDs/ep0152ledpwm.service

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[Unit]
2+
Description=EP-0152 LEDs PWM Pulse
3+
After=multi-user.target
4+
5+
[Service]
6+
Type=simple
7+
ExecStart=/opt/EP-0152/LEDs/LEDsV2.sh
8+
Restart=on-abort
9+
10+
[Install]
11+
WantedBy=multi-user.target
12+

OLED/OLED.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
source /opt/EP-0152/bin/activate
4+
python3 /opt/EP-0152/OLED/oledV2.py
5+

OLED/ep0152oled.service

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[Unit]
2+
Description=EP-0152 OLED Monitor
3+
After=multi-user.target
4+
5+
[Service]
6+
Type=simple
7+
ExecStart=/opt/EP-0152/OLED/OLED.sh
8+
Restart=on-abort
9+
10+
[Install]
11+
WantedBy=multi-user.target
12+

OLED/oledV2.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import time
2+
import board
3+
import busio
4+
import subprocess
5+
import adafruit_ssd1306 as ssd1306
6+
from PIL import Image, ImageDraw, ImageFont
7+
8+
I2C = busio.I2C(board.SCL, board.SDA)
9+
ADDR = 0x3C
10+
RST = None
11+
oled = ssd1306.SSD1306_I2C(128, 32, I2C, addr=ADDR, reset=RST)
12+
13+
# Clear display
14+
oled.fill(0)
15+
oled.show()
16+
17+
width = oled.width
18+
height = oled.height
19+
image = Image.new('1', (width, height))
20+
21+
draw = ImageDraw.Draw(image)
22+
23+
draw.rectangle((0,0,width,height), outline=0, fill=0)
24+
25+
font = ImageFont.load_default()
26+
27+
padding = -2
28+
top = padding
29+
bottom = height - padding
30+
x = 0
31+
32+
while True:
33+
draw.rectangle((0,0,width,height), outline=0, fill=0)
34+
cmd = "hostname -I | cut -d\' \' -f1"
35+
ip = subprocess.check_output(cmd, shell=True)
36+
37+
cmd = "top -bn1 | grep load | awk '{printf \"CPU Load: %s%%\", $(NF-2)*100}'"
38+
cpu = subprocess.check_output(cmd, shell=True)
39+
40+
cmd = "free -m | awk 'NR==2{printf \"Mem: %.2f/%.2fGB %.2f%%\", $3/1024, $2/1024, $3*100/$2 }'"
41+
mem = subprocess.check_output(cmd, shell=True)
42+
43+
cmd = "df -h | awk '$NF==\"/\"{printf \"Disk: %d/%dGB %s\", $3, $2, $5}'"
44+
disk = subprocess.check_output(cmd, shell=True)
45+
46+
cmd = "vcgencmd measure_temp"
47+
temp = subprocess.check_output(cmd, shell=True)
48+
49+
draw.text((x, top), "IP: {}".format(ip.decode('utf-8')), font=font, fill=255)
50+
draw.text((x, top+8), "{}".format(cpu.decode('utf-8')), font=font, fill=255)
51+
draw.text((x, top+16), "{}".format(mem.decode('utf-8')), font=font, fill=255)
52+
draw.text((x, top+24), "{}".format(temp.decode('utf-8')), font=font, fill=255)
53+
54+
oled.image(image)
55+
#oled.display()
56+
oled.show()
57+
time.sleep(3)
58+
59+
60+
61+
62+
63+
64+
65+
66+
67+
68+
69+
70+
71+
72+
73+
74+
75+
76+
77+
78+
79+
80+
81+

README.md

Lines changed: 130 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,132 @@
11
# EP-0152 Fan Hat - **UPDATED for RPi 5**
2-
EP-0152 Fan Hat, sold on Amazon as [GeeekPi Fan Hat](https://a.co/d/0fnQFZCU)
2+
EP-0152 Fan Hat, sold on Amazon as [GeeekPi Fan Hat](https://a.co/d/0fnQFZCU). The [original code](https://wiki.52pi.com/index.php?title=EP-0152) listed for the fan hat is woefully out of date. The code in this repository is compatible with the following revisions and Bookworm:
33

4-
## Compatibility
5-
- Raspberry Pi 5B
6-
- Raspberry Pi 4B
7-
- Raspberry Pi 3B+/3B
8-
- Raspberry Pi 2B
4+
<img style="float: right;" src="https://wiki.52pi.com/images/e/e6/OLEDFAN%E6%B8%85%E5%8D%95.jpg">
5+
6+
- Raspberry Pi 5B (:white_check_mark: - Tested)
7+
- Raspberry Pi 4B (:white_check_mark: - Tested)
8+
- Raspberry Pi 3B+/3B (:question: - Untested)
9+
- Raspberry Pi 2B (:question: - Untested)
10+
11+
## Python Requirements
12+
13+
1. Create a Python Virtual Environment to install `pip` packages.
14+
15+
```bash
16+
sudo -i
17+
python3 -m venv /opt/EP-0152
18+
source /opt/EP-0152/bin/activate
19+
```
20+
21+
2. Install `pip3` packages:
22+
23+
```bash
24+
pip3 install pillow adafruit_circuitPython_ssd1306
25+
```
26+
27+
- For **Raspbery Pi 5**:
28+
29+
```bash
30+
pip3 uninstall RPI.GPIO
31+
pip3 install rpi-lgpio
32+
```
33+
34+
### Uninstallation of Python VEnv
35+
36+
```bash
37+
sudo rm -rf /opt/EP-0152
38+
```
39+
40+
## Fan Control
41+
I've added [@franganghi](https://github.com/franganghi)'s version of [Raspberry-Pi5-PWM-Fan-Control](https://github.com/franganghi/Raspberry-Pi5-PWM-Fan-Control) as a submodule to this repository.
42+
43+
- Follow the instructions listed in the [README](https://github.com/franganghi/Raspberry-Pi5-PWM-Fan-Control/tree/master?tab=readme-ov-file#raspberry-pi5-pwm-fan-control) to install [as a Linux service](https://github.com/franganghi/Raspberry-Pi5-PWM-Fan-Control/tree/master?tab=readme-ov-file#as-a-service).
44+
45+
46+
## PWM LEDs
47+
48+
### Installation
49+
50+
```bash
51+
cd EP-0152/LEDs
52+
sudo mkdir /opt/EP-0152/LEDs
53+
sudo cp ep0152ledpwm.service /lib/systemd/system/ep0152ledpwm.service
54+
sudo cp LEDsV2.* /opt/EP-0152/LEDs/.
55+
sudo chmod 644 /lib/systemd/system/ep0152ledpwm.service
56+
sudo chmod +x /opt/EP-0152/LEDs/LEDsV2.py
57+
sudo chmod +x /opt/EP-0152/LEDs/LEDsV2.sh
58+
sudo systemctl daemon-reload
59+
sudo systemctl enable --now ep0152ledpwm.service
60+
```
61+
62+
### Check status
63+
64+
```bash
65+
$ sudo systemctl status ep0152ledpwm.service
66+
● ep0152ledpwm.service - EP-0152 LEDs PWM Pulse
67+
Loaded: loaded (/lib/systemd/system/ep0152ledpwm.service; enabled; preset: enabled)
68+
Active: active (running) since Fri 2024-06-21 10:34:34 PDT; 1h 13min ago
69+
Main PID: 2701 (LEDsV2.sh)
70+
Tasks: 5 (limit: 9248)
71+
CPU: 3.627s
72+
CGroup: /system.slice/ep0152ledpwm.service
73+
├─2701 /bin/bash /opt/EP-0152/LEDs/LEDsV2.sh
74+
└─2710 python3 /opt/EP-0152/LEDs/LEDsV2.py
75+
76+
Jun 21 10:34:34 ussyukon systemd[1]: Started ep0152ledpwm.service - EP-0152 LEDs PWM Pulse.
77+
```
78+
79+
### Uninstallation
80+
81+
```bash
82+
sudo systemctl stop ep0152ledpwm.service
83+
sudo systemctl disable ep0152ledpwm.service
84+
sudo systemctl daemon-reload
85+
sudo rm /lib/systemd/system/ep0152ledpwm.service
86+
sudo rm -rf /opt/EP-0152/LEDs
87+
```
88+
89+
## OLED Screen
90+
91+
### Installation
92+
93+
```bash
94+
cd EP-0152/OLED
95+
sudo mkdir /opt/EP-0152/OLED
96+
sudo cp ep0152oled.service /lib/systemd/system/ep0152oled.service
97+
sudo cp oledV2.py /opt/EP-0152/OLED/.
98+
sudo cp OLED.sh /opt/EP-0152/OLED/.
99+
sudo chmod 644 /lib/systemd/system/ep0152oled.service
100+
sudo chmod +x /opt/EP-0152/LEDs/oledV2.py
101+
sudo chmod +x /opt/EP-0152/LEDs/OLED.sh
102+
sudo systemctl daemon-reload
103+
sudo systemctl enable --now ep0152oled.service
104+
```
105+
106+
107+
### Check Status
108+
109+
```bash
110+
$ sudo systemctl status ep0152oled.service
111+
● ep0152oled.service - EP-0152 OLED Monitor
112+
Loaded: loaded (/lib/systemd/system/ep0152oled.service; enabled; preset: enabled)
113+
Active: active (running) since Fri 2024-06-21 10:34:34 PDT; 1h 18min ago
114+
Main PID: 2703 (OLED.sh)
115+
Tasks: 2 (limit: 9248)
116+
CPU: 1min 729ms
117+
CGroup: /system.slice/ep0152oled.service
118+
├─2703 /bin/bash /opt/EP-0152/OLED/OLED.sh
119+
└─2711 python3 /opt/EP-0152/OLED/oledV2.py
120+
121+
Jun 21 10:34:34 ussyukon systemd[1]: Started ep0152oled.service - EP-0152 OLED Monitor.
122+
```
123+
124+
### Uninstallation
125+
126+
```bash
127+
sudo systemctl stop ep0152oled.service
128+
sudo systemctl disable ep0152oled.service
129+
sudo systemctl daemon-reload
130+
sudo rm /lib/systemd/system/ep0152oled.service
131+
sudo rm -rf /opt/EP-0152/OLED
132+
```

Raspberry-Pi5-PWM-Fan-Control

0 commit comments

Comments
 (0)