Skip to content

Commit 030922f

Browse files
Updates as per Kirk's request
Restructured the examples, added new functionality for the commands; created new functions for beginning and requesting data with only one function call to simplify the examples
1 parent 75aec5a commit 030922f

File tree

11 files changed

+1692
-949
lines changed

11 files changed

+1692
-949
lines changed

examples/Example01_PresenceBasicReadings/Example01_PresenceBasicReadings.ino

Lines changed: 18 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,12 @@ uint8_t i2cAddress = SFE_XM125_I2C_ADDRESS;
3131

3232
// Presence distance values
3333
uint32_t distance = 0;
34-
uint32_t presenceDetected = 0;
35-
uint32_t presenceDetectedSticky = 0;
36-
uint32_t startVal = 0;
37-
uint32_t endVal = 0;
38-
uint32_t gpioUsage;
3934

4035
// Error statuses
41-
uint32_t errorStatus = 0;
42-
uint32_t busyError = 0;
36+
int32_t errorStatus = 0;
37+
int32_t busyError = 0;
38+
int32_t setupError = 0;
39+
int32_t presValError = 0;
4340

4441
void setup()
4542
{
@@ -66,115 +63,35 @@ void setup()
6663

6764
delay(200);
6865

69-
// Presence Sensor Setup
70-
// Reset sensor configuration to reapply configuration registers
71-
radarSensor.setPresenceCommand(SFE_XM125_PRESENCE_RESET_MODULE);
72-
73-
// Check error and busy bits
74-
radarSensor.getPresenceDetectorErrorStatus(errorStatus);
75-
if(errorStatus != 0)
66+
// Start the sensor with default register values
67+
int32_t setupError = radarSensor.presenceDetectorStart();
68+
if(setupError != 0)
7669
{
77-
Serial.print("Detector status error: ");
78-
Serial.println(errorStatus);
79-
}
80-
81-
delay(100);
82-
83-
// Set Start register
84-
if(radarSensor.setPresenceStart(300) != 0)
85-
{
86-
Serial.println("Presence Start Error");
87-
}
88-
radarSensor.getPresenceStart(startVal);
89-
Serial.print("Start Val: ");
90-
Serial.println(startVal);
91-
92-
delay(100);
93-
// Set End register
94-
if(radarSensor.setPresenceEnd(7000) != 0)
95-
{
96-
Serial.println("Presence End Error");
97-
}
98-
radarSensor.getPresenceEnd(endVal);
99-
Serial.print("End Val: ");
100-
Serial.println(endVal);
101-
delay(100);
102-
103-
// Apply configuration
104-
if(radarSensor.setPresenceCommand(SFE_XM125_PRESENCE_APPLY_CONFIGURATION) != 0)
105-
{
106-
// Check for errors
107-
radarSensor.getPresenceDetectorErrorStatus(errorStatus);
108-
if(errorStatus != 0)
109-
{
110-
Serial.print("Detector status error: ");
111-
Serial.println(errorStatus);
112-
}
113-
114-
Serial.println("Configuration application error");
115-
}
116-
117-
// Poll detector status until busy bit is cleared
118-
if(radarSensor.presenceBusyWait() != 0)
119-
{
120-
Serial.print("Busy wait error");
121-
}
122-
123-
// Check detector status
124-
radarSensor.getPresenceDetectorErrorStatus(errorStatus);
125-
if(errorStatus != 0)
126-
{
127-
Serial.print("Detector status error: ");
128-
Serial.println(errorStatus);
70+
Serial.print("Presence Detection Start Setup Error: ");
71+
Serial.println(setupError);
12972
}
13073

74+
// New line and delay for easier reading
13175
Serial.println();
132-
13376
delay(1000);
13477
}
13578

