本文介绍了 Raspberry Pi Sensor HAT 扩展板结合 PicoClaw 实现智能读取传感器数据、远程数据采集、显示控制的项目设计。
项目介绍
通过 PicoClaw 远程读取 传感器数据和 LED 显示。
环境部署:PicoClaw 板端部署、模型配置、Web 对话、微信ClawBot对话等;
数据采集:采集单个和多个传感器数据、记录数据并给出演化曲线;
显示控制:显示传感器数据、天气图标、动图至 LED 矩阵;
PicoClaw
是一个轻量级个人 AI 助手。
采用 Go 语言编写,由 AI Agent 自身驱动整个架构迁移和代码优化;
极致轻量:内存占用小于 10MB;


架构


详见: .
硬件连接
将 SENSE-HAT 与树莓派 CM0 对应 40pin 接口连接;
使用 Type-C 数据线连接开发板和 5V 电源;


环境搭建
包括 PicoClaw 板端部署、模型配置、Web 端对话、微信接入、对话测试等。
安装
树莓派已烧录官方 OS,通过 SSH 连接互联网;
终端执行如下指令,拉取 PicoClaw 文件;
mkdir picoclaw && cd picoclaw wget https://github.com/sipeed/picoclaw/releases/latest/download/picoclaw_Linux_arm64.tar.gz tar -xzf picoclaw_Linux_arm64.tar.gz
初始化
终端执行 ./picoclaw onboard 指令,启动程序;


根据提示修改 home/ljl/.picoclaw/config.json 配置文件,终端执行
sudo nano /home/ljl/.picoclaw/config.json
在模型列表中添加 chat -ecnu 模型链接和秘钥;
{
"model_list": [
{
"model_name": "chat-ecnu",
"model": "ecnu-plus",
"api_base": "https://chat.ecnu.edu.cn/open/api/v1",
"api_key": "sk-4xxxx61xx4xxxx0bxxfaxxxx26xaxx84"
}
],
}保存文件。
Web UI
使用网页界面配置,终端执行
PICOCLAW_LAUNCHER_TOKEN=123456 ./picoclaw-launcher -public # Open http://localhost:18800 in your browser
浏览器输入 ip 地址 192.168.1.101:18800 打开网页,输入访问令牌 123456,进入 Web 配置界面


访问令牌可在左侧工具栏的 服务 - 配置 选项中修改。
模型配置
点击左侧菜单栏的 模型 选项,找到配置的目标模型;
点击编辑按钮,输入 API-KEY,设为默认;
点击左上角 启动服务 按钮;


网页对话
点击左侧工具栏的 对话 按钮,进入聊天界面;
输入消息即可开启文字对话;


获取开发板信息


获取 CPU 温度


连接微信
点击左侧工具栏 微信 选项卡,开启微信频道;
使用手机微信扫描加载出的二维码,绑定账号;


进入 ClawBot 微信机器人界面,开启对话


数据采集
单个传感器
读取单个传感器数据


多个传感器
读取 SENSE-HAT 板载多个传感器数据


演化曲线
给出一段时间内的数据变化曲线




打开 /home/ljl/.picoclaw/worksapce/sense_hat_quick.png 文件,显示各个传感器数据的历史演化曲线


显示控制
传感器数据


代码
from sense_hat import SenseHat
import time
sense = SenseHat()
def main():
print("=" * 50)
print("Sense HAT Temperature Display")
print("=" * 50)
try:
while True:
# Get current temperature
temp = sense.get_temperature()
temp_text = f"{int(temp)}C"
color = get_temp_color(temp)
# Scroll the temperature text on the LED matrix
sense.show_message(
temp_text,
scroll_speed=0.1,
text_colour=color
)
print(f"Displaying: {temp_text} Color: {color}")
# Wait before updating (2 seconds)
time.sleep(2)
if __name__ == "__main__":
main()效果如下,温度数据滚动显示


天气图标

代码
from sense_hat import SenseHat
import requests
import time
sense = SenseHat()
def get_icon_color(weather_type):
"""Get color for weather icon"""
colors = {
'sunny': COLOR_YELLOW,
'partly_cloudy': COLOR_YELLOW,
'cloudy': COLOR_WHITE,
'rainy': COLOR_BLUE,
'stormy': COLOR_PURPLE,
'snowy': COLOR_LIGHT_BLUE
}
return colors.get(weather_type, COLOR_GRAY)
def main():
print("=" * 50)
print("Sense HAT Weather Icon Display (Shanghai)")
print("=" * 50)
while True:
# Get current weather for Shanghai
weather_icon, weather_code = get_shanghai_weather()
print(f"Shanghai Weather - Code: {weather_code}, Icon: {weather_icon}")
# Display weather icon
display_weather_icon(weather_icon)
# Wait before updating (60 seconds)
time.sleep(60)
if __name__ == "__main__":
main()该程序可联网获取当地天气,并控制矩阵 LED 显示天气图标,多云效果如下


动图


终端运行程序,效果如下


总结
我要赚赏金
