Skip to content

Commit adc68c3

Browse files
committed
tof
1 parent 6614b48 commit adc68c3

File tree

3 files changed

+101
-1
lines changed

3 files changed

+101
-1
lines changed

examples/tof3/tof3.ino

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#include <Wire.h>
2+
#include <VL53L1X.h>
3+
#include <Wire.h>
4+
5+
TwoWire wire(PB7, PB8);
6+
const uint8_t sensorCount = 3;
7+
8+
const uint8_t xshutPins[sensorCount] = { PC5, PB0, PB1 }; //Right, Center, Left
9+
10+
VL53L1X sensors[sensorCount];
11+
12+
void setup(){
13+
while (!Serial);
14+
Serial.begin(115200);
15+
wire.begin();
16+
wire.setClock(400000);
17+
18+
for (uint8_t i = 0; i < sensorCount; i++){
19+
pinMode(xshutPins[i], OUTPUT);
20+
digitalWrite(xshutPins[i], LOW);
21+
}
22+
23+
for (uint8_t i = 0; i < sensorCount; i++){
24+
pinMode(xshutPins[i], INPUT);
25+
delay(10);
26+
sensors[i].setBus(&wire);
27+
sensors[i].setTimeout(500);
28+
if (!sensors[i].init()){
29+
Serial.print("Failed to detect and initialize sensor ");
30+
Serial.println(i);
31+
while (1);
32+
}
33+
34+
sensors[i].setAddress(0x2A + i);
35+
sensors[i].startContinuous(50);
36+
}
37+
}
38+
39+
void loop(){
40+
for (uint8_t i = 0; i < sensorCount; i++){
41+
Serial.print(sensors[i].read());
42+
if (sensors[i].timeoutOccurred()){
43+
Serial.print(" TIMEOUT");
44+
}
45+
Serial.print('\t');
46+
}
47+
Serial.print("\n");
48+
}

examples/tofM/tofM.ino

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#include <Arduino.h>
2+
#include <Wire.h>
3+
#include <vl53l7cx_class.h>
4+
5+
6+
TwoWire wire(PB7, PB8);
7+
#define DEV_I2C wire
8+
9+
#define SerialPort Serial
10+
11+
#define LPN_PIN PB1
12+
#define I2C_RST_PIN PB0
13+
14+
VL53L7CX sensor_vl53l7cx(&DEV_I2C, LPN_PIN, I2C_RST_PIN);
15+
16+
17+
uint8_t res = VL53L7CX_RESOLUTION_8X8; //VL53L7CX_RESOLUTION_4X4
18+
19+
20+
void setup(){
21+
SerialPort.begin(115200);
22+
DEV_I2C.begin();
23+
sensor_vl53l7cx.begin();
24+
sensor_vl53l7cx.init_sensor();
25+
sensor_vl53l7cx.vl53l7cx_set_resolution(res);
26+
sensor_vl53l7cx.vl53l7cx_start_ranging();
27+
}
28+
29+
void loop(){
30+
VL53L7CX_ResultsData Results;
31+
uint8_t NewDataReady = 0;
32+
uint8_t status;
33+
do {
34+
status = sensor_vl53l7cx.vl53l7cx_check_data_ready(&NewDataReady);
35+
} while (!NewDataReady);
36+
37+
if ((!status) && (NewDataReady != 0)) {
38+
status = sensor_vl53l7cx.vl53l7cx_get_ranging_data(&Results);
39+
for (int y=0; y<8; y++){
40+
for (int x=0; x<8; x++){
41+
Serial.print((int)Results.distance_mm[x+y*8]);
42+
Serial.print(" ");
43+
}
44+
Serial.println();
45+
}
46+
Serial.println();
47+
}
48+
delay(100);
49+
50+
}

src/Arduino_Robot_Firmware.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,16 @@ class Arduino_Robot_Firmware{
1818
Servo * servo_A;
1919
Servo * servo_B;
2020

21+
TwoWire * wire;
22+
23+
2124
public:
2225
RGBled * led1;
2326
RGBled * led2;
2427
DCmotor * motor_left;
2528
DCmotor * motor_right;
2629
Encoder * encoder_left;
2730
Encoder * encoder_right;
28-
TwoWire * wire;
2931

3032

3133
Arduino_Robot_Firmware();

0 commit comments

Comments
 (0)