-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWLOOP_Onboarding_ESP32.ino
More file actions
68 lines (50 loc) · 2.03 KB
/
Copy pathWLOOP_Onboarding_ESP32.ino
File metadata and controls
68 lines (50 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Bluetooth Reference: https://randomnerdtutorials.com/esp32-bluetooth-classic-arduino-ide
// UART Reference: https://www.youtube.com/watch?v=1veVFMcxe3M
#include "BluetoothSerial.h"
#include <HardwareSerial.h>
// #include <ESP32Servo.h> // install ESP32Servo Library
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif
BluetoothSerial SerialBT;
HardwareSerial SerialPort(2); // port 2 for UART communication
// Servo servo;
// int servoPin = 15; // GPIO to connect servo (digital out)
// Interrupt Handler
void IRAM_ATTR isr() {
SerialPort.println("BRAKE");
}
void setup() {
// Servo Setup
// servo.setPeriodHertz(50);
// servo.attach(servoPin, 500, 2500); // attach servo on servoPin to servo object
SerialPort.begin(115200, SERIAL_8N1, 34, 35); // initialize UART (34 = RX, 35 = TX)
Serial.begin(115200); // initialize serial port for debugging
SerialBT.begin("ESP32Test"); //Bluetooth device name
Serial.println("The device started, now you can pair it with bluetooth!");
attachInterrupt()
}
void loop() {
// check if bytes received in serial port
// if (Serial.available()) {
// SerialBT.write(Serial.read()); // send via Bluetooth to connected device
// }
// check if bytes available to read in Bluetooth serial port
if (SerialBT.available()) {
//Serial.write(SerialBT.read()); // write bytes to serial monitor
String bluetoothData = SerialBT.readStringUntil('\n'); // read data from Bluetooth
Serial.println("Received from Bluetooth: " + bluetoothData);
// Send desired commands to STM32
if (bluetoothData.equals("BEGIN")) {
SerialPort.println("BEGIN");
} else if (bluetoothData.equals("END")) {
SerialPort.println("END");
}
}
// check if data is present in UART buffer
if(SerialPort.available()){
String bufferUART = SerialPort.readStringUntil('\n'); // read data from UART
Serial.println("Received from STM32: " + bufferUART);
}
delay(20);
}