#include <Servo.h>
#include <Wire.h>
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
Servo bldc;
double roll,pitch,yaw,thr;
char packet[255];
struct __attribute__((packed)) JoyStick {
double yaw;
double thr;
double pitch;
double roll;
int32_t mode;
double array[9];
};
#define WIFI_SSID "K.G.F - 2"
#define WIFI_PASS "assafkhan92786"
#define UDP_PORT 4210
//----------------------------------------
WiFiUDP UDP;
void setup() {
Serial.begin(115200); //115200
//-----------------------------
WiFi.begin(WIFI_SSID, WIFI_PASS);
Serial.print("Connecting to ");
Serial.print(WIFI_SSID);
while (WiFi.status() != WL_CONNECTED)
{
delay(100);
Serial.print(".");
}
// Connected to WiFi
Serial.println();
Serial.print("Connected! IP address: ");
Serial.println(WiFi.localIP());
// Begin listening to UDP port
UDP.begin(UDP_PORT);
Serial.print("Listening on UDP port ");
Serial.println(UDP_PORT);
//----------------------------
bldc.attach(D5,1000,2000);
}
void udp_rcv()
{
int packetSize = UDP.parsePacket();
JoyStick myJoystick;
if (packetSize) {
//Serial.printf("Received %d bytes\n", packetSize);
if (UDP.read(packet, packetSize) > 0) {
memcpy(&myJoystick, packet, packetSize); //copy packet array to the a struct
//Serial.print(myJoystick.roll,HEX);
yaw=myJoystick.yaw;
thr=myJoystick.thr;
pitch=myJoystick.pitch;
roll=myJoystick.roll;
}
}
}
void loop()
{
udp_rcv();
Serial.println(thr);// the received values are in range from 0 to 1023
bldc.writeMicroseconds(thr);
}
I am trying to controll a 1000kv bldc motor(A2212) with a 30A ESC using esp8266, but I am completely lost, and I am unable to ARM the motor and controll it, although I am reciving the input from my laptop via UDP, please guide me, on how to ARM the ESC/MOTOR, and controll its speed using ESP8266 (wemos D1 mini) also I have used the d5 and d6 pin in wemos_d1_mini, so please let me know which other pins i can use.