---
title: "W5500 and UWB not Working Together with ESP32"
url: "https://maker.wiznet.io/forum/15278"
markdown_url: "https://maker.wiznet.io/forum/15278/md"
type: "Forum topic"
category: "Ethernet Chips"
author: "Ali Hamza Malik"
created: "2024-09-14T13:25:26+09:00"
last_activity: "2024-09-14T13:26:03+09:00"
language: "en"
views: 9
replies: 1
source: "WIZnet Makers forum (https://maker.wiznet.io/forum/)"
---

# W5500 and UWB not Working Together with ESP32

## Question

Asked by Ali Hamza Malik on 2024-09-14 in Ethernet Chips.

Hi everyone How are you.I am working on a Project right now in which I am using Esp32 with UWB to get distance. Now We can also send reading received by MQTT but I need to get the readings by Ethernet via W5500 Module. No when write code only for uwb i can get the distance readings from another similar PCB.But when I add code for W5500 both devices are initialized but UWB is not getting reading from Tag and When i add delay to initializw W5500 the I can recieve distance readings but W5500 failed to initliazed.Please Note W5500 and UWB are on Seprate SPI busses W5500 is on HSPI with different Cs and UWB is on VSPI.Can any body has any idea why this is happening.As i am using seprate SPI busses why its not working properly I can share more If any one has idea about this Thanks

## Replies

### Reply 1 by Ali Hamza Malik, 2024-09-14

#include &lt;SPI.h>
#include &lt;Ethernet.h>
#include “DW1000Ranging.h”

// SPI pins for W5500
#define HSPI_SCK 14
#define HSPI_MISO 12
#define HSPI_MOSI 13

// Chip Select pin for W5500
#define W5500_CS 15

// SPI pins for UWB
#define SPI_SCK 18
#define SPI_MISO 19
#define SPI_MOSI 23
#define DW_CS 5

// Control Pins for UWB
const uint8_t PIN_RST = 27; // reset pin
const uint8_t PIN_IRQ = 34; // irq pin
const uint8_t PIN_SS = 5; // spi select pin

// Ethernet configuration
byte mac = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // MAC address for W5500
IPAddress ip(192, 168, 1, 178); // Static IP address for W5500
IPAddress myDns(8, 8, 8, 8); // DNS server
IPAddress gateway(192, 168, 1, 1); // Gateway
IPAddress subnet(255, 255, 255, 0); // Subnet mask

EthernetServer server(23); // Create a server that listens on port 23

// Calibration Range for UWB
float calibrationRange = 0.78;

void setup() {
Serial.begin(115200);
delay(1000);

// Initialize the SPI bus for W5500
SPI.begin(HSPI_SCK, HSPI_MISO, HSPI_MOSI);

// Initialize W5500 Ethernet module with static IP
Serial.println(“Initializing W5500…”);
Ethernet.init(W5500_CS);
Ethernet.begin(mac, ip, myDns, gateway, subnet);

if (Ethernet.hardwareStatus() == EthernetNoHardware) {
Serial.println(“W5500 not found. Check wiring.”);
} else if (Ethernet.linkStatus() == LinkOFF) {
Serial.println(“Ethernet cable is not connected.”);
} else {
Serial.println(“Ethernet initialized successfully.”);
Serial.print("IP Address: ");
Serial.println(Ethernet.localIP());
}

server.begin(); // Start the TCP server

// Initialize SPI for UWB
SPI.begin(SPI_SCK, SPI_MISO, SPI_MOSI);
DW1000Ranging.initCommunication(PIN_RST, PIN_SS, PIN_IRQ);

// Define the sketch as anchor
DW1000Ranging.attachNewRange(newRange);
DW1000Ranging.attachBlinkDevice(newBlink);
DW1000Ranging.attachInactiveDevice(inactiveDevice);

DW1000.enableDebounceClock();
DW1000.enableLedBlinking();
DW1000.setGPIOMode(MSGP0, LED_MODE);

// Start the module as an anchor
DW1000Ranging.startAsAnchor(“82:17:5B:D5:A9:9A:E2:9C”, DW1000.MODE_LONGDATA_RANGE_LOWPOWER);
}

void loop() {
DW1000Ranging.loop();

// Check if a client has connected
EthernetClient client = server.available();
if (client) {
Serial.println(“New client connected”);
while (client.connected()) {
// Get the range data
String message = getRangeData();

```
  // Show message on serial monitor
  Serial.println("Sending to client: " + message);
 
  // Send the message to the client
  client.println(message);  
 
  delay(1000);  // Send the message every second
}
// Close the connection
client.stop();
Serial.println("Client disconnected");
```

}
}

// Function to get the range data
String getRangeData() {
String data = “”;
if (DW1000Ranging.getDistantDevice()) {
data += "from: ";
data += DW1000Ranging.getDistantDevice()->getShortAddress(), HEX;
data += "\t Range: ";
data += DW1000Ranging.getDistantDevice()->getRange() * calibrationRange;
data += " m\t RX power: “;
data += DW1000Ranging.getDistantDevice()->getRXPower();
data += " dBm”;
}
return data;
}

void newRange() {
Serial.print(“from: “); Serial.print(DW1000Ranging.getDistantDevice()->getShortAddress(), HEX);
Serial.print(”\t Range: “); Serial.print(DW1000Ranging.getDistantDevice()->getRange() * calibrationRange); Serial.print(” m”);
Serial.print(“\t RX power: “); Serial.print(DW1000Ranging.getDistantDevice()->getRXPower()); Serial.println(” dBm”);
}

void newBlink(DW1000Device* device) {
Serial.print(“blink; 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);
}

---

Source: https://maker.wiznet.io/forum/15278
