Cov txheej txheem:

Raspberry Pi Monitoring System Via OLED Display Module: 5 Kauj Ruam
Raspberry Pi Monitoring System Via OLED Display Module: 5 Kauj Ruam

Video: Raspberry Pi Monitoring System Via OLED Display Module: 5 Kauj Ruam

Video: Raspberry Pi Monitoring System Via OLED Display Module: 5 Kauj Ruam
Video: How To Setup a OLED Display on The Raspberry Pi 2024, Kaum ib hlis
Anonim
Raspberry Pi Kev Saib Xyuas Txheej Txheem Ntawm OLED Zaub Module
Raspberry Pi Kev Saib Xyuas Txheej Txheem Ntawm OLED Zaub Module

Hauv qhov kev qhia no kuv yuav piav qhia yuav teeb tsa 0.96 nti OLED zaub module rau qhia cov ntaub ntawv txheej txheem ntawm Raspberry Pi 4 Model B siv nws I2C interface.

Khoom siv

Yuav tsum tau kho vajtse:

  • Raspberry Pi 4 Qauv B.
  • 128 × 64 OLED zaub module (SSD1306)
  • Txuas Txuas

Kauj Ruam 1: Kev Kho Vajtse Txuas

Kho vajtse txuas
Kho vajtse txuas

Hauv qab no yog kev sib txuas ntawm OLED module nrog Raspberry Pi 4 Qauv B:

  • SDA ==> GPIO 2 (tus pin 3)
  • SCL ==> GPIO 3 (tus pin 5)
  • VCC ==> 3.3V (tus pin 1)
  • GND ==> GND (pin 14)

Kauj ruam 2: Pab kom I2C Interface

I2C interface yog neeg xiam oob khab yog li koj xav tau los pab nws. Koj tuaj yeem ua qhov no hauv cov cuab yeej raspi-teeb tsa ntawm kab hais kom ua los ntawm kev khiav:

sudo raspi-teeb tsa

  1. Ib qho screen xiav yuav tshwm. Tam sim no xaiv qhov kev xaiv cuam tshuam.
  2. Tom qab qhov no, peb yuav tsum xaiv I2C xaiv.
  3. Tom qab qhov no, peb yuav tsum xaiv Yog thiab nias nkag mus thiab tom qab ntawd ua tiav.
  4. Tom qab qhov no, peb yuav tsum tau rov pib dua Raspberry Pi los ntawm kev ntaus hauv qab cov lus txib:

sudo rov pib dua

Cov tsev qiv ntawv hauv qab no tej zaum yuav raug teeb tsa tab sis khiav cov lus txib no ib qho kom ntseeg tau tias:

sudo apt-tau nruab python-smbus

sudo apt-tau nruab i2c-cuab yeej

Txhawm rau nrhiav cov npe khoom siv txuas nrog I2C npav ntawm Raspberry Pi koj tuaj yeem siv cov lus txib hauv qab no:

sudo i2cdetect -y 1

Ntawm cov laus Raspberry Pi ntaus cov lus txib hauv qab no:

sudo i2cdetect -y 0

Nov yog qhov tso tawm kuv pom ntawm kuv Raspberry Pi 4 Qauv B:

0 1 2 3 4 5 6 7 8 9 a b c d e f

00: -- -- -- -- -- -- -- -- -- -- -- -- --

10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

30: - - - - - - - - - - - -3c - - -

40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

70: -- -- -- -- -- -- -- --

Nws tau qhia tias lub cuab yeej tau kuaj pom nrog qhov chaw nyob ntawm 0x3c. Nov yog qhov chaw nyob hex tsis zoo rau hom cuab yeej no.

Kauj Ruam 3: Nruab Adafruit Python Library rau OLED Display Module

Txhawm rau teeb tsa lub tsev qiv ntawv peb yuav clone Adafruit git chaw cia khoom.

git clone

Thaum ua tiav mus rau lub tsev qiv ntawv cov npe:

cd Adafruit_Python_SSD1306

thiab teeb tsa lub tsev qiv ntawv rau Python 2:

sudo python setup.py nruab

lossis rau Python 3:

sudo python3 setup.py nruab

Kauj ruam 4: System Saib Python Script

System Saib Python Script
System Saib Python Script

Nkag mus rau hauv cov piv txwv piv txwv:

cd piv txwv

Hauv daim nplaub tshev no koj yuav tsum pom cov ntawv piv txwv:

stats.py

sej 3 stats.py

Los ntawm lub neej ntawd nws qhia txog kev siv nco, siv disk, CPU thauj khoom thiab tus IP chaw nyob. Tsis tas li, b-ua ntej ntawm txhua kab tuaj yeem pom.

Nws yuav hloov kho me ntsis txhawm rau tshem tawm b-ua ntej thiab ntxiv CPU kub ntawm Raspberry Pi 4 Qauv B ib yam.

cmd = "hostname -I | txiav -d / '\' -f1"

yuav raug hloov los ntawm cov kab hauv qab no:

cmd = "hostname -I | txiav -f 2 -d ''"

Cov cai no zoo meej rau khau raj thaum koj xav nrhiav koj li Raspberry Pi tus IP chaw nyob rau SSH lossis VNC.

Cov kab hauv qab no yuav raug ntxiv los qhia CPU kub ntawm OLED zaub module:

cmd = "vcgencmd ntsuas_temp | txiav -f 2 -d '='"

temp = subprocess.check_output (cmd, plhaub = Tseeb)

Hauv qab cov cai tau hloov kho kom tshem tawm 'b' tus cwj pwm los ntawm OLED zaub.

draw.text ((x, saum), "IP:" + str (IP, 'utf-8'), font = font, sau = 255) kos.text ((x, saum + 8), str (CPU, 'utf-8') + "" + str (temp, 'utf-8'), font = font, fill = 255) kos.text ((x, saum + 16), str (MemUsage, 'utf-8')), font = font, fill = 255) draw.text ((x, top+25), str (Disk, 'utf-8'), font = font, fill = 255)

Thaum kawg, koj yuav tsum pom qee yam zoo ib yam li cov hauv qab no ntawm OLED zaub:

Kauj ruam 5: Khiav Stats.py ntawm Startup

Koj tuaj yeem yooj yim ua nws yog li qhov haujlwm no ua haujlwm txhua lub sijhawm koj khau raj koj Raspberry Pi.

Txoj kev nrawm tshaj plaws thiab yooj yim tshaj plaws yog muab tso rau hauv /etc/rc.local. Khiav cov lus txib hauv qab no ntawm lub davhlau ya nyob twg:

sudo nano /etc/rc.local

Scroll cia, thiab ua ntej tawm kab 0 kab, sau cov hauv qab no:

sudo nab hab sej /home/pi/stats.py &

  • Txuag thiab tawm.
  • Rov pib dua kom paub tseeb tias lub vijtsam tuaj txog ntawm khau raj!

Pom zoo: