Hello, I bought a Pololu motor controller about 10 years ago. It was working fine with Arduino Mega 2560 and UNO. However, even the sample program does not work on Arduino Nano ESP32. They just said they don’t see any reason that it does not work. Are there any good motor controller boards that are fully compatible with ESP32 and its variants such as the ESP32-S3, have sample Arduino C++ code and can offer about 4-5A? If possible, smaller size is desirable.
It's not clear here, if your problem is code that is not compatible (out of the box) or driver that is not compatible with 3.3V logic signals (without level shifter).
If you post your code and the driver you have, someone can have a look...
Sorry, what do you mean by driver? Software or hardware? I don’t use any level shifter.
For the connections, I used:
Digital 2 - M1INA
Digital 4 - M1INB
Digital 6 - MIEN/DIAG
Digital 9 - MIPWN
3.3V - VDD
GND - GND
Please note that on the product page, there is no mention about connecting 3.3V from an ESP32 board to VDD on the motor controller board in the pin mapping table but a youtuber said that this has to be done to make it works.
youtoober is wrong
Pololu is your very best source of information about Pololu products.
I looked at your thread on the Pololu forum, and noticed that you failed to address the issues that one of their professionals raised. It would be wise to continue on that thread.
However, the default pin assignments in the demo program from our library do not match the pin assignments you used in the code from your second post (not sure why you deleted that), so double checking your connections still seems like the best starting point. Along with pictures, can you post what the demo program reports through the Arduino Serial Monitor when you run it?
try with some generic code:
const int INA = 2;
const int INB = 4;
const int PWM = 9;
const int PWM_CHANNEL = 0;
const int PWM_FREQ = 20000;
const int PWM_RES = 8;
void setup() {
pinMode(INA, OUTPUT);
pinMode(INB, OUTPUT);
ledcSetup(PWM_CHANNEL, PWM_FREQ, PWM_RES);
ledcAttachPin(PWM, PWM_CHANNEL);
}
void loop() {
// Forward at half speed
digitalWrite(INA, HIGH);
digitalWrite(INB, LOW);
ledcWrite(PWM_CHANNEL, 128);
delay(5000);
// Reverse
digitalWrite(INA, LOW);
digitalWrite(INB, HIGH);
ledcWrite(PWM_CHANNEL, 128);
delay(5000);
}
leave the enable pin disconnected, it should be pulled up on the driver.
What is your motor's voltage rating? What is it's full load current rating? What is it's stall current rating? What is your power supply's voltage and current rating?
I tried your code on Nano EPS32 but it gave:
/private/var/folders/73/5jp6cqrx3bs6yfqq73b5nr9m0000gn/T/.arduinoIDE-unsaved2025112-1584-uzmhdt.2o1rm/sketch_dec2a/sketch_dec2a.ino: In function 'void setup()':
/private/var/folders/73/5jp6cqrx3bs6yfqq73b5nr9m0000gn/T/.arduinoIDE-unsaved2025112-1584-uzmhdt.2o1rm/sketch_dec2a/sketch_dec2a.ino:12:3: error: 'ledcSetup' was not declared in this scope
12 | ledcSetup(PWM_CHANNEL, PWM_FREQ, PWM_RES);
| ^~~~~~~~~
/private/var/folders/73/5jp6cqrx3bs6yfqq73b5nr9m0000gn/T/.arduinoIDE-unsaved2025112-1584-uzmhdt.2o1rm/sketch_dec2a/sketch_dec2a.ino:13:3: error: 'ledcAttachPin' was not declared in this scope; did you mean 'ledcAttach'?
13 | ledcAttachPin(PWM, PWM_CHANNEL);
| ^~~~~~~~~~~~~
| ledcAttach
exit status 1
Compilation error: 'ledcSetup' was not declared in this scope
Don't ask me what I think about Nano Esp32...
Try arduino style instead:
const int INA = 2;
const int INB = 4;
const int PWM = 9;
void setup() {
pinMode(INA, OUTPUT);
pinMode(INB, OUTPUT);
}
void loop() {
// Forward half speed
digitalWrite(INA, HIGH);
digitalWrite(INB, LOW);
analogWrite(PWM, 128);
delay(5000);
// Reverse half speed
digitalWrite(INA, LOW);
digitalWrite(INB, HIGH);
analogWrite(PWM, 128);
delay(5000);
}
Thanks. Which parameter contols the speed? If I want 1/10 of what it does, I should use analogWrite(PWM, 128/10)? Also, what does delay(5000) do? Keep turning for 5000 msec before reversing the direction?
I posted the code just to verify if your setup is working.
1/10 speed would be 256/10. Delay does what you expected.
Thanks. I just tried your code and it made the motor turned ![]()
I modified it slightly as following:
void loop() {
// Forward half speed
digitalWrite(INA, HIGH);
digitalWrite(INB, LOW);
analogWrite(PWM, 128);
delay(1000);
// Reverse half speed
digitalWrite(INA, LOW);
digitalWrite(INB, HIGH);
analogWrite(PWM, 25.6);
delay(1000);
How come sometimes the motor reverses the direction but sometimes it doesn’t?
don't use decimals.
OK. Thanks
If in the loop I only have this:
digitalWrite(INA, HIGH);
digitalWrite(INB, LOW);
analogWrite(PWM, 1);
It turns clockwise very slowly like the way I want it to be but if I use my fingers to impede the turning, it stops turning at all. It does not start to turn again even my fingers are away from it. I have to use my fingers to turn it clockwise (kind of helping it) before it can turn by itself again. Why it is behaving it that way? I also want it to be able to maintain the high torque even turning at very slow speed. How to do that?
I'm not following you right now.
Do you mean that the hardware setup that works as desired with Uno, doesn't have torque enough with nano esp32 setup?
I don’t use the UNO. When I used it with this controller about 10 years ago, I only worked on high speed turning. It jus worked.
Now, I am working on slow speed turning (with high torque) and only use the Pololu board with the Nano ESP32. I am trying to understand your program by modifying some parameters. What I noticed is that even I used analogWrite(PWM, 0), it still turns like I were using analogWrite(PWM, 1); How come? Shouldn’t 0 means no turnng?
It should. But with nano esp32 I'm not sure about anything.
Try how it behaves with this line added to setup:
analogWriteFrequency(PWM, 20000);
Ps. If you happen to have regular Esp32 board try with that.
It gave:
Compilation error: too many arguments to function 'void analogWriteFrequency(uint32_t)'
If I use analogWriteFrequency(20000); instead:
digitalWrite(INA, HIGH);
digitalWrite(INB, LOW);
analogWrite(PWM, 0);
No turning. I can easily turn it in one direction (nothing to impede my turning) but when I turn it in another direction, there is a high torque to impede my turning. I can still turn it if I use larger force. Not so difficult. If I change the last statement to
analogWrite(PWM, 1);, I need to apply a large force to turn the motor in either direction
What do you mean by regular ESP32 board? Mine is the official Arduino Nano ESP32.
I mean that common Esp32 is well supported and documented board.
Arduino nano esp32 is not so. I'm having great difficulties to deal with that like you see.
Someone else used to deal with it could give better support.
In any case, I don't see a reason your driver board would not work with esp32.
What common ESP32 product do you recommend?
Since I am using the nano, the VNH5019 taken from an old project looks very big. I also want to get a smaller driver board. If I want a smaller one that can control the motor speed and perhaps also torque (turning very slowly but also keep the high torque), can provide about 4Amp, what products do you recommend?