确保您拥有以下组件:
按照以下方式连接OLED显示屏和触摸传感器:
| OLED引脚 | 树莓派引脚 |
|---|---|
| VCC | 5V (Pin 5) |
| GND | GND (Pin 6) |
| SDA | SDA (Pin 3) |
| SCL | SCL (Pin 5) |
在树莓派终端中执行以下命令:
# 切换到root用户
sudo -i
# 进入项目目录
cd /path/to/树莓派OLED系统监控完整解决方案
# 给安装脚本添加执行权限
chmod +x install.sh
# 运行安装脚本
./install.sh
按照安装向导的提示完成安装过程。
安装完成后,OLED显示屏会显示以下系统信息:
如果您想手动测试程序运行情况,可以在终端中执行:
cd /opt/oled_monitor_final
python3 oled_system_monitor_final.py
安装完成后,系统监控程序会作为systemd服务自动运行。
systemctl status oled-monitor-final.service
# 启动服务
systemctl start oled-monitor-final.service
# 停止服务
systemctl stop oled-monitor-final.service
# 重启服务
systemctl restart oled-monitor-final.service
# 设置开机自启
systemctl enable oled-monitor-final.service
# 取消开机自启
systemctl disable oled-monitor-final.service
# 实时查看服务日志
journalctl -u oled-monitor-final.service -f
# 查看最近的日志
journalctl -u oled-monitor-final.service --since "10 minutes ago"
# 查看程序日志
tail -f /opt/oled_monitor_final/logs/monitor.log
# 查看错误日志
tail -f /opt/oled_monitor_final/logs/error.log
sudo raspi-config -> Interfacing Options -> I2C -> Enablei2cdetect -y 1命令检查设备是否被识别ls /usr/share/fonts/truetype/wqy/systemctl status oled-monitor-final.servicels -l /opt/oled_monitor_final/编辑 /opt/oled_monitor_final/oled_system_monitor_final.py 文件:
draw_main_screen() 函数systemctl restart oled-monitor-final.service在 oled_system_monitor_final.py 文件中找到 check_touch() 函数:
# 调整这些参数来改变触摸灵敏度
CHARGE_THRESHOLD = 5000 # 充电时间阈值
SAMPLE_COUNT = 10 # 采样次数
在 oled_system_monitor_final.py 文件中找到以下变量:
SCREEN_TIMEOUT = 30 # 自动熄屏时间(秒)
如果需要卸载程序,可以执行以下步骤:
停止并禁用服务:
systemctl stop oled-monitor-final.service
systemctl disable oled-monitor-final.service
删除服务文件:
rm /etc/systemd/system/oled-monitor-final.service
systemctl daemon-reload
删除程序文件:
rm -rf /opt/oled_monitor_final
如有其他问题,请参考以下资源: