Pololu Robotics & Electronics
Menu
My account Comments or questions? About Pololu Contact Ordering information Distributors

Pololu Forum

DRV8838 + ESP01 + DC Motor

Hi Pololu Team,

I replied on another person’s forum post (Drv8838 + esp8266) however it is a year later reply so I am unsure if the notification is being received by team. Anyhow, I appreciate your responses to everyone’s postings in the forum. My situation is I am using the ESP01 as my MCU and following the DRV8838 diagram to wire my project (pictures included). However, I’m having trouble programming the ESP01 to control the DRV8838 and ultimately the DC motor. Am I missing something or do I need to change my pin connections? Currently in my code, I have enablePin set to 2 and phasePin set to 3. Let me know if you have any questions.

Thanks,
Aaron


Hello, Aaron.

I am sorry I missed your initial post. Specifically what behavior are you seeing when you try to run your system? Can you connect ENABLE and PHASE on the DRV8838 to VCC on your ESP-01 and tell me if the motor runs?

-Jon

1 Like

Hi Jon,

Thanks for the response. I tried to connect the Enable and Phase pins from the DRV8388 to the VCC on the ESP-01 like you suggested and our result was the same, no motor movement. I believe it is due to the code I am currently running. Does the code below look correct to you?

int enablePin = 2;
int phasePin = 3;

void setup()
{
  pinMode(enablePin, OUTPUT);
  pinMode(phasePin, OUTPUT);
}
void loop()
{ 
  
  digitalWrite(enablePin, HIGH);
  digitalWrite(phasePin, HIGH);
  delay(100);
  digitalWrite(enablePin, LOW);
  digitalWrite(phasePin, LOW);
  delay(500);
  digitalWrite(enablePin, HIGH);
  digitalWrite(phasePin, LOW);
  delay(100);
  digitalWrite(enablePin, LOW);
  digitalWrite(phasePin, LOW);
  delay(500);
}

I have included pictures of my current wiring set up. Thanks in advance for your help!

Thank you for including more high-resolution photos. Based on those pictures, it looks like your electrical connections are not good, which is almost certainly the cause of your system not working, especially since the motor does not turn when PHASE and ENABLE are connected to VCC.

There are several issues with your connections. First, most of the soldered joints on your DRV8838 do not look completely wetted. I recommend reheating those joints to look more like the ideal joints in this Adafruit guide to soldering. Second, the ends of the wires coming from your battery are frayed, which means those wire strands are not well connected to their crimp pins. I recommend replacing those connections. Third, simply inserting the ends of your crimp pins inside the hole of the tabs on your motor is not adequate enough of an electrical connection. Those connections should be soldered.

In general, I think it is also useful if you check your connections with the continuity function of a multimeter before applying power and trying to control your motor. If the multimeter shows that those connections are good, you should focus on testing with PHASE and ENABLE connected to VCC. We can work on your code after your connections are properly set up.

-Jon

Hey Jon,

Thank you for your reply. I re-wetted the joints and strengthened the wire connections as well as soldered the crimp pins to the motor. After doing this all, I have power to the motor and ESP01. When I turn on the power, the motor runs but does not stop. I am trying to use a program on my phone and the ESP via wifi to control the motor on and off. Does my code look appropriate to control the DRV?

Thanks for your help!
Aaron

int enablePin = 2;
int phasePin = 3;
// deviceId is the ID assigned to smart-home-device 
void turnOn(String deviceId) {
  if (deviceId == "5ebc95b8d13d5c20309317d7") // Device ID 
  {
    Serial.print("Turn on device id: ");
    Serial.println(deviceId);
  digitalWrite(enablePin, HIGH);
  digitalWrite(phasePin, LOW);
  }
}
void turnOff(String deviceId) {
   if (deviceId == "5ebc95b8d13d5c20309317d7") // Device ID
   {
     Serial.print("Turn off Device ID: ");
     Serial.println(deviceId);
  digitalWrite(enablePin, LOW);
  digitalWrite(phasePin, LOW);
   }
}
void setup()
{
// setup wifi
WiFi.begin(MySSID, MyWifiPassword);
// while having a wifi connection continue to output to the enable and phase pins
//while (WiFi.status() == WL_CONNECTED) {
pinMode(enablePin, OUTPUT);
pinMode(phasePin, OUTPUT);
//}  
}

I just noticed in your most recent pictures that you only had a single wire going from your ESP01 to the DRV8838. If you were trying to test the driver by connecting ENABLE and PHASE to VCC like I mentioned before, you still would have needed to have the DRV8838’s GND and VCC pins connected as well so that it had a common ground and a logic voltage. If you got the motor running, it sounds like you might have figured that out and made the proper connections already. Have you since connected the ENABLE and PHASE pins back to pins 2 and 3 on your ESP01 as your program expects? Could you post an updated picture of your connections? A wiring diagram or a list of your connections would also be helpful since it can be difficult to see which pin each wire connects to in the pictures.

I don’t see any obvious problems with your code, but it looks like you might not have posted your entire program. I do not see any calls to your turnOff() and turnOn() functions; are they in the loop() function, which you did not post?

-Jon