USAGE.md 4.6 KB

树莓派OLED系统监控使用说明

快速开始

1. 硬件准备

确保您拥有以下组件:

  • 树莓派4B
  • SSD1306 OLED显示屏(128x64像素)
  • 1MΩ电阻
  • 杜邦线若干
  • 金属触摸片或导电材料

2. 硬件连接

按照以下方式连接OLED显示屏和触摸传感器:

OLED显示屏连接:

OLED引脚 树莓派引脚
VCC 5V (Pin 5)
GND GND (Pin 6)
SDA SDA (Pin 3)
SCL SCL (Pin 5)

触摸传感器连接:

  1. 将1MΩ电阻一端连接到GPIO18 (物理引脚12)
  2. 将电阻另一端连接到金属触摸片
  3. 将金属触摸片连接到GPIO24 (物理引脚18)

3. 软件安装

在树莓派终端中执行以下命令:

# 切换到root用户
sudo -i

# 进入项目目录
cd /path/to/树莓派OLED系统监控完整解决方案

# 给安装脚本添加执行权限
chmod +x install.sh

# 运行安装脚本
./install.sh

按照安装向导的提示完成安装过程。

显示界面说明

安装完成后,OLED显示屏会显示以下系统信息:

  1. 第一行:CPU使用率和温度(例如:CPU 25% 45°C)
  2. 第二行:内存使用情况(例如:内存 1.2G/3.8G)
  3. 第三行:磁盘空间使用情况(例如:硬盘 15G/58G)
  4. 第四行:系统运行时间(例如:运行 2天15小时)
  5. 第五行:IP地址(例如:IP 192.168.1.100)
  6. 第六行:当前时间(例如:TIME 14:30:25)

使用方法

触摸唤醒

  • 屏幕默认会在30秒无操作后自动熄灭以节省电量
  • 轻触金属触摸片即可唤醒屏幕显示系统信息
  • 再次触摸可保持屏幕常亮状态

手动测试

如果您想手动测试程序运行情况,可以在终端中执行:

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

常见问题解决

1. 屏幕不显示任何内容

  • 检查OLED显示屏接线是否正确
  • 确认I2C接口已启用:sudo raspi-config -> Interfacing Options -> I2C -> Enable
  • 使用i2cdetect -y 1命令检查设备是否被识别

2. 触摸功能无效

  • 检查GPIO连接是否正确
  • 确认使用的是1MΩ电阻
  • 在调试模式下运行程序查看触摸检测日志

3. 中文显示乱码

  • 确认已安装中文字体
  • 检查字体文件是否存在:ls /usr/share/fonts/truetype/wqy/

4. 服务无法启动

  • 查看服务状态和错误信息:systemctl status oled-monitor-final.service
  • 检查程序文件权限:ls -l /opt/oled_monitor_final/
  • 验证Python依赖是否安装完整

自定义配置

修改显示内容

编辑 /opt/oled_monitor_final/oled_system_monitor_final.py 文件:

  1. 找到 draw_main_screen() 函数
  2. 修改各系统信息的显示位置和格式
  3. 保存文件后重启服务: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  # 自动熄屏时间(秒)

卸载程序

如果需要卸载程序,可以执行以下步骤:

  1. 停止并禁用服务:

    systemctl stop oled-monitor-final.service
    systemctl disable oled-monitor-final.service
    
  2. 删除服务文件:

    rm /etc/systemd/system/oled-monitor-final.service
    systemctl daemon-reload
    
  3. 删除程序文件:

    rm -rf /opt/oled_monitor_final
    

技术支持

如有其他问题,请参考以下资源:

  • 项目源代码:oled_system_monitor_final.py 和 install.sh
  • 系统日志:/opt/oled_monitor_final/logs/