@@ -186,18 +186,18 @@ void rangingHandler(UWBRangingData &rangingData) {
186
186
if(newDoorState != doorUnlocked) {
187
187
doorUnlocked = newDoorState;
188
188
digitalWrite(DOOR_CONTROL_PIN, doorUnlocked ? HIGH : LOW);
189
- #if defined(ARDUINO_PORTENTA_C33)
189
+ #if defined(ARDUINO_PORTENTA_C33)
190
190
digitalWrite(LEDG, doorUnlocked ? LOW : HIGH); // Green LED for door status
191
- #endif
191
+ #endif
192
192
}
193
193
194
194
// Update machine control
195
195
if(newMachineState != machineEnabled) {
196
196
machineEnabled = newMachineState;
197
197
digitalWrite(MACHINE_CONTROL_PIN, machineEnabled ? HIGH : LOW);
198
- #if defined(ARDUINO_PORTENTA_C33)
198
+ #if defined(ARDUINO_PORTENTA_C33)
199
199
digitalWrite(LEDB, machineEnabled ? LOW : HIGH); // Blue LED for machine status
200
- #endif
200
+ #endif
201
201
}
202
202
203
203
lastProximityStateChange = millis();
@@ -322,7 +322,7 @@ Below is the complete code for the Arduino Stella. To compile and upload the cod
322
322
*/
323
323
324
324
// Include required UWB library for Arduino Stella
325
- #include "ardUWBSr040.h"
325
+ #include <StellaUWB.h>
326
326
327
327
// Define proximity thresholds (centimeters)
328
328
#define WORKSPACE_ACCESS_THRESHOLD 100 // 1 meter for door unlock
@@ -344,7 +344,10 @@ unsigned long lastBlinkTime = 0;
344
344
@param rangingData Reference to UWB ranging data object
345
345
*/
346
346
void rangingHandler(UWBRangingData &rangingData) {
347
- if(rangingData.measureType() == MEASUREMENT_TYPE_TWOWAY) {
347
+ Serial.print("GOT RANGING DATA - Type: ");
348
+ Serial.println(rangingData.measureType());
349
+
350
+ if(rangingData.measureType() == (uint8_t)uwb::MeasurementType::TWO_WAY) {
348
351
RangingMeasures twr = rangingData.twoWayRangingMeasure();
349
352
350
353
for(int j = 0; j < rangingData.available(); j++) {
@@ -386,25 +389,45 @@ void setup() {
386
389
digitalWrite(LED_PIN, HIGH); // Start with LED off
387
390
lastLedPhysicalState = true;
388
391
389
- Serial.println("UWB Personal Access Tag");
392
+ Serial.println("UWB Personal Access Tag - Stella ");
390
393
394
+ // Define the source (this device) and destination MAC addresses, using 2-bytes MACs
395
+ // This device is the controller/initiator, so it uses 0x22,0x22
396
+ // and targets the responder/controlee at 0x11,0x11
391
397
uint8_t devAddr[] = {0x22, 0x22};
392
398
uint8_t destination[] = {0x11, 0x11};
393
399
UWBMacAddress srcAddr(UWBMacAddress::Size::SHORT, devAddr);
394
400
UWBMacAddress dstAddr(UWBMacAddress::Size::SHORT, destination);
395
401
402
+ // Register the ranging notification handler before starting
396
403
UWB.registerRangingCallback(rangingHandler);
397
- UWB.begin();
398
404
405
+ UWB.begin(); // Start the UWB stack, use Serial for the log output
406
+ Serial.println("Starting UWB ...");
407
+
408
+ // Wait until the stack is initialized
399
409
while(UWB.state() != 0)
400
410
delay(10);
401
411
412
+ Serial.println("Starting session ...");
413
+
414
+ // Setup a session with ID 0x11223344 as Controller/Initiator (default role)
402
415
UWBTracker myTracker(0x11223344, srcAddr, dstAddr);
416
+
417
+ // Add the session to the session manager
403
418
UWBSessionManager.addSession(myTracker);
419
+
420
+ // Prepare the session applying the default parameters
404
421
myTracker.init();
422
+
423
+ // Start the session
405
424
myTracker.start();
406
425
407
426
Serial.println("Personal tag ready!");
427
+ Serial.println("Proximity zones:");
428
+ Serial.println("- Outside workspace: LED off");
429
+ Serial.println("- Workspace zone (≤" + String(WORKSPACE_ACCESS_THRESHOLD) + "cm): Slow blink");
430
+ Serial.println("- Equipment zone (≤" + String(EQUIPMENT_OPERATION_THRESHOLD) + "cm): Fast blink");
408
431
409
432
// Initialization complete signal
410
433
for(int i = 0; i < 3; i++) {
@@ -420,12 +443,14 @@ void loop() {
420
443
421
444
// Handle LED control based on proximity zones
422
445
if(blinkInterval == 0) {
446
+ // Outside workspace - LED off
423
447
if(lastLedPhysicalState != true) {
424
448
digitalWrite(LED_PIN, HIGH);
425
449
lastLedPhysicalState = true;
426
450
ledState = false;
427
451
}
428
452
} else {
453
+ // Inside workspace - blink at appropriate interval
429
454
if(currentTime - lastBlinkTime >= blinkInterval) {
430
455
lastBlinkTime = currentTime;
431
456
ledState = !ledState;
0 commit comments