Hello,
I have set up a circuit very similar to the starter kit "zoetrope" except with an ESP32. The H bridge pins are connected in the same way, and I have tested the circuit with an Arduino Uno and the zoetrope example and it works. The DC motor does not spin at all when I connect it to ESP32. I tried different output pins and when I connect it to pin 2, which also communicates with the ESP32 LED, the LED turns on and off but the motor doesn't move. I first tried ledcWrite and then simplified it just to digital low/high output for the H-bridge enable pin and neither version seems to work. What could be going on here?
#include "BluetoothSerial.h"
#include <ESP32_Servo.h>
#include "esp32-hal-ledc.h"
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif
#include "Arduino.h"
BluetoothSerial SerialBT;
int controlPin1 = 4;
int controlPin2 = 19;
int enablePin = 13;
const int freq = 30000;
const int pwmChannel = 0;
const int resolution = 8;
int motorSpeed = 200;
String message = "";
char incomingChar;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
SerialBT.begin("Dora the explorer"); //Bluetooth device name
Serial.println("The device started, now you can pair it with bluetooth!");
pinMode(controlPin1, OUTPUT);
pinMode(controlPin2, OUTPUT);
pinMode(enablePin, OUTPUT);
ledcSetup(pwmChannel, freq, resolution);
ledcAttachPin(enablePin, pwmChannel);
ledcWrite(enablePin, 0);
}
void loop() {
// put your main code here, to run repeatedly:
if (Serial.available()) {
SerialBT.write(Serial.read());
}
if (SerialBT.available()) {
char incomingChar = SerialBT.read();
if (incomingChar != '\n') {
message += String(incomingChar);
}
else {
message = "";
}
Serial.setTimeout(50);
Serial.write(incomingChar);
if (message == "Go") {
digitalWrite(controlPin1, HIGH);
digitalWrite(controlPin2, LOW);
//ledcWrite(enablePin, motorSpeed);
digitalWrite(enablePin, HIGH);
}
if (message == "Back") {
digitalWrite(controlPin1, LOW);
digitalWrite(controlPin2, HIGH);
//ledcWrite(enablePin, motorSpeed);
digitalWrite(enablePin, HIGH);
}
if (message == "Stop") {
//ledcWrite(enablePin, 0);
digitalWrite(enablePin, LOW);
}
}
delay(20);
}