Skip to content

Commit 75aec5a

Browse files
Cleaned up distance examples and comments
Getting ready for review - all examples are now functional and ready for use
1 parent d00bb95 commit 75aec5a

File tree

7 files changed

+363
-101
lines changed

7 files changed

+363
-101
lines changed

examples/Example01_PresenceBasicReadings/Example01_PresenceBasicReadings.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
Using the Acconeer XM125 A121 60GHz Pulsed Coherent Radar Sensor.
55
66
This example shows how operate the XM125 when the device is in Presence Reading Mode.
7-
The sensor is initialized, then the presence values will print out to the terminal.
8-
For full algorithm for
7+
The sensor is initialized, then the presence distance values will print out
8+
to the terminal.
99
1010
By: Madison Chodikov
1111
SparkFun Electronics

examples/Example03_PresenceSerialPlotter/Example03_PresenceSerialPlotter.ino

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -123,21 +123,8 @@ void setup()
123123
Serial.println(errorStatus);
124124
}
125125

126+
// Extra line and 1 second delay for easier readings
126127
Serial.println();
127-
128-
// Original code below:
129-
// // Default start = 1000; Default stop = 5000
130-
// int32_t sensorStartError = radarSensor.presenceDetectorStart();
131-
// if(sensorStartError != 0)
132-
// {
133-
// Serial.println("Sensor Started Successfully");
134-
// }
135-
// else
136-
// {
137-
// Serial.println("Sensor not initialized correctly - Freezing code.");
138-
// while(1); // Runs forever
139-
// }
140-
141128
delay(1000);
142129
}
143130

@@ -180,7 +167,7 @@ void loop()
180167
if((presenceDetected == 1) | (presenceDetectedSticky == 1))
181168
{
182169
radarSensor.getPresenceDistance(distance);
183-
Serial.println((distance/10));
170+
Serial.println(distance);
184171
}
185172

186173
// Delay 1 second between readings

examples/Example04_DistanceBasicReadings/Example04_DistanceBasicReadings.ino

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ uint32_t measDistErr = 0;
4040
uint32_t errorStatus = 0;
4141

4242
// Distance Variables
43-
uint32_t distanceRegVal = 0;
4443
uint32_t distancePeakStrength0 = 0;
4544
uint32_t distancePeak0 = 0;
4645
uint32_t distancePeakStrength1 = 0;
@@ -162,7 +161,6 @@ void loop()
162161
Serial.println(errorStatus);
163162
}
164163

165-
166164
// Start detector
167165
if(radarSensor.setDistanceCommand(SFE_XM125_DISTANCE_START_DETECTOR) != 0)
168166
{

examples/Example05_DistanceThresholdSettings/Example05_DistanceThresholdSettings.ino

Lines changed: 161 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
Using the Acconeer XM125 A121 60GHz Pulsed Coherent Radar Sensor.
55
66
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.
89
910
By: Madison Chodikov
1011
SparkFun Electronics
@@ -28,6 +29,22 @@ SfeXM125 radarSensor;
2829
// I2C default address
2930
uint8_t i2cAddress = SFE_XM125_I2C_ADDRESS;
3031

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+
3148
void setup()
3249
{
3350
// Start serial
@@ -48,18 +65,153 @@ void setup()
4865
while(1); // Runs forever
4966
}
5067

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);
57142

58143
}
59144

60145
void loop()
61146
{
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+
}
63174

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);
65217
}

0 commit comments

Comments
 (0)