Skip to content

Commit 700fac3

Browse files
I2C Bus Functionality Added
Added the correct code to communicate over the I2C bus - need to finish printing and working the examples.
1 parent 80dfefa commit 700fac3

File tree

8 files changed

+59
-4
lines changed

8 files changed

+59
-4
lines changed

examples/Example01_DistanceBasicReadings/Example01_DistanceBasicReadings.ino

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ void setup()
3636
Serial.println("XM125 Example 1: Basic Distance Readings");
3737
Serial.println("");
3838

39+
Wire.begin();
40+
3941
// If begin is successful (0), then start example
4042
if(radarSensor.begin(i2cAddress, Wire) == 1)
4143
{

examples/Example02_DistanceThresholdSettings/Example02_DistanceThresholdSettings.ino

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ void setup()
3535
Serial.println("XM125 Example 2: Distance Threshold Settings");
3636
Serial.println("");
3737

38+
Wire.begin();
39+
3840
// If begin is successful (0), then start example
3941
if(radarSensor.begin(i2cAddress, Wire) == 1)
4042
{
@@ -47,8 +49,10 @@ void setup()
4749
}
4850

4951
// Set the fixed amplitude threshold
50-
radarSensor.();
52+
radarSensor.setDistanceFixedAmpThreshold();
5153
// Set the fixed strength threshold
54+
radarSensor.setDistanceFixedStrengthThresholdValue(5);
55+
// Set the distance threshold sensitivity
5256
radarSensor.();
5357

5458
}

examples/Example03_DistanceSubsweeps/Example03_DistanceSubsweeps.ino

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ void setup()
3939
Serial.println("XM125 Example 3: Distance Subsweeps - Power Consumption Optimization");
4040
Serial.println("");
4141

42+
Wire.begin();
43+
4244
// If begin is successful (0), then start example
4345
if(radarSensor.begin(i2cAddress, Wire) == 1)
4446
{

examples/Example04_PresenceBasicReadings/Example04_PresenceBasicReadings.ino

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
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+
For full algorithm for
89
910
By: Madison Chodikov
1011
SparkFun Electronics
@@ -28,13 +29,19 @@ SfeXM125 radarSensor;
2829
// I2C default address
2930
uint8_t i2cAddress = SFE_XM125_I2C_ADDRESS;
3031

32+
// Value to fill presence distance (in mm)
33+
uint32_t distance;
34+
uint32_t presenceDetected;
35+
3136
void setup()
3237
{
3338
// Start serial
3439
Serial.begin(115200);
3540
Serial.println("XM125 Example 4: Basic Presence Readings");
3641
Serial.println("");
3742

43+
Wire.begin();
44+
3845
// If begin is successful (0), then start example
3946
if(radarSensor.begin(i2cAddress, Wire) == 1)
4047
{
@@ -45,11 +52,34 @@ void setup()
4552
Serial.println("Device failed to setup - Freezing code.");
4653
while(1); // Runs forever
4754
}
55+
56+
// uint32_t regVal;
57+
// int32_t retVal;
58+
// retVal = radarSensor.returnRegister(&regVal);
59+
// Serial.println(regVal, HEX);
60+
// Serial.println(retVal);
61+
62+
delay(2000);
63+
4864
}
4965

5066
void loop()
5167
{
52-
// Request Presence Data from the device
68+
// If Presence is detected, then print out distance from device
69+
radarSensor.getPresenceDistanceResult(&presenceDetected);
70+
71+
radarSensor.getPresenceDistance(&distance);
72+
Serial.print("Presence detected at ");
73+
Serial.print(distance);
74+
Serial.println("mm");
75+
76+
if(presenceDetected == 1)
77+
{
78+
radarSensor.getPresenceDistance(&distance);
79+
Serial.print("Presence detected at ");
80+
Serial.print(distance);
81+
Serial.println("mm");
82+
}
5383

5484
delay(100);
5585
}

examples/Example05_PresenceSubsweeps/Example05_PresenceSubsweeps.ino

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ void setup()
3535
Serial.println("XM125 Example 5: Presence Subsweeps - Power Consumption Optimization");
3636
Serial.println("");
3737

38+
Wire.begin();
39+
3840
// If begin is successful (0), then start example
3941
if(radarSensor.begin(i2cAddress, Wire) == 1)
4042
{
@@ -45,6 +47,9 @@ void setup()
4547
Serial.println("Device failed to setup - Freezing code.");
4648
while(1); // Runs forever
4749
}
50+
51+
// Set minimum start range for profile
52+
radarSensor.setPresenceStart();
4853
}
4954

5055
void loop()

src/SparkFun_Qwiic_XM125_Arduino_Library.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class SfeXM125 : public QwDevXM125
1919
_i2cBus.init(wirePort, deviceAddress);
2020

2121
// Initialize the system - return results
22-
return this->QwDevXM125::begin(&_i2cBus);
22+
return this->QwDevXM125::begin(&_i2cBus) == 0;
2323
}
2424

2525
private:

src/sfeQwiicXM125.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ bool QwDevXM125::begin(sfeTkII2C *theBus)
4444
return 0;
4545
}
4646

47+
48+
/*Test functions below - delete once complete with library */
49+
int32_t QwDevXM125::returnRegister(uint32_t *regVal)
50+
{
51+
return _theBus->read16BitRegisterRegion(SFE_XM125_DISTANCE_VERSION, (uint8_t*)regVal, 4);
52+
}
53+
54+
55+
56+
4757
// --------------------- I2C Disance Detector Functions ---------------------
4858

4959
int32_t QwDevXM125::getDistanceDetectorVersion(uint8_t *major, uint8_t *minor, uint8_t *patch)

src/sfeQwiicXM125.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ class QwDevXM125
1313
/// @return Error code (0 no error)
1414
bool begin(sfeTkII2C *theBus = nullptr);
1515

16+
int32_t returnRegister(uint32_t *regVal);
17+
1618
// --------------------- I2C Disance Detector Functions ---------------------
1719

1820
/// @brief This function returns the version number of the device
@@ -376,7 +378,7 @@ class QwDevXM125
376378
/// @return Error code (0 no error)
377379
int32_t getPresenceDetectorStatus(uint32_t *status);
378380

379-
/// @brief This function returns the number of detected distance.
381+
/// @brief This function returns if presence was detected
380382
/// @param detected Number of detected distance
381383
/// @return Error code (0 no error)
382384
int32_t getPresenceDistanceResult(uint32_t *detected);

0 commit comments

Comments
 (0)