使用したモジュール
おもて | うら |
---|---|
APIやドライバのソースコードを取得
STマイクロエレクトロニクスのページから、ソースコードをダウンロードします。
ソースコード(C言語)
上記のURLアクセスして、ユーザ登録しソースコードをダウンロードします。
赤枠のところをクリックします。
ライセンスの許諾とユーザ登録のダイアログが表示されますので、確認・必要事項を入力して「Download」ボタンを押下します。
以下のようなダイアログが表示された後、登録したメールアドレスにメールが届きますので「Download now」のボタンを押下します。
以下の画面に遷移しますのでダウンロードされるのを待ちます。
※ 自分は、ダウンロードに失敗しましたが、もううちど「Get latest」のボタンを押下したらダウンロードできました。
ソースコードをラズパイにコピー
VL53L0Xを使用するためのダウンロードしたドライバをラズパイにコピーします。
今回はFileZillaを使用しました。
ソースコードのビルド
APIのビルドを行うためのMakeFileを以下のURLから取得します。
$ cd ~
$ git clone https://github.com/cassou/VL53L0X_rasp
Cloning into 'VL53L0X_rasp'...
remote: Enumerating objects: 134, done.
remote: Total 134 (delta 0), reused 0 (delta 0), pack-reused 134
Receiving objects: 100% (134/134), 218.60 KiB | 2.95 MiB/s, done.
Resolving deltas: 100% (47/47), done.
$
ソースコードをコピーしたディレクトリを指定してmakeコマンドを実行します。
$ cd VL53L0X_rasp
$ API_DIR=~/VL53L0X_1.0.4 make
mkdir -p obj/
gcc -O0 -g -Wall -c -I. -I/home/pi/VL53L0X_1.0.4/Api/core/inc -I./platform/inc /home/pi/VL53L0X_1.0.4/Api/core/src/vl53l0x_api_calibration.c -o obj/vl53l0x_api_calibration.o
mkdir -p obj/
gcc -O0 -g -Wall -c -I. -I/home/pi/VL53L0X_1.0.4/Api/core/inc -I./platform/inc /home/pi/VL53L0X_1.0.4/Api/core/src/vl53l0x_api_core.c -o obj/vl53l0x_api_core.o
mkdir -p obj/
gcc -O0 -g -Wall -c -I. -I/home/pi/VL53L0X_1.0.4/Api/core/inc -I./platform/inc /home/pi/VL53L0X_1.0.4/Api/core/src/vl53l0x_api_ranging.c -o obj/vl53l0x_api_ranging.o
mkdir -p obj/
gcc -O0 -g -Wall -c -I. -I/home/pi/VL53L0X_1.0.4/Api/core/inc -I./platform/inc /home/pi/VL53L0X_1.0.4/Api/core/src/vl53l0x_api_strings.c -o obj/vl53l0x_api_strings.o
mkdir -p obj/
gcc -O0 -g -Wall -c -I. -I/home/pi/VL53L0X_1.0.4/Api/core/inc -I./platform/inc /home/pi/VL53L0X_1.0.4/Api/core/src/vl53l0x_api.c -o obj/vl53l0x_api.o
mkdir -p obj/
gcc -O0 -g -Wall -c -I. -I/home/pi/VL53L0X_1.0.4/Api/core/inc -I./platform/inc ./platform/src/vl53l0x_platform.c -o obj/vl53l0x_platform.o
mkdir -p bin/
ar -rcs bin/libVL53L0X_Rasp.a obj/vl53l0x_api_calibration.o obj/vl53l0x_api_core.o obj/vl53l0x_api_ranging.o obj/vl53l0x_api_strings.o obj/vl53l0x_api.o obj/vl53l0x_platform.o
$
同じようにサンプルコードもmakeします。
$ API_DIR=~/VL53L0X_1.0.4 make examples
mkdir -p bin/
gcc -Lbin examples/vl53l0x_ContinuousRanging_Example.c -lVL53L0X_Rasp -I. -I/home/pi/VL53L0X_1.0.4/Api/core/inc -I./platform/inc -o bin/vl53l0x_ContinuousRanging_Example
mkdir -p bin/
gcc -Lbin examples/vl53l0x_SingleRanging_Long_Range_Example.c -lVL53L0X_Rasp -I. -I/home/pi/VL53L0X_1.0.4/Api/core/inc -I./platform/inc -o bin/vl53l0x_SingleRanging_Long_Range_Example
$
ラズパイとVL53L0Xの接続
ラズパイ | VL530L0X | |
---|---|---|
3 : I2C SDA | SDA | |
5 : I2C SCL | SCL | |
2 : 5V | VDD | |
6 : GND | GND |
I2Cを有効にする
$ sudo raspi-config
「3 Interface Options」を選択します。
「I5 I2C」を選択します。
I2CをEnableにしてraspi-configを終了します。
i2cdetectコマンドでデバイスのアドレスを確認します。
$ sudo i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- 29 -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
サンプルの実行
$ ./VL53L0X_rasp/bin/vl53l0x_ContinuousRanging_Example
VL53L0X PAL Continuous Ranging example
VL53L0X API Version Error: Your firmware has 1.0.4 (revision 4960). This example requires 1.0.1.
Call of VL53L0X_DataInit
API Status: 0 : No Error
VL53L0X_GetDeviceInfo:
Device Name : VL53L0X ES1 or later
Device Type : VL53L0X
Device ID : VL53L0CAV0DH/1$5
ProductRevisionMajor : 1
ProductRevisionMinor : 1
Call of VL53L0X_StaticInit
API Status: 0 : No Error
Call of VL53L0X_PerformRefCalibration
API Status: 0 : No Error
Call of VL53L0X_PerformRefSpadManagement
API Status: 0 : No Error
Call of VL53L0X_SetDeviceMode
API Status: 0 : No Error
Call of VL53L0X_StartMeasurement
API Status: 0 : No Error
In loop measurement 0: 73
In loop measurement 1: 61
In loop measurement 2: 59
In loop measurement 3: 60
In loop measurement 4: 59
In loop measurement 5: 58
In loop measurement 6: 51
In loop measurement 7: 47
In loop measurement 8: 45
In loop measurement 9: 46
In loop measurement 10: 45
In loop measurement 11: 41
In loop measurement 12: 41
In loop measurement 13: 42
In loop measurement 14: 40
In loop measurement 15: 40
In loop measurement 16: 41
In loop measurement 17: 38
In loop measurement 18: 36
In loop measurement 19: 39
In loop measurement 20: 38
In loop measurement 21: 39
In loop measurement 22: 38
In loop measurement 23: 39
In loop measurement 24: 39
In loop measurement 25: 42
In loop measurement 26: 47
・・・
参考サイト