Skip to content

Commit 92ca522

Browse files
author
Eric
committed
ESP32 + UWB | Indoor Positioning + Unity Visualization
1 parent 2c6511b commit 92ca522

File tree

135 files changed

+26312
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

135 files changed

+26312
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/////////////////////////////////////////////////////////////////
2+
/*
3+
ESP32 + UWB | Indoor Positioning + Unity Visualization
4+
For More Information: https://youtu.be/c8Pn7lS5Ppg
5+
Created by Eric N. (ThatProject)
6+
*/
7+
/////////////////////////////////////////////////////////////////
8+
9+
#include <SPI.h>
10+
#include "DW1000Ranging.h"
11+
12+
// connection pins
13+
const uint8_t PIN_SCK = 18;
14+
const uint8_t PIN_MOSI = 23;
15+
const uint8_t PIN_MISO = 19;
16+
const uint8_t PIN_SS = 15;
17+
const uint8_t PIN_RST = 2;
18+
const uint8_t PIN_IRQ = 22;
19+
20+
void setup() {
21+
Serial.begin(115200);
22+
delay(1000);
23+
//init the configuration
24+
SPI.begin(PIN_SCK, PIN_MISO, PIN_MOSI);
25+
DW1000Ranging.initCommunication(PIN_RST, PIN_SS, PIN_IRQ); //Reset, CS, IRQ pin
26+
//define the sketch as anchor. It will be great to dynamically change the type of module
27+
DW1000Ranging.attachNewRange(newRange);
28+
DW1000Ranging.attachBlinkDevice(newBlink);
29+
DW1000Ranging.attachInactiveDevice(inactiveDevice);
30+
//Enable the filter to smooth the distance
31+
//DW1000Ranging.useRangeFilter(true);
32+
33+
DW1000.enableDebounceClock();
34+
DW1000.enableLedBlinking();
35+
DW1000.setGPIOMode(MSGP3, LED_MODE);
36+
37+
//Left Anchor - short name of this anchor: aabb
38+
//DW1000Ranging.startAsAnchor("BB:AA:5B:D5:A9:9A:E2:9C", DW1000.MODE_LONGDATA_RANGE_LOWPOWER, false);
39+
40+
//Right Anchor - short name of this anchor: ccdd
41+
DW1000Ranging.startAsAnchor("DD:CC:5B:D5:A9:9A:E2:9C", DW1000.MODE_LONGDATA_RANGE_LOWPOWER, false);
42+
}
43+
44+
void loop() {
45+
DW1000Ranging.loop();
46+
}
47+
48+
void newRange() {
49+
updateRange(DW1000Ranging.getDistantDevice()->getRange());
50+
}
51+
52+
void newBlink(DW1000Device* device) {
53+
}
54+
55+
void inactiveDevice(DW1000Device* device) {
56+
}
57+
58+
void updateRange(float range) {
59+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/////////////////////////////////////////////////////////////////
2+
/*
3+
ESP32 + UWB | Indoor Positioning + Unity Visualization
4+
For More Information: https://youtu.be/c8Pn7lS5Ppg
5+
Created by Eric N. (ThatProject)
6+
*/
7+
/////////////////////////////////////////////////////////////////
8+
9+
#include <SPI.h>
10+
#include "DW1000Ranging.h"
11+
#include "WiFi.h"
12+
#include <WiFiUdp.h>
13+
14+
// connection pins
15+
const uint8_t PIN_SCK = 18;
16+
const uint8_t PIN_MOSI = 23;
17+
const uint8_t PIN_MISO = 19;
18+
const uint8_t PIN_SS = 15;
19+
const uint8_t PIN_RST = 2;
20+
const uint8_t PIN_IRQ = 22;
21+
22+
const char * ssid = "ThatProject";
23+
const char * password = "California";
24+
const char * udpAddress = "192.168.0.2"; //My UDP Server IP
25+
const int udpPort = 8080;
26+
27+
boolean connected = false;
28+
WiFiUDP udp;
29+
30+
void setup() {
31+
Serial.begin(115200);
32+
delay(1000);
33+
SPI.begin(PIN_SCK, PIN_MISO, PIN_MOSI);
34+
//init the configuration
35+
DW1000Ranging.initCommunication(PIN_RST, PIN_SS, PIN_IRQ); //Reset, CS, IRQ pin
36+
//define the sketch as anchor. It will be great to dynamically change the type of module
37+
DW1000Ranging.attachNewRange(newRange);
38+
DW1000Ranging.attachNewDevice(newDevice);
39+
DW1000Ranging.attachInactiveDevice(inactiveDevice);
40+
//Enable the filter to smooth the distance
41+
//DW1000Ranging.useRangeFilter(true);
42+
43+
DW1000.enableDebounceClock();
44+
DW1000.enableLedBlinking();
45+
DW1000.setGPIOMode(MSGP3, LED_MODE);
46+
47+
//we start the module as a tag
48+
DW1000Ranging.startAsTag("7D:00:22:EA:82:60:3B:9C", DW1000.MODE_LONGDATA_RANGE_LOWPOWER);
49+
50+
connectToWiFi(ssid, password);
51+
}
52+
53+
void loop() {
54+
DW1000Ranging.loop();
55+
}
56+
57+
void newRange() {
58+
float projectedRange = DW1000Ranging.getDistantDevice()->getRange() * 2 / 5;
59+
String strData = String(DW1000Ranging.getDistantDevice()->getShortAddress(), HEX);
60+
strData += ", ";
61+
strData += String(projectedRange);
62+
Serial.println(strData);
63+
64+
if(connected){
65+
udp.beginPacket(udpAddress, udpPort);
66+
udp.write((uint8_t *)strData.c_str(), strlen(strData.c_str()));
67+
udp.endPacket();
68+
}
69+
}
70+
71+
void newDevice(DW1000Device* device) {
72+
Serial.print("ranging init; 1 device added ! -> ");
73+
Serial.print(" short:");
74+
Serial.println(device->getShortAddress(), HEX);
75+
}
76+
77+
void inactiveDevice(DW1000Device* device) {
78+
Serial.print("delete inactive device: ");
79+
Serial.println(device->getShortAddress(), HEX);
80+
}
81+
82+
void WiFiEvent(WiFiEvent_t event){
83+
switch(event) {
84+
case SYSTEM_EVENT_STA_GOT_IP:
85+
Serial.print("WiFi connected! IP address: ");
86+
Serial.println(WiFi.localIP());
87+
udp.begin(WiFi.localIP(),udpPort);
88+
connected = true;
89+
break;
90+
case SYSTEM_EVENT_STA_DISCONNECTED:
91+
Serial.println("WiFi lost connection");
92+
connected = false;
93+
break;
94+
}
95+
}
96+
97+
void connectToWiFi(const char * ssid, const char * pwd){
98+
Serial.println();
99+
Serial.println("Connecting to WiFi network: " + String(ssid));
100+
WiFi.disconnect(true);
101+
WiFi.onEvent(WiFiEvent);
102+
WiFi.begin(ssid, pwd);
103+
Serial.println("Waiting for WIFI connection...");
104+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# This .gitignore file should be placed at the root of your Unity project directory
2+
#
3+
# Get latest from https://github.com/github/gitignore/blob/master/Unity.gitignore
4+
#
5+
/[Ll]ibrary/
6+
/[Tt]emp/
7+
/[Oo]bj/
8+
/[Bb]uild/
9+
/[Bb]uilds/
10+
/[Ll]ogs/
11+
/[Uu]ser[Ss]ettings/
12+
13+
# MemoryCaptures can get excessive in size.
14+
# They also could contain extremely sensitive data
15+
/[Mm]emoryCaptures/
16+
17+
# Asset meta data should only be ignored when the corresponding asset is also ignored
18+
!/[Aa]ssets/**/*.meta
19+
20+
# Uncomment this line if you wish to ignore the asset store tools plugin
21+
# /[Aa]ssets/AssetStoreTools*
22+
23+
# Autogenerated Jetbrains Rider plugin
24+
/[Aa]ssets/Plugins/Editor/JetBrains*
25+
26+
# Visual Studio cache directory
27+
.vs/
28+
29+
# Gradle cache directory
30+
.gradle/
31+
32+
# Autogenerated VS/MD/Consulo solution and project files
33+
ExportedObj/
34+
.consulo/
35+
*.csproj
36+
*.unityproj
37+
*.sln
38+
*.suo
39+
*.tmp
40+
*.user
41+
*.userprefs
42+
*.pidb
43+
*.booproj
44+
*.svd
45+
*.pdb
46+
*.mdb
47+
*.opendb
48+
*.VC.db
49+
50+
# Unity3D generated meta files
51+
*.pidb.meta
52+
*.pdb.meta
53+
*.mdb.meta
54+
55+
# Unity3D generated file on crash reports
56+
sysinfo.txt
57+
58+
# Builds
59+
*.apk
60+
*.unitypackage
61+
62+
# Crashlytics generated file
63+
crashlytics-build.properties
64+
65+
# Packed Addressables
66+
/[Aa]ssets/[Aa]ddressable[Aa]ssets[Dd]ata/*/*.bin*
67+
68+
# Temporary auto-generated Android Assets
69+
/[Aa]ssets/[Ss]treamingAssets/aa.meta
70+
/[Aa]ssets/[Ss]treamingAssets/aa/*

UWB_Indoor_Position_Visualization/Unity_UWB_INDOOR_POSITION_Visualization/.idea/.idea.UWB_INDOOR_POSITION/.idea/.gitignore

+13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UWB_Indoor_Position_Visualization/Unity_UWB_INDOOR_POSITION_Visualization/.idea/.idea.UWB_INDOOR_POSITION/.idea/indexLayout.xml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UWB_Indoor_Position_Visualization/Unity_UWB_INDOOR_POSITION_Visualization/.idea/.idea.UWB_INDOOR_POSITION/.idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UWB_Indoor_Position_Visualization/Unity_UWB_INDOOR_POSITION_Visualization/.idea/.idea.Unity_UWB_INDOOR_POSITION_Visualization/.idea/.gitignore

+13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UWB_Indoor_Position_Visualization/Unity_UWB_INDOOR_POSITION_Visualization/.idea/.idea.Unity_UWB_INDOOR_POSITION_Visualization/.idea/indexLayout.xml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UWB_Indoor_Position_Visualization/Unity_UWB_INDOOR_POSITION_Visualization/.idea/.idea.Unity_UWB_INDOOR_POSITION_Visualization/.idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UWB_Indoor_Position_Visualization/Unity_UWB_INDOOR_POSITION_Visualization/Assets/Images.meta

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)