W5500 and UWB not Working Together with ESP32
Ethernet Chips
No replies yet. Be the first to reply.
Join the discussion.
Ethernet Chips
No replies yet. Be the first to reply.
Join the discussion.
Share projects and connect with makers.
Joined before the site update? first.
New to WIZnet Makers?
We sent a verification link to your address. Open it to activate your account, then log in.
Accounts from this email provider are reviewed by an administrator after verification. Approval usually takes one business day.
Already have an account?
Enter your email address. If it belongs to an account, we'll send a link to set a new password. Members who joined before the site update use this to set their password.
If an account uses that address, we sent a link to set a new password. The link works once and expires in 30 minutes.
Know your password?
Need an account?
RE: W5500 and UWB not Working Together with ESP32
by Ali Hamza Malik ·
#include <SPI.h>
#include <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();
}
}
// 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);
}