Compare commits
10 commits
0f2e0e9374
...
6890b53161
Author | SHA1 | Date | |
---|---|---|---|
6890b53161 | |||
f2dbf018b9 | |||
97d80e7f73 | |||
c595a4ab3c | |||
0903ed14c2 | |||
2b2e716e6a | |||
a1da93e206 | |||
bbf538a87c | |||
ddc32358f6 | |||
29d6622726 |
4 changed files with 218 additions and 17 deletions
73
BLE-Communication/client.py
Normal file
73
BLE-Communication/client.py
Normal file
|
@ -0,0 +1,73 @@
|
|||
# import asyncio
|
||||
# from bleak import BleakClient
|
||||
|
||||
# # Replace with your ESP32 address and characteristic UUIDs
|
||||
# ESP32_ADDRESS = "80:7D:3A:B7:99:A2"
|
||||
# SENSOR_CHARACTERISTIC_UUID = "19b10001-e8f2-537e-4f6c-d104768a1214"
|
||||
# LED_CHARACTERISTIC_UUID = "19b10002-e8f2-537e-4f6c-d104768a1214"
|
||||
|
||||
# led_state = 0
|
||||
|
||||
# async def run(address, loop):
|
||||
# global led_state
|
||||
# try:
|
||||
# async with BleakClient(address, loop=loop) as client:
|
||||
# print(f"Connected to {address}")
|
||||
# while True:
|
||||
# # Read temperature
|
||||
# data = await client.read_gatt_char(SENSOR_CHARACTERISTIC_UUID)
|
||||
# temperature = float(data.decode('utf_8')) # Assuming temperature is the value
|
||||
# print(temperature)
|
||||
|
||||
# # Write to LED characteristic
|
||||
# await client.write_gatt_char(LED_CHARACTERISTIC_UUID, bytearray([led_state]))
|
||||
# print(f"LED state set to {led_state}")
|
||||
|
||||
# # Toggle LED state
|
||||
# led_state = 1 - led_state
|
||||
|
||||
# await asyncio.sleep(1) # Adjust the interval as needed
|
||||
# except Exception as e:
|
||||
# print(f"Error: {e}")
|
||||
|
||||
# loop = asyncio.get_event_loop()
|
||||
# loop.run_until_complete(run(ESP32_ADDRESS, loop))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
import asyncio
|
||||
from bleak import BleakClient
|
||||
|
||||
# Replace with your ESP32 address and characteristic UUIDs
|
||||
ESP32_ADDRESS = "F4:12:FA:9F:27:11"
|
||||
SENSOR_CHARACTERISTIC_UUID = "19b10001-e8f2-537e-4f6c-d104768a1214"
|
||||
LED_CHARACTERISTIC_UUID = "19b10002-e8f2-537e-4f6c-d104768a1214"
|
||||
|
||||
led_state = 0
|
||||
|
||||
async def run(address, loop):
|
||||
global led_state
|
||||
try:
|
||||
async with BleakClient(address, loop=loop) as client:
|
||||
print(f"Connected to {address}")
|
||||
while True:
|
||||
# Read temperature
|
||||
data = await client.read_gatt_char(SENSOR_CHARACTERISTIC_UUID)
|
||||
temperature = float(data.decode('utf_8')) # Assuming temperature is the value
|
||||
print(temperature)
|
||||
|
||||
# Write to LED characteristic
|
||||
await client.write_gatt_char(LED_CHARACTERISTIC_UUID, bytearray([led_state]))
|
||||
print(f"LED state set to {led_state}")
|
||||
|
||||
# Toggle LED state
|
||||
led_state = 1 - led_state
|
||||
|
||||
await asyncio.sleep(0.01) # Adjust the interval as needed
|
||||
except Exception as e:
|
||||
print(f"Error: {e}")
|
||||
|
||||
loop = asyncio.get_event_loop()
|
||||
loop.run_until_complete(run(ESP32_ADDRESS, loop))
|
122
BLE-Communication/server/server.ino
Normal file
122
BLE-Communication/server/server.ino
Normal file
|
@ -0,0 +1,122 @@
|
|||
#include <BLEDevice.h>
|
||||
#include <BLEServer.h>
|
||||
#include <BLEUtils.h>
|
||||
#include <BLE2902.h>
|
||||
|
||||
BLEServer* pServer = NULL;
|
||||
BLECharacteristic* pSensorCharacteristic = NULL;
|
||||
BLECharacteristic* pLedCharacteristic = NULL;
|
||||
bool deviceConnected = false;
|
||||
bool oldDeviceConnected = false;
|
||||
uint32_t value = 0;
|
||||
|
||||
const int ledPin = 2; // Use the appropriate GPIO pin for your setup
|
||||
|
||||
// See the following for generating UUIDs:
|
||||
// https://www.uuidgenerator.net/
|
||||
|
||||
#define SERVICE_UUID "19b10000-e8f2-537e-4f6c-d104768a1214"
|
||||
#define SENSOR_CHARACTERISTIC_UUID "19b10001-e8f2-537e-4f6c-d104768a1214"
|
||||
#define LED_CHARACTERISTIC_UUID "19b10002-e8f2-537e-4f6c-d104768a1214"
|
||||
|
||||
class MyServerCallbacks: public BLEServerCallbacks {
|
||||
void onConnect(BLEServer* pServer) {
|
||||
deviceConnected = true;
|
||||
};
|
||||
|
||||
void onDisconnect(BLEServer* pServer) {
|
||||
deviceConnected = false;
|
||||
}
|
||||
};
|
||||
|
||||
class MyCharacteristicCallbacks : public BLECharacteristicCallbacks {
|
||||
void onWrite(BLECharacteristic* pLedCharacteristic) {
|
||||
std::string value = pLedCharacteristic->getValue();
|
||||
if (value.length() > 0) {
|
||||
Serial.print("Characteristic event, written: ");
|
||||
Serial.println(static_cast<int>(value[0])); // Print the integer value
|
||||
|
||||
int receivedValue = static_cast<int>(value[0]);
|
||||
if (receivedValue == 1) {
|
||||
digitalWrite(ledPin, HIGH);
|
||||
} else {
|
||||
digitalWrite(ledPin, LOW);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
pinMode(ledPin, OUTPUT);
|
||||
|
||||
// Create the BLE Device
|
||||
BLEDevice::init("ESP32");
|
||||
|
||||
// Create the BLE Server
|
||||
pServer = BLEDevice::createServer();
|
||||
pServer->setCallbacks(new MyServerCallbacks());
|
||||
|
||||
// Create the BLE Service
|
||||
BLEService *pService = pServer->createService(SERVICE_UUID);
|
||||
|
||||
// Create a BLE Characteristic
|
||||
pSensorCharacteristic = pService->createCharacteristic(
|
||||
SENSOR_CHARACTERISTIC_UUID,
|
||||
BLECharacteristic::PROPERTY_READ |
|
||||
BLECharacteristic::PROPERTY_WRITE |
|
||||
BLECharacteristic::PROPERTY_NOTIFY |
|
||||
BLECharacteristic::PROPERTY_INDICATE
|
||||
);
|
||||
|
||||
// Create the ON button Characteristic
|
||||
pLedCharacteristic = pService->createCharacteristic(
|
||||
LED_CHARACTERISTIC_UUID,
|
||||
BLECharacteristic::PROPERTY_WRITE
|
||||
);
|
||||
|
||||
// Register the callback for the ON button characteristic
|
||||
pLedCharacteristic->setCallbacks(new MyCharacteristicCallbacks());
|
||||
|
||||
// https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.descriptor.gatt.client_characteristic_configuration.xml
|
||||
// Create a BLE Descriptor
|
||||
pSensorCharacteristic->addDescriptor(new BLE2902());
|
||||
pLedCharacteristic->addDescriptor(new BLE2902());
|
||||
|
||||
// Start the service
|
||||
pService->start();
|
||||
|
||||
// Start advertising
|
||||
BLEAdvertising *pAdvertising = BLEDevice::getAdvertising();
|
||||
pAdvertising->addServiceUUID(SERVICE_UUID);
|
||||
pAdvertising->setScanResponse(false);
|
||||
pAdvertising->setMinPreferred(0x0); // set value to 0x00 to not advertise this parameter
|
||||
BLEDevice::startAdvertising();
|
||||
Serial.println("Waiting a client connection to notify...");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// notify changed value
|
||||
if (deviceConnected) {
|
||||
pSensorCharacteristic->setValue(String(value).c_str());
|
||||
pSensorCharacteristic->notify();
|
||||
value++;
|
||||
Serial.print("New value notified: ");
|
||||
Serial.println(value);
|
||||
delay(100); // bluetooth stack will go into congestion, if too many packets are sent, in 6 hours test i was able to go as low as 3ms
|
||||
}
|
||||
// disconnecting
|
||||
if (!deviceConnected && oldDeviceConnected) {
|
||||
Serial.println("Device disconnected.");
|
||||
delay(500); // give the bluetooth stack the chance to get things ready
|
||||
pServer->startAdvertising(); // restart advertising
|
||||
Serial.println("Start advertising");
|
||||
oldDeviceConnected = deviceConnected;
|
||||
}
|
||||
// connecting
|
||||
if (deviceConnected && !oldDeviceConnected) {
|
||||
// do stuff here on connecting
|
||||
oldDeviceConnected = deviceConnected;
|
||||
Serial.println("Device Connected");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
void setup() {
|
||||
// put your setup code here, to run once:
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// put your main code here, to run repeatedly:
|
||||
|
||||
}
|
31
README.md
31
README.md
|
@ -1,13 +1,13 @@
|
|||
# Ringinator
|
||||
|
||||
The repository for my 3D-printed ring-shaped motion-control presentation control and pointer device written in C, MicroPython and TinyML and implemented with a TinyPICO Nano microcontroller. The Bachelor thesis is written in Typst.
|
||||
The repository for my 3D-printed ring-shaped motion-control presentation control and pointer device written in C++ and TinyML and implemented with a TinyS3 microcontroller. The Bachelor thesis is written in Typst.
|
||||
|
||||
## Goals
|
||||
|
||||
The goal is to develop a prototype device shaped like a ring that can be used to control presentations and as a laser pointer using only motion controls.
|
||||
|
||||
1. Maximum compactness
|
||||
Everything needs to be small, the software should be minimalistic (ideally as much processing on the TinyPICO as possible)
|
||||
Everything needs to be small, the software should be minimalistic (ideally as much processing on the TinyS3 as possible)
|
||||
2. Wirelessness
|
||||
|
||||
Planned commands:
|
||||
|
@ -25,7 +25,7 @@ My goal is to work on my bachelor thesis every day 18:00 and when I'm in the lib
|
|||
- [ ] Wiring the components together
|
||||
- [ ] Soldering the components together
|
||||
- [ ] Creating the hull containing the components
|
||||
- [ ] Establishing a connection between the TinyPICO and the PC
|
||||
- [ ] Establishing a connection between the TinyS3 and the PC
|
||||
- [ ] Write the first chapters (State of the art and goals)
|
||||
- [ ] May: Software:
|
||||
- [ ] IMU-Visualization
|
||||
|
@ -33,21 +33,18 @@ My goal is to work on my bachelor thesis every day 18:00 and when I'm in the lib
|
|||
- [ ] Setting up TinyML
|
||||
- [ ] June: Training and evaluating the models
|
||||
|
||||
### Tasks for today
|
||||
### Done To-Dos
|
||||
|
||||
- [x] Setup the Forgejo directory
|
||||
- [ ] Connect the Dummy ESP32 with your Arduino IDE and set everything up wired
|
||||
- [ ] Prepare the first pages in the Bachelor thesis
|
||||
- [ ] Write an email to your mentors
|
||||
- [x] Connect the Dummy ESP32 with your Arduino IDE and set everything up wired
|
||||
- [x] Establish a Bluetooth connection between your ESP32 and your PC
|
||||
- [x] Write the first report
|
||||
- [x] Set the chapters in the Bachelor thesis as in line with past bachelor theses at TAMS
|
||||
- [x] Write the goals and the delimitation
|
||||
|
||||
## To-Dos this week
|
||||
|
||||
### Tasks for tomorrow
|
||||
|
||||
- [ ] Set the chapters in the Bachelor thesis as in line with past bachelor theses at TAMS
|
||||
- [ ] Collecting TinyML and TinyPICO tutorials
|
||||
|
||||
## Link to the Typst paper
|
||||
|
||||
The Bachelor Thesis can be accessed here by anyone:
|
||||
|
||||
[Bachelor Thesis](https://typst.app/project/rio617iGUt9juXxjIQUfiF)
|
||||
- [ ] Write the summaries of the 8 state of the art papers in the State of the Art chapter
|
||||
- [ ] Write the sources for the TinyML tutorials in the introduction
|
||||
- [ ] Establish bidirectional Bluetooth communication and visualize the output from the ESP32
|
||||
- [ ] Solder the headers onto the TinyS3
|
||||
|
|
Loading…
Reference in a new issue