RaspberryPi,5110液晶显示CPU+GPU占用

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

RaspberryPi,5110液晶显⽰CPU+GPU占⽤
#!/usr/bin/python
# -*- coding: utf-8 -*-
import RPi.GPIO as GPIO
import commands
import os
import time
import sys
#gpio's :
SCLK = 18
DIN = 15
DC = 13
RST = 11
font =[
0x00,0x3e,0x51,0x49,0x45,0x3e,#0 0x00,0x00,0x42,0x7f,0x40,0x00,#1 0x00,0x42,0x61,0x51,0x49,0x46,#2
0x00,0x21,0x41,0x45,0x4b,0x31,#3 0x00,0x18,0x14,0x12,0x7f,0x10,#4 0x00,0x27,0x45,0x45,0x45,0x39,#5
0x00,0x3c,0x4a,0x49,0x49,0x30,#6 0x00,0x01,0x71,0x09,0x05,0x03,#7 0x00,0x36,0x49,0x49,0x49,0x36,#8
0x00,0x06,0x49,0x49,0x29,0x1e,#9 0x7E, 0x11, 0x11, 0x11, 0x7E, # A 0x7F, 0x49, 0x49, 0x49, 0x36, # B 0x3E, 0x41, 0x41, 0x41, 0x22, # C 0x7F, 0x41, 0x41, 0x22, 0x1C, # D 0x7F, 0x49, 0x49, 0x49, 0x41, # E 0x7F, 0x09, 0x09, 0x09, 0x01, # F
0x3E, 0x41, 0x49, 0x49, 0x7A, # G 0x7F, 0x08, 0x08, 0x08, 0x7F, # H 0x00, 0x41, 0x7F, 0x41, 0x00, # I 0x20, 0x40, 0x41, 0x3F, 0x01, # J 0x7F, 0x08, 0x14, 0x22, 0x41, # K 0x7F, 0x40, 0x40, 0x40, 0x40, # L 0x7F, 0x02, 0x0C, 0x02, 0x7F, # M
0x7F, 0x04, 0x08, 0x10, 0x7F, # N 0x3E, 0x41, 0x41, 0x41, 0x3E, # O 0x7F, 0x09, 0x09, 0x09, 0x06, # P 0x3E, 0x41, 0x51, 0x21, 0x5E, # Q 0x7F, 0x09, 0x19, 0x29, 0x46, # R 0x46, 0x49, 0x49, 0x49, 0x31, # S 0x01, 0x01, 0x7F, 0x01, 0x01, # T
0x3F, 0x40, 0x40, 0x40, 0x3F, # U
0x1F, 0x20, 0x40, 0x20, 0x1F, # V
0x3F, 0x40, 0x38, 0x40, 0x3F, # W
0x63, 0x14, 0x08, 0x14, 0x63, # X
0x07, 0x08, 0x70, 0x08, 0x07, # Y
0x61, 0x51, 0x49, 0x45, 0x43, # Z
]
def get_cpu_temp():
tempFile = open( "/sys/class/thermal/thermal_zone0/temp" )
cpu_temp = tempFile.read()
tempFile.close()
return float(cpu_temp)/1000
# Uncomment the next line if you want the temp in Fahrenheit
#return (1.8*cpu_temp)+32
def get_gpu_temp():
gpu_temp = commands.getoutput( '/opt/vc/bin/vcgencmd measure_temp' ).replace( 'temp=', '' ).replace( '\'C', '' ) return float(gpu_temp)
# Uncomment the next line if you want the temp in Fahrenheit
# return (1.8* gpu_temp)+32
def main():
begin(0xbc) # contrast - may need tweaking for each display
gotoxy(0,0)
text("CPU")
display_char (cpu_temp)
def gotoxy(x,y):
lcd_cmd(x+128)
lcd_cmd(y+64)
def text(words):
for i in range(len(words)):
# print (words[i])
display_char(words[i])
def display_char(char):
index=(ord(char)-65)*5
if ord(char) >=65 and ord(char) <=90:
for i in range(5):
# print (index+i)
lcd_data(font[index+i])
lcd_data(0) # space inbetween characters
elif ord(char)==32:
lcd_data(0)
lcd_data(0)
lcd_data(0)
lcd_data(0)
lcd_data(0)
lcd_data(0)
def cls():
gotoxy(0,0)
for i in range(84):
for j in range(6):
lcd_data(0)
def setup():
# set pin directions
GPIO.setmode(GPIO.BOARD) GPIO.setup(DIN, GPIO.OUT) GPIO.setup(SCLK, GPIO.OUT) GPIO.setup(DC, GPIO.OUT) GPIO.setup(RST, GPIO.OUT)
def begin(contrast):
setup()
# toggle RST low to reset
GPIO.output(RST, False)
time.sleep(0.100)
GPIO.output(RST, True)
lcd_cmd(0x21) # extended mode
lcd_cmd(0x14) # bias
lcd_cmd(contrast) # vop
lcd_cmd(0x20) # basic mode
lcd_cmd(0xc) # non-inverted display cls()
def SPI(c):
# data = DIN
# clock = SCLK
# MSB first
# value = c
for i in xrange(8):
GPIO.output(DIN, (c & (1 << (7-i))) > 0) GPIO.output(SCLK, True)
GPIO.output(SCLK, False)
def lcd_cmd(c):
# print ("lcd_cmd sent :",hex(c)) GPIO.output(DC, False)
SPI(c)
def lcd_data(c):
# print ("data sent :",hex(c))
GPIO.output(DC, True)
SPI(c)
if __name__ == "__main__": main()。

相关文档
最新文档