Brenton just shared a new content in Guides > Raspberry Pi Pico: "Makerverse Motor Driver, 2 Channel - Application Guide"
Read more
Hi,
Re: Core 2 - Channel Motor Driver (CE08038)
Using the Motor drive in Phase mode (PWM) driving a Turbo gear 12 V dc motor via esp32. All works as per the truth table in doco. 2 questions:
- I need to brake the motor quickly, is this possible in PWM mode? Tried soldering IN1/IN2 link…no luck
- Is there a compatible library available for PWM use via esp32 Arduino IDE (C/C++) environment?
Braking should be possible in IN1 IN2 mode by setting both inputs to HIGH
not for this motor driver specifically, but it’s just a dual h-bridge driver for which many drivers exist online eg. use in IN1/IN2 mode and treat it just like an l293d motor driver (another dual-h-bridge driver)
Thanks for your reply. I’m still confused. I can’t get it to operate reliably.
The Motor driver is IN1/IN2 mode. The single DC motor is connected to B- and B+ terminals. VM = 12 V. Logic voltage is 3.3V. I apply a PWM signal to PWM B the motor rotates in one direction only irrespective of HIGH or LOW logic level on DIR B. Varing the duty cycle does control the speed
I’m confused as to the truth table. For example, to go in the reverse direction I need a logic 0 on the IN1 input signal, if so, where is the PWM applied? I must be missing something basic
Hi Graeme
I don’t know your specifics but a common set up with these H bridge devices is to use IN1 and IN2 for direction and apply the PWM to the enable pin. This works as long as you don’t want to start a motor creeping very slowly from standstill. There is a reason behind this which I won’t go into here but it why I am not a great fan of this system but it seems to be popular.
Cheers Bob
Thanks Bob. Yes that is logical and what i would have expect too. However, this Makerverse Motor Driver from Core doesn’t have an enable pin that I can see! Cheers
Hi @GRAEME51636
In In1/In2 mode you can do bidirectional speed control with only two pins;
-
drive the motor forward with IN1=HIGH and IN2=LOW
-
drive the motor backward with IN1=LOW and IN2=HIGH
-
drive the motor forward slowly with IN1=PWM(30%) and IN2=LOW
-
drive the motor forward slowly with IN1=LOW and IN2=PWM(30%)
I hope this clears things up, let us know how you go.
If you like, you can post your code and we can take a look
Hi Graeme
Apologise, I did not look at the product I just considered the H bridge IC.
It looks like you have a PWM connection and a DIR connection for each channel.
Looking at the schematic, PWM is indeed connected to the “enable” pin on the IC on the board. There is a “Mode” link which you can cut or bridge to change “Modes”. Perhaps someone with some experience with this module can chip in here to explain what that is all about.
Looks like Michael has already done that while I was typing but I think his last bullet item should read “backward”
I don’t know about braking though.
Cheers Bob
Hi Michael
When I mentioned “slow” above I was talking about a lot lower than 30%.
I mean “creeping” very slowly from standstill. The last time I tried this with PWM applied to the chip “enable” pin the motor would not move for a while and when it did it went to about 25% speed in a rush. Once it did that I was able to back it off to a fairly slow speed but not quite down to a crawl.
This was done some time ago and it is possible that things have improved with the internal logic, I don’t know. It is to do with how the flywheel diodes (there are effectively 2 in series) get connected across the motor. With all H bridge switches OFF one of the diodes is connected via the power supply and a diode can never be directly across the motor. If you try this with an oscilloscope connected directly across the motor (with the scope mains ground removed for safety) you can see why this happens.
I know with Mosfet switches the body diode play a part in this but with the chip disabled and all switches OFF the path is still via the power supply which effectively clamps the LOW side of the motor to + motor supply during the flyback period.
Try this. Interesting. I think I can find the scope screen shots I can email to you if you liked.
Incidentally I did do the experiment in one direction with a diode directly connected to the motor and the whole thing worked fine. I was able to creep the motor very slowly from standstill.
Cheers Bob
Hi Michael, See my code below. The motor only goes in one direction. The brake function doesn’t work as expected it coats rather than brakes. This code uses ledc, I did another version using analogWrite same issue. Must be doing something obviously wrong.
// Test Core Electronics 2 channel motor driver with a
// Turbo gears 12V 160rpm DC Motor. ESP32 micro
const int PWM_A = 18; //IN1
const int DIR_A = 26; //IN2
const int pwmAChannel = 0;
const int rangeDC = 255;
const double FREQ = 1000;
void forward(int percent){
int dutyCycle = percent / 100 * rangeDC;
Serial.print("Motor Forward Duty Cycle = ");
Serial.println(dutyCycle);
ledcDetachPin(PWM_A);
ledcDetachPin(DIR_A);
ledcAttachPin(PWM_A, pwmAChannel);
digitalWrite(DIR_A, LOW);
ledcWrite(pwmAChannel, dutyCycle);
}
void reverse(int percent){
int dutyCycle = percent / 100 * rangeDC;
Serial.print("Motor Reverse Duty Cycle = ");
Serial.println(dutyCycle);
ledcDetachPin(PWM_A);
ledcDetachPin(DIR_A);
ledcAttachPin(DIR_A, pwmAChannel);
digitalWrite(PWM_A, LOW);
ledcWrite(pwmAChannel, dutyCycle);
}
void brake(){
Serial.println("Braking");
ledcDetachPin(PWM_A);
ledcDetachPin(DIR_A);
digitalWrite(DIR_A, HIGH);
digitalWrite(PWM_A, HIGH);
ledcSetup(pwmAChannel, FREQ, 8);
}
void setup() {
Serial.begin(115200);
delay(1000);
ledcSetup(pwmAChannel, FREQ, 8);
pinMode(PWM_A, OUTPUT);
pinMode(DIR_A, OUTPUT);
}
void loop() {
forward(30);
delay(3000);
brake();
delay(1000);
reverse(30);
delay(3000);
brake();
}
Hi @GRAEME51636 - i’m going to strip this code down to simplify it. The following should deliver bidirectional control. Once we get there we can think about speed control.
This will only work if the solder jumper is soldered
const int IN1 = 18;
const int IN2 = 26;
void setup() {
Serial.begin(115200);
delay(1000);
pinMode(IN1 , OUTPUT);
pinMode(IN2, OUTPUT);
}
void loop() {
Serial.println("Forward");
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
delay(1000);
Serial.println("Reverse");
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
delay(1000);
}
Hi Michael, Thanks for your help. Using your stripped down code the motor will only go in the one direction, it doesn’t reverse. Maybe the board is damaged?
Interesting! Some pictures front+back + how it’s set up will be really helpful I think
does it go forward continuously? or does it pause for a second at a time?
In any case, if you think you’re up for a warranty discussion you can reply to your order confirmation email - our technicians will lead by asking for those photos in the first place.
Hi Michael, Not to worry. Maybe it’s faulty, maybe I have inadvertently damaged it. I’ve spent enough time on it. Oddly it works perfectly in the PWM mode, the issue is with IN1/IN2 mode.
My motor works perfectly with Pololu MP6550: and TB9051FTG
One thing I did discover in Arduino IDE (2.3.0) using analogWrite and digitalWrite alternatively on the same pin is problematic. You need to redefine the pin after each analogWrite eg pinMode(IN1, OUTPUT)
Does the Micropython Makerverse 2 Channel Motor Driver Module work with Python or just Micropython?
What module would you recommend for use with a Raspberry Pi Zero W and this motor driver if the module included in this article doesn’t work with Python?
Hi @Nicholas277711, Welcome to The Forums!!!
The Motor driver should work fine with a full Raspberry Pi such as the Pi Zero W.
It can be driven without the MicroPython Library, directly using the information from the tables provided in the guide. From what I can find the Pi Zero is limited to 2CH of PWM output but that should be fine for 2 channel operation in PWM Mode.
Thanks Aaron
Hello all. I have used these drivers before with no issue. I recently purchased an ESP32-C3 mini and have loaded the ramping example in the tutorial. I get the following error:
Traceback (most recent call last):
File “”, line 1, in
File “LED.py”, line 4, in
File “Makerverse_Motor_2ch.py”, line 31, in init
ValueError: unreachable frequency 5000
Note I do not currently have a driver connected, I am just testing the code. Is this my problem?
Cheers
Hi John, Welcome to the Forums!!!
This shouldn’t be the issue here as far as I can tell.
Have you modified the example or the Makerverse_Motor_2ch.py to have a different PWM frequency apart from the default 200?
I have now but even when I ran it as published I had the same error.