关于
该,以及在完成的设备上可以运行的各种程序。是一款扩展板,可为您的 Raspberry Pi 提供一系列传感功能。其板载传感器允许您监测气压、湿度、温度、颜色、方向和运动。8×8 RGB LED 矩阵可让您将传感器数据可视化。五个按键的操纵杆使用户能够与您的项目进行交互。
官方支持的Python 库提供了对板载传感器、LED 矩阵和操纵杆的访问接口。Sense HAT 兼容任何带有 40 针 GPIO 接口的 Raspberry Pi 设备。
特点
Sense HAT 配备 8×8 RGB LED 矩阵和五键操纵杆,并包含以下传感器:
-
陀螺仪
-
加速度计
-
磁力计
-
温度
-
气压
-
湿度
-
颜色与亮度
Sense HAT 和 Sense HAT V2 的原理图与机械图可供下载,位于产品信息门户.
LED矩阵
LED matrix 是一个 RGB565帧缓冲区,其 id 为RPi-Sense FB. The appropriate device node can be written to as a standard file or mmap-ed. The included snake example shows how to access the framebuffer.
操纵杆
joystick 会作为名为Raspberry Pi Sense HAT Joystick, mapped to the arrow keys and 输入的输入事件设备出现。任何能够处理输入的库都支持它,也可直接通过evdev接口使用。合适的库包括对于代码,他使用了几个开源工具,例如, pygame以及python-evdev。随附的snake example shows how to access the joystick directly.
安装
为了正常工作,Sense HAT 需要:
-
最新的 kernel
-
I2C在你的 Raspberry Pi 上启用
-
一些依赖项
完成以下步骤,让你的 Raspberry Pi 设备准备好连接到 Sense HAT:
-
首先,确保你的 Raspberry Pi 运行最新的软件。运行以下命令进行更新:
$ sudo apt update && sudo apt full-upgrade -
接下来,安装
sense-hatpackage, which will ensure the kernel is up to date, enable I2C, and install the necessary dependencies:$ sudo apt install sense-hat -
最后,重启你的 Raspberry Pi 以启用 I2C 并加载新的 kernel(如果它发生了变化):
$ sudo reboot
校准
安装必要的软件,并按如下方式运行校准程序:
$ sudo apt update
$ sudo apt install octave -y
$ cd
$ cp /usr/share/librtimulib-utils/RTEllipsoidFit ./ -a
$ cd RTEllipsoidFit
$ RTIMULibCal
校准程序显示以下菜单:
Options are: m - calibrate magnetometer with min/max e - calibrate magnetometer with ellipsoid (do min/max first) a - calibrate accelerometers x - exit Enter option:
按下小写m. The following message will then show. Press any key to start.
Magnetometer min/max calibration ------------------------------- Waggle the IMU chip around, ensuring that all six axes (+x, -x, +y, -y and +z, -z) go through their extrema. When all extrema have been achieved, enter 's' to save, 'r' to reset or 'x' to abort and discard the data. Press any key to start...
启动后,你会看到类似以下内容在屏幕上向上滚动:
Min x: 51.60 min y: 69.39 min z: 65.91 Max x: 53.15 max y: 70.97 max z: 67.97
请关注屏幕最底部的两行,因为它们是程序最近发布的测量值。
现在,拿起 Raspberry Pi 和 Sense HAT,并尽可能以你能想到的每一种方式移动它。拔掉所有非必要线缆以避免杂乱会有所帮助。
尝试在 pitch、roll 和 yaw 三个轴向上各画出一个完整的圆。操作时注意不要意外弹出 SD card。花几分钟移动 Sense HAT,当你发现数字不再变化时就停下来。
现在按下小写s then lowercase x to exit the program. If you run the ls command now, you’ll see a new RTIMULib.ini file has been created.
除了这些步骤外,你还可以通过执行上述步骤来进行 ellipsoid fit,但需按下e instead of m.
完成后,复制生成的RTIMULib.ini to /etc/ and remove the local copy in ~/.config/sense_hat/:
$ rm ~/.config/sense_hat/RTIMULib.ini
$ sudo cp RTIMULib.ini /etc
入门指南
安装后,示例代码可在以下位置找到/usr/src/sense-hat/examples.
在 Python 中使用 Sense HAT
sense-hat is the officially supported library for the Sense HAT; it provides access to all of the on-board sensors and the LED matrix.
该库的完整文档可在以下位置找到sense-hat.readthedocs.io.
在 C++ 中使用 Sense HAT
RTIMULib是一个 C++ 和 Python 库,可让在嵌入式 Linux 系统上轻松使用 9-dof 和 10-dof IMU。预校准的设置文件提供在/etc/RTIMULib.ini, which is also copied and used by sense-hat. The included examples look for RTIMULib.ini in the current working directory, so you might want to copy the file there to get more accurate data.
RTIMULibDrive11 示例已预编译,以帮助确保一切按预期工作。可通过运行以下命令启动RTIMULibDrive11 and closed by pressing Ctrl C.
[5] 读取和写入 EEPROM 数据make in the appropriate directory.
|
故障排除
读取和写入EEPROM数据
这些步骤仅用于调试目的。
| 在 Raspberry Pi 2 Model B Rev 1.0 和 Raspberry Pi 3 Model B 板上,这些步骤可能无法工作。固件将接管 I2C0,导致 ID 引脚被配置为输入。 |
在您能够从 Sense HAT 读取 EEPROM 数据以及向 Sense HAT 写入 EEPROM 数据之前,必须完成以下步骤:
-
通过将以下行添加到以下位置来启用 I2C0 和 I2C1:
/boot/firmware/config.txt文件中:dtparam=i2c_vc=on dtparam=i2c_arm=on -
运行以下命令以重启:
$ sudo reboot -
下载并构建 flash tool:
$ git clone https://github.com/raspberrypi/hats.git $ cd hats/eepromutils $ make
阅读
要读取 EEPROM 数据,请运行以下命令:
$ sudo ./eepflash.sh -f=sense_read.eep -t=24c32 -r
写入
| 此操作不会损坏您的 Raspberry Pi 或 Sense HAT,但如果发生错误,您的 Raspberry Pi 可能无法自动检测到 HAT。 |
-
首先,下载 EEPROM 设置并构建
.eepbinary:$ wget https://github.com/raspberrypi/rpi-sense/raw/master/eeprom/eeprom_settings.txt -O sense_eeprom.txt $ ./eepmake sense_eeprom.txt sense.eep /boot/firmware/overlays/rpi-sense-overlay.dtb -
接下来,禁用写保护:
$ i2cset -y -f 1 0x46 0xf3 1 -
写入 EEPROM 数据:
$ sudo ./eepflash.sh -f=sense.eep -t=24c32 -w -
最后,重新启用写保护:
$ i2cset -y -f 1 0x46 0xf3 0