目的:在 BeagleBone Black Board(Debian OS)上使用 C 语言使用 I2C 通信读取 4 个 VL53L0X(TOF) 传感器的数据。
我已经为单个 VL53L0X(TOF) 传感器实现了 c 代码,它是:https://github.com/bitbank2/VL53L0X
从上面的链接:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <tof.h> // time of flight sensor library
int main(int argc, char *argv[])
{
int i;
int iDistance;
int model, revision;
// For Raspberry Pi's, the I2C channel is usually 1
// For other boards (e.g. OrangePi) it's 0
i = tofInit(2, 0x29, 1); // 2=I2CBus, 0x29 i2c slave address, 1 = long range.
if (i != 1)
{
return -1; // problem - quit
}
printf("VL53L0X device successfully opened.\n");
i = tofGetModel(&model, &revision);
usleep(50000); // 50ms
printf("Model ID =%d,\n", model);
printf("Revision ID =%d,\n", revision);
for (i=0; i<1200; i++) // read values 20 times a second for 1 minute
{
iDistance = tofReadDistance();
if (iDistance < 4096) // valid range?
printf("Distance = %dmm\n", iDistance);
usleep(50000); // 50ms
}
return 0;
} /* main() */
但我的应用程序是与4VL53L0X(TOF) 传感器。
或者用另一种方式用 c 编码来获得解决方案。
谢谢。