4
4
Using the Acconeer XM125 A121 60GHz Pulsed Coherent Radar Sensor.
5
5
6
6
This example shows how operate the XM125 when the device is in Distance Reading Mode.
7
- The sensor is initialized, then the distance amplitude, and strength thresholds are set.
7
+ The sensor is initialized, then the distance amplitude, and strength , fixed
8
+ amplitude, and sensitivity thresholds are set.
8
9
9
10
By: Madison Chodikov
10
11
SparkFun Electronics
@@ -28,6 +29,22 @@ SfeXM125 radarSensor;
28
29
// I2C default address
29
30
uint8_t i2cAddress = SFE_XM125_I2C_ADDRESS;
30
31
32
+ // Setup Variables
33
+ uint32_t startVal = 0 ;
34
+ uint32_t endVal = 0 ;
35
+ uint32_t numDistances = 9 ;
36
+ uint32_t calibrateNeeded = 0 ;
37
+ uint32_t measDistErr = 0 ;
38
+
39
+ // Error statuses
40
+ uint32_t errorStatus = 0 ;
41
+
42
+ // Distance Variables
43
+ uint32_t distancePeakStrength0 = 0 ;
44
+ uint32_t distancePeak0 = 0 ;
45
+ uint32_t distancePeakStrength1 = 0 ;
46
+ uint32_t distancePeak1 = 0 ;
47
+
31
48
void setup ()
32
49
{
33
50
// Start serial
@@ -48,18 +65,153 @@ void setup()
48
65
while (1 ); // Runs forever
49
66
}
50
67
51
- // Set the fixed amplitude threshold
52
- radarSensor.setDistanceFixedAmpThreshold ();
53
- // Set the fixed strength threshold
54
- radarSensor.setDistanceFixedStrengthThresholdValue (5 );
55
- // Set the distance threshold sensitivity
56
- radarSensor.();
68
+ // Distance Sensor Setup
69
+ // Reset sensor configuration to reapply configuration registers
70
+ radarSensor.setDistanceCommand (SFE_XM125_DISTANCE_RESET_MODULE);
71
+
72
+ radarSensor.distanceBusyWait ();
73
+
74
+ // Check error and busy bits
75
+ radarSensor.getDistanceDetectorErrorStatus (errorStatus);
76
+ if (errorStatus != 0 )
77
+ {
78
+ Serial.print (" Detector status error: " );
79
+ Serial.println (errorStatus);
80
+ }
81
+
82
+ delay (100 );
83
+
84
+ // Set Start register
85
+ if (radarSensor.setDistanceStart (100 ) != 0 )
86
+ {
87
+ Serial.println (" Distance Start Error" );
88
+ }
89
+ radarSensor.getDistanceStart (startVal);
90
+ Serial.print (" Start Val: " );
91
+ Serial.println (startVal);
92
+
93
+ delay (100 );
94
+ // Set End register
95
+ if (radarSensor.setDistanceEnd (4000 ) != 0 )
96
+ {
97
+ Serial.println (" Distance End Error" );
98
+ }
99
+ radarSensor.getDistanceEnd (endVal);
100
+ Serial.print (" End Val: " );
101
+ Serial.println (endVal);
102
+ delay (100 );
103
+
104
+ // Set Distance Threshold Settings - Threshold Sensitivity (range: 0 to 1000)
105
+ radarSensor.setDistanceThresholdSensitivity (100 );
106
+
107
+ // Set Fixed Amplitude Threshold
108
+ radarSensor.setDistanceFixedAmpThreshold (100 );
109
+
110
+
111
+ // Apply configuration
112
+ if (radarSensor.setDistanceCommand (SFE_XM125_DISTANCE_APPLY_CONFIGURATION) != 0 )
113
+ {
114
+ // Check for errors
115
+ radarSensor.getDistanceDetectorErrorStatus (errorStatus);
116
+ if (errorStatus != 0 )
117
+ {
118
+ Serial.print (" Detector status error: " );
119
+ Serial.println (errorStatus);
120
+ }
121
+
122
+ Serial.println (" Configuration application error" );
123
+ }
124
+
125
+ // Poll detector status until busy bit is cleared
126
+ if (radarSensor.distanceBusyWait () != 0 )
127
+ {
128
+ Serial.print (" Busy wait error" );
129
+ }
130
+
131
+ // Check detector status
132
+ radarSensor.getDistanceDetectorErrorStatus (errorStatus);
133
+ if (errorStatus != 0 )
134
+ {
135
+ Serial.print (" Detector status error: " );
136
+ Serial.println (errorStatus);
137
+ }
138
+
139
+ Serial.println ();
140
+
141
+ delay (1000 );
57
142
58
143
}
59
144
60
145
void loop ()
61
146
{
62
- // Request Distance Data from the device
147
+ // Check error bits
148
+ radarSensor.getDistanceDetectorErrorStatus (errorStatus);
149
+ if (errorStatus != 0 )
150
+ {
151
+ Serial.print (" Detector status error: " );
152
+ Serial.println (errorStatus);
153
+ }
154
+
155
+ // Start detector
156
+ if (radarSensor.setDistanceCommand (SFE_XM125_DISTANCE_START_DETECTOR) != 0 )
157
+ {
158
+ Serial.println (" Start detector error" );
159
+ }
160
+
161
+ // Poll detector status until busy bit is cleared - CHECK ON THIS!
162
+ if (radarSensor.distanceBusyWait () != 0 )
163
+ {
164
+ Serial.println (" Busy wait error" );
165
+ }
166
+
167
+ // Verify that no error bits are set in the detector status register
168
+ radarSensor.getDistanceDetectorErrorStatus (errorStatus);
169
+ if (errorStatus != 0 )
170
+ {
171
+ Serial.print (" Detector status error: " );
172
+ Serial.println (errorStatus);
173
+ }
63
174
64
- delay (100 );
175
+ // Check MEASURE_DISTANCE_ERROR for measurement failed
176
+ radarSensor.getDistanceMeasureDistanceError (measDistErr);
177
+ if (measDistErr == 1 )
178
+ {
179
+ Serial.println (" Measure Distance Error" );
180
+ }
181
+
182
+ // Recalibrate device if calibration error is triggered
183
+ radarSensor.getDistanceCalibrationNeeded (calibrateNeeded);
184
+ if (calibrateNeeded == 1 )
185
+ {
186
+ Serial.println (" Calibration Needed - Recalibrating.. " );
187
+ // Calibrate device (write RECALIBRATE command)
188
+ radarSensor.setDistanceCommand (SFE_XM125_DISTANCE_RECALIBRATE);
189
+ }
190
+
191
+ // Read PeakX Distance and PeakX Strength registers for the number of distances detected
192
+ radarSensor.getDistancePeak0Distance (distancePeak0);
193
+ radarSensor.getDistancePeak0Strength (distancePeakStrength0);
194
+ radarSensor.getDistancePeak1Distance (distancePeak1);
195
+ radarSensor.getDistancePeak1Strength (distancePeakStrength1);
196
+
197
+ // Read out 2 distances and peaks with threshold settings adjusted
198
+ if (distancePeak0 != 0 )
199
+ {
200
+ Serial.print (" Peak0 Distance, Strength: " );
201
+ Serial.print (distancePeak0);
202
+ Serial.print (" mm, " );
203
+ Serial.println (distancePeakStrength0);
204
+ Serial.println ();
205
+ }
206
+ if (distancePeak1 != 0 )
207
+ {
208
+ Serial.print (" Peak1 Distance, Strength: " );
209
+ Serial.print (distancePeak1);
210
+ Serial.print (" mm, " );
211
+ Serial.println (distancePeakStrength1);
212
+ Serial.println ();
213
+ }
214
+
215
+ // Half a second delay for easier readings
216
+ delay (500 );
65
217
}
0 commit comments