@@ -186,18 +186,18 @@ void rangingHandler(UWBRangingData &rangingData) {
186186 if(newDoorState != doorUnlocked) {
187187 doorUnlocked = newDoorState;
188188 digitalWrite(DOOR_CONTROL_PIN, doorUnlocked ? HIGH : LOW);
189- #if defined(ARDUINO_PORTENTA_C33)
189+ #if defined(ARDUINO_PORTENTA_C33)
190190 digitalWrite(LEDG, doorUnlocked ? LOW : HIGH); // Green LED for door status
191- #endif
191+ #endif
192192 }
193193
194194 // Update machine control
195195 if(newMachineState != machineEnabled) {
196196 machineEnabled = newMachineState;
197197 digitalWrite(MACHINE_CONTROL_PIN, machineEnabled ? HIGH : LOW);
198- #if defined(ARDUINO_PORTENTA_C33)
198+ #if defined(ARDUINO_PORTENTA_C33)
199199 digitalWrite(LEDB, machineEnabled ? LOW : HIGH); // Blue LED for machine status
200- #endif
200+ #endif
201201 }
202202
203203 lastProximityStateChange = millis();
@@ -322,7 +322,7 @@ Below is the complete code for the Arduino Stella. To compile and upload the cod
322322*/
323323
324324// Include required UWB library for Arduino Stella
325- #include "ardUWBSr040.h"
325+ #include <StellaUWB.h>
326326
327327// Define proximity thresholds (centimeters)
328328#define WORKSPACE_ACCESS_THRESHOLD 100 // 1 meter for door unlock
@@ -344,7 +344,10 @@ unsigned long lastBlinkTime = 0;
344344 @param rangingData Reference to UWB ranging data object
345345*/
346346void 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) {
348351 RangingMeasures twr = rangingData.twoWayRangingMeasure();
349352
350353 for(int j = 0; j < rangingData.available(); j++) {
@@ -386,25 +389,45 @@ void setup() {
386389 digitalWrite(LED_PIN, HIGH); // Start with LED off
387390 lastLedPhysicalState = true;
388391
389- Serial.println("UWB Personal Access Tag");
392+ Serial.println("UWB Personal Access Tag - Stella ");
390393
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
391397 uint8_t devAddr[] = {0x22, 0x22};
392398 uint8_t destination[] = {0x11, 0x11};
393399 UWBMacAddress srcAddr(UWBMacAddress::Size::SHORT, devAddr);
394400 UWBMacAddress dstAddr(UWBMacAddress::Size::SHORT, destination);
395401
402+ // Register the ranging notification handler before starting
396403 UWB.registerRangingCallback(rangingHandler);
397- UWB.begin();
398404
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
399409 while(UWB.state() != 0)
400410 delay(10);
401411
412+ Serial.println("Starting session ...");
413+
414+ // Setup a session with ID 0x11223344 as Controller/Initiator (default role)
402415 UWBTracker myTracker(0x11223344, srcAddr, dstAddr);
416+
417+ // Add the session to the session manager
403418 UWBSessionManager.addSession(myTracker);
419+
420+ // Prepare the session applying the default parameters
404421 myTracker.init();
422+
423+ // Start the session
405424 myTracker.start();
406425
407426 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");
408431
409432 // Initialization complete signal
410433 for(int i = 0; i < 3; i++) {
@@ -420,12 +443,14 @@ void loop() {
420443
421444 // Handle LED control based on proximity zones
422445 if(blinkInterval == 0) {
446+ // Outside workspace - LED off
423447 if(lastLedPhysicalState != true) {
424448 digitalWrite(LED_PIN, HIGH);
425449 lastLedPhysicalState = true;
426450 ledState = false;
427451 }
428452 } else {
453+ // Inside workspace - blink at appropriate interval
429454 if(currentTime - lastBlinkTime >= blinkInterval) {
430455 lastBlinkTime = currentTime;
431456 ledState = !ledState;
0 commit comments