13679
void loop()
13780
{
138-
// Check error bits
139-
radarSensor.getPresenceDetectorErrorStatus(errorStatus);
140-
if(errorStatus != 0)
141-
{
142-
Serial.print("Detector status error: ");
143-
Serial.println(errorStatus);
144-
}
145-
146-
147-
// Start detector
148-
if(radarSensor.setPresenceCommand(SFE_XM125_PRESENCE_START_DETECTOR) != 0)
149-
{
150-
Serial.println("Start detector error");
151-
}
152-
153-
// Poll detector status until busy bit is cleared - CHECK ON THIS!
154-
if(radarSensor.presenceBusyWait() != 0)
155-
{
156-
Serial.println("Busy wait error");
157-
}
158-
159-
// Verify that no error bits are set in the detector status register
160-
radarSensor.getPresenceDetectorErrorStatus(errorStatus);
161-
if(errorStatus != 0)
162-
{
163-
Serial.print("Detector status error: ");
164-
Serial.println(errorStatus);
165-
}
81+
radarSensor.presenceBusyWait();
16682

167-
// Read detector result register and determine detection status
168-
radarSensor.getPresenceDetectorPresenceDetected(presenceDetected);
169-
radarSensor.getPresenceDetectorPresenceStickyDetected(presenceDetectedSticky);
170-
171-
if((presenceDetected == 1) | (presenceDetectedSticky == 1))
83+
// Get the presence distance value and print out if no errors
84+
presValError = radarSensor.getPresenceDistanceValuemm(distance);
85+
if(presValError != 0)
17286
{
173-
radarSensor.getPresenceDistance(distance);
17487
Serial.print("Presence Detected: ");
17588
Serial.print(distance);
17689
Serial.println("mm");
17790
}
91+
else
92+
{
93+
Serial.println("Error returning presence distance value");
94+
}
17895

17996
// Delay 1 second between readings
18097
delay(1000);

examples/Example02_PresenceGPIO0Usage/Example02_PresenceGPIO0Usage.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
2-
Example 2: Presence Subsweeps - Power Consumption Optimization
2+
Example 2: Presence GPIO0 Pin Usage
33
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.
77
The sensor is initialized, then the presence values will print out to the terminal
8-
and trigger the GPIO1 pin high when there is a presence detected.
8+
and trigger the GPIO0 pin high when there is a presence detected.
99
1010
By: Madison Chodikov
1111
SparkFun Electronics
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
/*
2+
Example 4: Presence Advanced Readings
3+
4+
Using the Acconeer XM125 A121 60GHz Pulsed Coherent Radar Sensor.
5+
6+
This example shows how operate the XM125 when the device is in Presence Reading Mode.
7+
The sensor is initialized, then the presence distance, intra-presence, and
8+
inter-presence values will be printed to the terminal.
9+
10+
By: Madison Chodikov
11+
SparkFun Electronics
12+
Date: 2024/1/22
13+
SparkFun code, firmware, and software is released under the MIT License.
14+
Please see LICENSE.md for further details.
15+
16+
Hardware Connections:
17+
QWIIC --> QWIIC
18+
19+
Serial.print it out at 115200 baud to serial monitor.
20+
21+
Feel like supporting our work? Buy a board from SparkFun!
22+
https://www.sparkfun.com/products/ - Qwiic XM125 Breakout
23+
*/
24+
#include <Arduino.h>
25+
#include "SparkFun_Qwiic_XM125_Arduino_Library.h"
26+
27+
SfeXM125 radarSensor;
28+
29+
// I2C default address
30+
uint8_t i2cAddress = SFE_XM125_I2C_ADDRESS;
31+
32+
// Presence distance values
33+
uint32_t distance = 0;
34+
uint32_t presenceDetected = 0;
35+
uint32_t presenceDetectedSticky = 0;
36+
uint32_t startVal = 0;
37+
uint32_t endVal = 0;
38+
uint32_t gpioUsage;
39+
40+
// Error statuses
41+
uint32_t errorStatus = 0;
42+
uint32_t busyError = 0;
43+
44+
void setup()
45+
{
46+
// Start serial
47+
Serial.begin(115200);
48+
Serial.println("XM125 Example 4: Presence Advanced Readings");
49+
Serial.println("");
50+
51+
Wire.begin();
52+
53+
// If begin is successful (1), then start example
54+
int startErr = radarSensor.begin(i2cAddress, Wire);
55+
if(startErr == 1)
56+
{
57+
Serial.println("Begin");
58+
}
59+
else // Otherwise, infinite loop
60+
{
61+
Serial.print("Start Error Code: ");
62+
Serial.println(startErr);
63+
Serial.println("Device failed to setup - Freezing code.");
64+
while(1); // Runs forever
65+
}
66+
67+
delay(200);
68+
69+
// Setup: start the sensor - reset, apply configuration
70+
// Loop: anything there? get the distance
71+
72+
// Presence Sensor Setup
73+
// Reset sensor configuration to reapply configuration registers
74+
radarSensor.setPresenceCommand(SFE_XM125_PRESENCE_RESET_MODULE);
75+
76+
// Check error and busy bits
77+
radarSensor.getPresenceDetectorErrorStatus(errorStatus);
78+
if(errorStatus != 0)
79+
{
80+
Serial.print("Detector status error: ");
81+
Serial.println(errorStatus);
82+
}
83+
84+
delay(100);
85+
86+
// Set Start register
87+
if(radarSensor.setPresenceStart(300) != 0)
88+
{
89+
Serial.println("Presence Start Error");
90+
}
91+
radarSensor.getPresenceStart(startVal);
92+
Serial.print("Start Val: ");
93+
Serial.println(startVal);
94+
95+
delay(100);
96+
// Set End register
97+
if(radarSensor.setPresenceEnd(7000) != 0)
98+
{
99+
Serial.println("Presence End Error");
100+
}
101+
radarSensor.getPresenceEnd(endVal);
102+
Serial.print("End Val: ");
103+
Serial.println(endVal);
104+
delay(100);
105+
106+
// Apply configuration
107+
if(radarSensor.setPresenceCommand(SFE_XM125_PRESENCE_APPLY_CONFIGURATION) != 0)
108+
{
109+
// Check for errors
110+
radarSensor.getPresenceDetectorErrorStatus(errorStatus);
111+
if(errorStatus != 0)
112+
{
113+
Serial.print("Detector status error: ");
114+
Serial.println(errorStatus);
115+
}
116+
117+
Serial.println("Configuration application error");
118+
}
119+
120+
// Poll detector status until busy bit is cleared
121+
if(radarSensor.presenceBusyWait() != 0)
122+
{
123+
Serial.print("Busy wait error");
124+
}
125+
126+
// Check detector status
127+
radarSensor.getPresenceDetectorErrorStatus(errorStatus);
128+
if(errorStatus != 0)
129+
{
130+
Serial.print("Detector status error: ");
131+
Serial.println(errorStatus);
132+
}
133+
134+
Serial.println();
135+
136+
delay(1000);
137+
}
138+
139+
void loop()
140+
{
141+
// Check error bits
142+
radarSensor.getPresenceDetectorErrorStatus(errorStatus);
143+
if(errorStatus != 0)
144+
{
145+
Serial.print("Detector status error: ");
146+
Serial.println(errorStatus);
147+
}
148+
149+
// Start detector
150+
if(radarSensor.setPresenceCommand(SFE_XM125_PRESENCE_START_DETECTOR) != 0)
151+
{
152+
Serial.println("Start detector error");
153+
}
154+
155+
// Poll detector status until busy bit is cleared - CHECK ON THIS!
156+
if(radarSensor.presenceBusyWait() != 0)
157+
{
158+
Serial.println("Busy wait error");
159+
}
160+
161+
// Verify that no error bits are set in the detector status register
162+
radarSensor.getPresenceDetectorErrorStatus(errorStatus);
163+
if(errorStatus != 0)
164+
{
165+
Serial.print("Detector status error: ");
166+
Serial.println(errorStatus);
167+
}
168+
169+
// Read detector result register and determine detection status
170+
radarSensor.getPresenceDetectorPresenceDetected(presenceDetected);
171+
radarSensor.getPresenceDetectorPresenceStickyDetected(presenceDetectedSticky);
172+
173+
if((presenceDetected == 1) | (presenceDetectedSticky == 1))
174+
{
175+
radarSensor.getPresenceDistance(distance);
176+
Serial.print("Presence Detected: ");
177+
Serial.print(distance);
178+
Serial.println("mm");
179+
}
180+
181+
// Delay 1 second between readings
182+
delay(1000);
183+
}

0 commit comments

Comments
 (0)