标签:mamicode range __name__ spi redirect img global byte 执行文件
物件:
orangepi一套(电源,网线,orangepiPC)110元
nokia 5110 lcd 接线8跟 15块
展示:
使用python操作orangepi_PC 的gpio需要安装 https://github.com/duxingkei33/orangepi_PC_gpio_pyH3
想在orangepi_PC中驱动 nokia5110 需要 编译 cd8544_rpi https://github.com/nopnop2002/pcd8544_rpi
安装方法
git clone https://github.com/nopnop2002/pcd8544_rpi
cd pcd8544_rpi/
cc -o nokia nokia.c fontx.c pcd8544.c -lwiringPi -lpthread
bash ./test.sh
简单使用说明。
? > 最大支持6行,4X8一行可以显示个字符20 6X8一行可以可显示12左右吧
上面编译一个nokia的可执行文件,之后我们使用这个可执行文件来操作nokia5110
常用操作指令 | --- | 说明 |
---|---|---|
nokia r | --- | 清屏 |
./nokia +1 "ABCDEFG" | --- | 在第一行以4X8显示字符串"ABCDEFG" |
./nokia +2 "ABCDEFG" | --- | 在第二行以6X8显示字符串"ABCDEFG" |
./nokia +a "ABCDEFG" | --- | 在第一行以6X8显示字符串"ABCDEFG" |
./nokia +f "ABCDEFG" | --- | 在第六行以6X8显示字符串"ABCDEFG" |
./nokia c 60 | --- | 设置对比度为60 |
./nokia s | --- | 显示 |
GPIO接口(按示意图连接OrangePi gpio口和 nokia5110)
NOKIA5110 | --- | RPi/OPi | 物理针脚编号 |
---|---|---|---|
1 RST | --- | GPIO23 | (Pin#16) |
2 CE | --- | SPI CE0 | (Pin#24) |
3 DC | --- | GPIO24 | (PIn#18) |
4 DIN | --- | SPI MOSI | (Pin#19) |
5 CLK | --- | SPI SCLK | (Pin#23) |
6 VCC | --- | 3.3V | |
7 BL | --- | 3.3V/GND(*) | |
8 GND | --- | GND |
nokia5110的第7pin(背光) 可以选择接地(灭背光)或3.3v(亮背光)。
连接导线时注意第一个针脚旁边有小白色三角标志
使用supervisord 管理frpc 和 状态刷新程序。
supervisord的配置文件
directory = /tmp
command = /usr/bin/frpc -c /etc/frp/frpc.ini
autostart = true
startsecs = 10
autorestart = true
startretries = 3
user = root
redirect_stderr = true
stdout_logfile_maxbytes = 20MB
stdout_logfile_backups = 20
stdout_logfile = /tmp/frac.log
[program:orangePiStatus]
directory = /root/pcd8544_rpinew/
command = /usr/bin/python /root/pcd8544_rpinew/status.py
autostart = true
startsecs = 10
autorestart = true
startretries = 3
user = root
redirect_stderr = true
stdout_logfile_maxbytes = 20MB
stdout_logfile_backups = 20
stdout_logfile = /tmp/orangepiStatus.log
frpc.ini
server_addr = serverip
server_port = 9000
token= 20192019
[orangepi_ssh]
type = tcp
local_ip = 127.0.0.1
local_port = 22
remote_port = 6223
https://github.com/fatedier/frp
操作屏幕的python脚本(status.py)
import os
import time
import commands
SLEEPTIME=10 #every 10s
times=0
WANIP=commands.getstatusoutput("curl -s http://members.3322.org/dyndns/getip")[1]
def getdatas():
line0='UpTime:{}'
line1='TP:{}.PC:{}' #temp pscount
line2='LD:{}'
line3='Frpc:{}'#running stop
line4='WANIP:'
line5='Net:{}'
uptime= commands.getstatusoutput("uptime|awk '{print $3$4}'")[1][0:-1].replace(',','')
temp= commands.getstatusoutput("cat /sys/class/thermal/thermal_zone0/temp")[1]
psCount= commands.getstatusoutput("ps aux|wc -l")[1].replace(' ','')
load = commands.getstatusoutput("uptime|awk -Faverage: '{print $2}'")[1].replace(' ','')
global times
if times>=60:
wanip=commands.getstatusoutput("curl -s http://members.3322.org/dyndns/getip")[1]
global WANIP
WANIP=wanip
times=0
else:
wanip=WANIP
times += 1
network= commands.getstatusoutput("ping baidu.com -c 1 2>/dev/null|grep -q time && echo Online ||echo offline")[1]
frpc= commands.getstatusoutput("ps aux|grep -q frpc && echo Running ||echo Stoped")[1]
return [line0.format(uptime),line1.format(temp,psCount),line2.format(load),line3.format(frpc),line5.format(network),wanip if wanip else "Offline"]
def show():
''
os.system('./nokia r')
line=0
a=['a','b','3','d','e','6']
for i in getdatas():
# print("nokia {} {}".format(line,i))
os.system("./nokia +{} {}".format(a[line],i))
line += 1
os.system('./nokia c 60')
def loop():
''
while True:
time.sleep(SLEEPTIME)
show()
def main():
loop()
if __name__=="__main__":
main()
之后可以设置个开机脚本来启动supervisord
即可。 也可以用systemctl
管理.
之后在外网也可轻松管理orangepi了。
【后续,有必要再补充!】
玩转orangpi 之frpc远程管理+pcd8544(nokia5110 屏幕) 显示运行状态
标签:mamicode range __name__ spi redirect img global byte 执行文件
原文地址:https://www.cnblogs.com/lovesKey/p/11044439.html