I want to obtain the range value using the code below and print it to the serial port. However, my output appears as follows: "17:31:53.127 -> from: DE0 Range: 0.00 m RX power: 0.00 dBm".
I've checked the SPI connections multiple times according to the dwm1001c datasheet, but I haven't been able to get any results. Could there be an issue with the pins I'm using on the ESP32? Thank you very much for your help.
type here
#include <SPI.h>
#include <DW1000.h>
#include <DW1000Ranging.h>
// connection pins
const uint8_t PIN_SCK = 18;
const uint8_t PIN_MOSI = 23;
const uint8_t PIN_MISO = 19;
const uint8_t PIN_SS = 15;
const uint8_t PIN_RST = 2;
const uint8_t PIN_IRQ = 22;
DW1000Device myDevice;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
delay(100);
initDW1000();
delay(100);
inactiveDevice(&myDevice);
delay(30000);
newDevice(&myDevice);
delay(30000);
}
void newRange() {
Serial.print("from: ");
Serial.print(DW1000Ranging.getDistantDevice()->getShortAddress(), HEX);
Serial.print("\t Range: ");
Serial.print(DW1000Ranging.getDistantDevice()->getRange());
Serial.print(" m");
Serial.print("\t RX power: ");
Serial.print(DW1000Ranging.getDistantDevice()->getRXPower());
Serial.println(" dBm");
}
void newDevice(DW1000Device* device) {
Serial.print("ranging init; 1 device added ! -> ");
Serial.print(" short:");
//Serial.println(device->getShortAddress(), HEX);
}
void inactiveDevice(DW1000Device* device) {
Serial.print("delete inactive device: ");
Serial.println(device->getShortAddress(), HEX);
}
void initDW1000() {
SPI.begin(PIN_SCK, PIN_MISO, PIN_MOSI);
//init the configuration
DW1000Ranging.initCommunication(PIN_RST, PIN_SS, PIN_IRQ); //Reset, CS, IRQ pin
//define the sketch as anchor. It will be great to dynamically change the type of module
DW1000Ranging.attachNewRange(newRange);
DW1000Ranging.attachNewDevice(newDevice);
DW1000Ranging.attachInactiveDevice(inactiveDevice);
//Enable the filter to smooth the distance
//DW1000Ranging.useRangeFilter(true);
DW1000.enableDebounceClock();
DW1000.enableLedBlinking();
DW1000.setGPIOMode(MSGP0, LED_MODE);
//we start the module as a tag
DW1000Ranging.startAsTag("FC:60:9A:AF:55:1C", DW1000.MODE_LONGDATA_RANGE_ACCURACY);
}
void loop() {
// put your main code here, to run repeatedly:
newRange();
delay(1000);
}
I am trying to retrieve the range value from the DWM1001C module using Arduino and programming ESP32 through SPI communication. However, it keeps returning 0 consistently. I don't think the SPI connection is being established properly. Could you help me?
Do you know a code block that I can use to test my SPI connection? Because I want to determine if the issue is with the DWM1001C module or with my SPI connection. By the way, the SPI codes are embedded within the DW1000.h library. I've changed the values of IRQ, RST, and SS pins with the numbers I sent by checking their values within the library, but that didn't work either.