Embedded System/Arduino

[Arduino] multiple VL53L1x

전두선 2020. 7. 7. 15:08

 

TEST ENVIRONMENT

  • Arduino mega
  • VL53L1x sensor x4

 

Connections

VL53L1x 센서의 VIN PIN에 3.3V 또는 5V의 입력전압을 인가하고, GND, I2C Line 연결 후, 여러개의 센서를 제어하기 위해 XSHUT PIN까지 각각 할당된 GPIO에 연결한다. 저는 9~12 PIN을 사용했습니다. 

 

TEST RESULT

결과적으로 비슷한 거리의 물체에 대해서 1,4 센서와 2,3 센서의 측정 결과가 다르게 나왔다. 각각의 센서의 위치를 바꿔서 테스트 해본 결과 코드의 문제가 아닌 센서 자체의 문제라는 것으로 판단됬고, 추후 사용하게 된다면 캘리브레이션을 통해 4개의 센서를 처리하여 사용할 것이다.

* 센서를 처음 구매했을 때 송수신기 부분에 스티커가 붙어있는데 꼭 제거해주어야지 정상출력을 얻을 수 있다.

 

그냥 간단하게 눈대중으로 보정했을 때,

 

SOURCE CODE

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#include <VL53L1X.h> //Download this library from https://github.com/pololu/vl53l1x-arduino
#include <Wire.h>
 
VL53L1X sensor_A; //Create the sensor object
VL53L1X sensor_B; //Create the sensor object
VL53L1X sensor_C; //Create the sensor object
VL53L1X sensor_D; //Create the sensor object
 
int startTime = millis(); //used for our timing loop
int mInterval = 100//refresh rate of 10hz
 
#define XSHUT_A 9
#define XSHUT_B 10
#define XSHUT_C 11
#define XSHUT_D 12
 
#define M_INTERVAL 50
 
void setup() {
 
    Serial.begin(115200);
    
    Wire.begin(); //Setup your I2C interface
    Wire.setClock(400000); // use 400 kHz I2C
 
    //Set the pin mode to output
    pinMode(XSHUT_A ,OUTPUT);
    pinMode(XSHUT_B ,OUTPUT);
    pinMode(XSHUT_C ,OUTPUT);
    pinMode(XSHUT_D ,OUTPUT);
    
    //Turn all TOF's off
    digitalWrite(XSHUT_A, LOW);
    digitalWrite(XSHUT_B, LOW);
    digitalWrite(XSHUT_C, LOW);
    digitalWrite(XSHUT_D, LOW);
 
    //-----------------------------------------------------------------
    //FIRST WE WILL CONFIGURE AND SETUP SENSOR_A
    //-----------------------------------------------------------------
    delay(50);
    digitalWrite(XSHUT_A, HIGH); //Turn sensor_A on
    delay(50);
    
    sensor_A.setTimeout(500); //Set the sensors timeout
    
    if (!sensor_A.init())//try to initilise the sensor
    {
        //Sensor does not respond within the timeout time
        Serial.println("Sensor_A is not responding, check your wiring");
    }
    else
    {
        sensor_A.setAddress(42); //Set the sensors I2C address
        sensor_A.setDistanceMode(VL53L1X::Long); //Set the sensor to maximum range of 4 meters
        sensor_A.setMeasurementTimingBudget(40000); //Set its timing budget in microseconds longer timing budgets will give more accurate measurements
        sensor_A.startContinuous(M_INTERVAL); //Sets the interval where a measurement can be requested in milliseconds
    }   
 
    //-----------------------------------------------------------------
    //NOW CONFIGURE AND SETUP SENSOR_B
    //-----------------------------------------------------------------
    delay(50);
    digitalWrite(XSHUT_B, HIGH); //Turn sensor_A on
    delay(50);
    
    sensor_B.setTimeout(500); //Set the sensors timeout
    
    if (!sensor_B.init())//try to initilise the sensor
    {
        //Sensor does not respond within the timeout time
        Serial.println("Sensor_A is not responding, check your wiring");
    }
    else
    {
        sensor_B.setAddress(43); //Set the sensors I2C address
        sensor_B.setDistanceMode(VL53L1X::Long); //Set the sensor to maximum range of 4 meters
        sensor_B.setMeasurementTimingBudget(40000); //Set its timing budget in microseconds longer timing budgets will give more accurate measurements
        sensor_B.startContinuous(M_INTERVAL); //Sets the interval where a measurement can be requested in milliseconds
    }
 
      //-----------------------------------------------------------------
    //NOW CONFIGURE AND SETUP SENSOR_C
    //-----------------------------------------------------------------
    delay(50);
    digitalWrite(XSHUT_C, HIGH); //Turn sensor_A on
    delay(50);
    
    sensor_C.setTimeout(500); //Set the sensors timeout
    
    if (!sensor_C.init())//try to initilise the sensor
    {
        //Sensor does not respond within the timeout time
        Serial.println("Sensor_A is not responding, check your wiring");
    }
    else
    {
        sensor_C.setAddress(44); //Set the sensors I2C address
        sensor_C.setDistanceMode(VL53L1X::Long); //Set the sensor to maximum range of 4 meters
        sensor_C.setMeasurementTimingBudget(40000); //Set its timing budget in microseconds longer timing budgets will give more accurate measurements
        sensor_C.startContinuous(M_INTERVAL); //Sets the interval where a measurement can be requested in milliseconds
    } 
 
    //-----------------------------------------------------------------
    //NOW CONFIGURE AND SETUP SENSOR_D
    //-----------------------------------------------------------------
    delay(50);
    digitalWrite(XSHUT_D, HIGH); //Turn sensor_A on
    delay(50);
    
    sensor_D.setTimeout(500); //Set the sensors timeout
    
    if (!sensor_D.init())//try to initilise the sensor
    {
        //Sensor does not respond within the timeout time
        Serial.println("Sensor_A is not responding, check your wiring");
    }
    else
    {
        sensor_D.setAddress(45); //Set the sensors I2C address
        sensor_D.setDistanceMode(VL53L1X::Long); //Set the sensor to maximum range of 4 meters
        sensor_D.setMeasurementTimingBudget(40000); //Set its timing budget in microseconds longer timing budgets will give more accurate measurements
        sensor_D.startContinuous(M_INTERVAL); //Sets the interval where a measurement can be requested in milliseconds
    } 
}
 
char buf[40];
 
void loop() {
    //We have to be careful here. If we request a measurement before the measurement has been taken your
    //code will be blovked until the measurement is complete. In order to stop this from happening we
    //must ensure that time between measurement requests is greater than the timing budget and the argument 
    //given in the startContinuous() function. In our case our measurement time must be greater than 50mS.
 
    if((millis()- startTime) > mInterval)
    {
        sprintf(buf, "%4d,%4d,%4d,%4d",sensor_A.read(),sensor_B.read(),sensor_C.read(),sensor_D.read());
        Serial.println(buf); //Get a reading in millimeters
        startTime = millis();
    }
}
cs

'Embedded System > Arduino' 카테고리의 다른 글

[error] arduino leonardo WebUSB  (0) 2020.07.02