概要
-
Sense HATを使う
-
温度センサーは、あてにならなそう。ラズパイ本体の熱で、温度があがる。
-
Pythonなら、
from sense_hat import SenseHat
python
from sense_hat import SenseHat
sense = SenseHat()
sense.get_temperature()
sense.get_humidity()
sense.get_pressure()
```py:実行例
pi@raspberrypi:~ $ python3
Python 3.4.2 (default, Oct 19 2014, 13:31:11)
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from sense_hat import SenseHat
>>> sense = SenseHat()
>>> sense.get_temperature()
22.5
>>> sense.get_humidity()
58.62303924560547
>>> sense.get_pressure()
0
>>> sense.get_pressure()
1022.631591796875
>>>
-
LEDマトリクスは、
/dev/fb1
(フレームバッファ)-
cat /dev/fb1 > fb1.raw
とすると、128バイトファイルができる。1ピクセル16ビット - 画面クリア
cat /dev/zero | head -c 128 > /dev/fb1
- ランダム
cat /dev/urandom | head -c 128 > /dev/fb1
- ランダムループ
while true; do cat /dev/urandom | head -c 128 > /dev/fb1 ; sleep 0.1; done
-
-
raspberrypi.orgのリンク
環境
- Raspberry Pi 2/3
- Sense HAT
- Raspbian :
2016-09-23-raspbian-jessie.img
=> すぐにSenseHATが使える
Sesne HATについて
ハードウェア
-
表
| | | | |
|:-:|:-:|:-:|:-:|
|1| 8×8 RGB LED matrix | 8×8 RGB LEDマトリックス |LED2472 LEDドライバIC (STMicroelectronics) |
|2| five-button joystick | 5ボタンジョイスティック | SKRHABE010 (ALPS)|
|3| Gyroscope | ジャイロスコープ | LSM9DS1 (STMicroelectronics) |
|4| Accelerometer | 加速度計 | 同上 |
|5| Magnetometer | 磁力計 | 同上 |
|6| Barometric pressure | 気圧計 | LPS25H (STMicroelectronics)|
|7| Temperature | 温度計 | HTS221 (STMicroelectronics) |
|8| Humidity | 湿度計 | 同上 |- LEDマトリクスとジョイスティックは、AVRマイコン(ATTINY88-MUR)にて制御される
- STマイクロだらけ。
-
I2C
pi@raspberrypi:~ $ i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- 1c -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- UU -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- 5c -- -- 5f
60: -- -- -- -- -- -- -- -- -- -- 6a -- -- -- -- --
70: -- -- -- -- -- -- -- --
pi@raspberrypi:~ $
0x1c = LSM9DS1: Accelerometer and gyroscope
0x6a = LSM9DS1: Magnetic sensor
0x5c = LPS25H: EMS pressure sensor: 260-1260 hPa absolute digital output barometer
0x5f = HTS221: Capacitive digital sensor for relative humidity and temperature
0x46 = (要確認)UUとなってるので、カーネルドライバ。LEDマトリクスのフレームバッファかと。AVRに接続されているやつ?
- I2C0に、CAT24C32WI-GT3 (EEPROM 32K-Bit I2C Serial EEPROM) => 自動コンフィギュレーションに使用
> [*Introducing Raspberry Pi HATs*](https://www.raspberrypi.org/blog/introducing-raspberry-pi-hats/) より
> The automatic configuration is achieved using 2 dedicated pins (ID_SD and ID_SC) on the 40W B+ GPIO header that are reserved for an I2C EEPROM. The EEPROM holds the board manufacturer information, GPIO setup and a thing called a ‘device tree‘ fragment – basically a description of the attached hardware that allows Linux to automatically load the required drivers.
>
> (ぐーぐる先生翻訳)
> 自動構成は、I2C EEPROM用に予約されている40W B + GPIOヘッダーの2つの専用ピン(ID_SDおよびID_SC)を使用して実現されます。 EEPROMには、ボードメーカーの情報、GPIOセットアップ、および「デバイスツリー」フラグメントというものがあります。基本的には、Linuxが自動的に必要なドライバをロードするためのハードウェアの説明です。
<!--
```/boot/config.txtに追加すると、I2C0が見れる
dtparam=i2c_vc=on
dtparam=i2c_arm=on
```txt:I2C0
pi@raspberrypi:~ $ i2cdetect -y 0
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- 1c -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- 43 -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
-->
- 素のときと比べて、SenseHAT取り付け時に読み込まれるモジュール
```txt:
rpisense_fb 3840 0
syscopyarea 2945 1 rpisense_fb
evdev 11396 2
sysfillrect 3443 1 rpisense_fb
sysimgblt 2069 1 rpisense_fb
fb_sys_fops 1309 1 rpisense_fb
rpisense_js 2588 0
rpisense_core 2323 2 rpisense_fb,rpisense_js
i2c_bcm2708 4834 0
ソフトウェア
- 関連ソース
- https://github.com/raspberrypi/rpi-sense : AVRのコード
- https://github.com/raspberrypi/hats : HAT関連EEPROMツール
Python
from sense_hat import SenseHat
sense = SenseHat()
- APIは、https://pythonhosted.org/sense-hat/api/
- あとはぐぐれば...
snakeゲーム (C サンプル)
-
ジョイスティックで、赤い実を食べると、緑のしっぽが長くなっていく
cd
cp /usr/src/sense-hat/examples/snake ./ -a
cd snake
make
./snake
#### RTIMULib (C++)
- サンプルコード: `/usr/src/sense-hat/examples/RTIMULib/RTIMULibDrive11/`
```bash
cd
cp /usr/src/sense-hat/examples/RTIMULib/RTIMULibDrive11/ ./ -a
cd RTIMULibDrive11
make
./RTIMULibDrive11
```txt:実行例
...
Sample rate 58: : roll:5.029336, pitch:-0.799201, yaw:-170.125204
Pressure: 1023.1, height above sea level: -81.3, temperature: 29.3, humidity: 38.9
Sample rate 58: : roll:7.555854, pitch:-1.707454, yaw:-147.708223
Pressure: 1023.0, height above sea level: -81.3, temperature: 29.3, humidity: 39.5
...
- 参考:[らずぱいで、MPU-9250](http://qiita.com/mt08/items/2bbe57ce92f2ff661da6)
- これと同様にして動きました
```bash
sudo apt-get install -y i2c-tools cmake git octave python-dev libqt4-dev
cd
git clone https://github.com/richards-tech/RTIMULib2.git
mkdir RTIMULib2/Linux/build
cd RTIMULib2/Linux/build
cmake ..
make -j1
cd ../RTIMULibDemoGL
./RTIMULibDemoGL
キャリブレーション
- https://www.raspberrypi.org/documentation/hardware/sense-hat/ の Calibration
- キャリブレーションデータは、RTIMULib.iniというファイルで保存される。
-
/etc/RTIMULib.ini
にコピーする。 -
~/.config/sense_hat/RTIMULib.ini
を削除(リネーム)する
-
octave
をインストールして、RTEllipsoidFit
フォルダをコピーして、RTIMULibCal
を実行
sudp apt-get update
sudo apt-get install octave -y
cd
cp /usr/share/librtimulib-utils/RTEllipsoidFit ./ -a
cd RTEllipsoidFit
RTIMULibCal
```txt:RTIMULibCalの実行例
pi@raspberrypi:~/RTEllipsoidFit $ RTIMULibCal
RTIMULibCal - using RTIMULib.ini
Settings file not found. Using defaults and creating settings file
Detected LSM9DS1 at standard/standard address
Using fusion algorithm RTQF
min/max compass calibration not in use
Ellipsoid compass calibration not in use
Accel calibration not in use
LSM9DS1 init complete
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
(calibrate magnetometer with min/max) をおして、なにか、キーを押すと、数字が出てくる。実行例
Enter option: m
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: 1000.00 min y: 1000.00 min z: 1000.00
Max x: -1000.00 max y: -1000.00 max z: -1000.00
Min x: 1000.00 min y: 1000.00 min z: 1000.00
Max x: -1000.00 max y: -1000.00 max z: -1000.00
...
Min x: -93.44 min y: -30.38 min z: 33.51
Max x: -33.45 max y: -15.56 max z: 37.03
Min x: -93.44 min y: -30.38 min z: 13.33
Max x: -33.45 max y: -14.95 max z: 38.12
...
3. ラズパイをぐるぐる回して、それぞれの minとmaxが変わらなくなるまでやる。
4. `s`をおして、抜けて、`e`(calibrate magnetometer with ellipsoid)を押す。
5. ラズパイを自動的にぬけまで、ぐるぐる回す。それぞれ、200サンプル以上とるとのこと。
```
Enter option: e
Magnetometer ellipsoid calibration
----------------------------------
Move the magnetometer around in as many poses as possible.
The counts for each of the 8 pose quadrants will be displayed.
When enough data (200 samples per octant) has been collected,
ellipsoid processing will begin.
Enter 'x' at any time to abort and discard the data.
Press any key to start...
---: 3 +--: 0 -+-: 2 ++-: 0
--+: 0 +-+: 0 -++: 0 +++: 0
---: 8 +--: 1 -+-: 2 ++-: 0
--+: 0 +-+: 0 -++: 0 +++: 0
...
数字が上がっていく
...
---: 499 +--: 270 -+-: 992 ++-: 700
--+: 272 +-+: 199 -++: 557 +++: 348
Processing ellipsoid fit data...
GNU Octave, version 3.8.2
Copyright (C) 2014 John W. Eaton and others.
This is free software; see the source code for copying conditions.
There is ABSOLUTELY NO WARRANTY; not even for MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. For details, type 'warranty'.
Octave was configured for "arm-unknown-linux-gnueabihf".
Additional information about Octave is available at http://www.octave.org.
Please contribute if you find this software useful.
For more information, visit http://www.octave.org/get-involved.html
Read http://www.octave.org/bugs.html to learn how to submit bug reports.
For information about changes from previous versions, type 'news'.
Mat size = 3
Mat size = 3838
Ellipsoid fit completed - saving data to file.
-
a
(calibrate accelerometers)を押す。以下のキーで、xyz軸を変えながら、ぐるぐる回して、s
おしてデータ保存する-
e
有効 -
d
無効 -
-
r
現在の軸のリセット -
s
セーブ -
x
保存しないで終了
-
Enter option: a
Accelerometer Calibration
The code normally ignores readings until an axis has been enabled.
The idea is to orient the IMU near the current extrema (+x, -x, +y, -y, +z, -z)
and then enable the axis, moving the IMU very gently around to find the
extreme value. Now disable the axis again so that the IMU can be inverted.
When the IMU has been inverted, enable the axis again and find the extreme
point. Disable the axis again and press the space bar to move to the next
axis and repeat. The software will display the current axis and enable state.
Available options are:
e - enable the current axis.
d - disable the current axis.
space bar - move to the next axis (x then y then z then x etc.
r - reset the current axis (if enabled).
s - save the data once all 6 extrema have been collected.
x - abort and discard the data.
Press any key to start...