无法用WEMOS D1 MINI和30A ESC使用A2212(1000KV)电动机

发布于 2025-01-27 04:55:47 字数 1926 浏览 7 评论 0原文

#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);
}

我正在尝试使用ESP8266使用30A ESC控制1000kV BLDC电机(A2212),但我完全迷失了,尽管我正在通过UDP从笔记本电脑那里收回输入,但我无法武装电动机并控制电机,请指导我,如何使用ESP8266(WEMOS D1 MINI)控制其速度,我也使用了Wemos_d1_mini中的D5和D6 PIN,所以请让我知道我可以使用哪些其他引脚。

#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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

这个俗人 2025-02-03 04:55:47

该解决方案对我来说很好,最后我想出了这一点,似乎很容易,您只需要发送最小的油门等待2秒钟,然后发送最大油门(Pulse)即可。 Boom ESC现在已经校准。

#include <Servo.h>
// ------------------------------------------------------------------------
// Customize here pulse lengths as needed
#define MIN_PULSE_LENGTH 1000 // Minimum pulse length in µs
#define MAX_PULSE_LENGTH 2000 // Maximum pulse length in µs
// ---------------------------------------------------------------------------
Servo mot;
char data;
// ---------------------------------------------------------------------------

/**
 * Initialisation routine
 */
void setup() {
    Serial.begin(9600);
    mot.attach(D5, MIN_PULSE_LENGTH, MAX_PULSE_LENGTH);
    delay(5000);
    //-------------------------------------
    Serial.println("Sending minimum throttle");
    mot.writeMicroseconds(MIN_PULSE_LENGTH);
    delay(2500);
    //-------------------------------------
    Serial.println("Sending maximum throttle");
    mot.writeMicroseconds(MAX_PULSE_LENGTH);
    //-------------------------------------
}
void loop()
{
  test();
}
void test()
{
    for (int i = MIN_PULSE_LENGTH; i <= MAX_PULSE_LENGTH; i += 5) {
        Serial.print("Pulse length = ");
        Serial.println(i);
        
        mot.writeMicroseconds(i);

        
        delay(200);
    }

    Serial.println("STOP");
    mot.writeMicroseconds(MIN_PULSE_LENGTH);
}

This solution works fine for me, at last i figured it out, seems it was very easy, you just need to send the min throttle wait for 2 seconds and then send the max throttle (pulse); boom ESC is calibrated now.

#include <Servo.h>
// ------------------------------------------------------------------------
// Customize here pulse lengths as needed
#define MIN_PULSE_LENGTH 1000 // Minimum pulse length in µs
#define MAX_PULSE_LENGTH 2000 // Maximum pulse length in µs
// ---------------------------------------------------------------------------
Servo mot;
char data;
// ---------------------------------------------------------------------------

/**
 * Initialisation routine
 */
void setup() {
    Serial.begin(9600);
    mot.attach(D5, MIN_PULSE_LENGTH, MAX_PULSE_LENGTH);
    delay(5000);
    //-------------------------------------
    Serial.println("Sending minimum throttle");
    mot.writeMicroseconds(MIN_PULSE_LENGTH);
    delay(2500);
    //-------------------------------------
    Serial.println("Sending maximum throttle");
    mot.writeMicroseconds(MAX_PULSE_LENGTH);
    //-------------------------------------
}
void loop()
{
  test();
}
void test()
{
    for (int i = MIN_PULSE_LENGTH; i <= MAX_PULSE_LENGTH; i += 5) {
        Serial.print("Pulse length = ");
        Serial.println(i);
        
        mot.writeMicroseconds(i);

        
        delay(200);
    }

    Serial.println("STOP");
    mot.writeMicroseconds(MIN_PULSE_LENGTH);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文