This guide covers the use of the Makerverse 2 Channel Motor Driver to control small DC motors and bipolar stepper motors from a microcontroller. Code examples are provided for the Raspberry Pi Pico, but the concepts can be easily applied to other microcontrollers such as the Arduino family or Micro:bit.

Transcript

G'day and welcome to the guide video for the Makerverse 2-channel motor driver. In this video, we're going to learn how to drive small DC motors and stepper motors with this module and MicroPython. Let's get started.

Out of the box, the Makerverse motor driver doesn't come with a screw terminal or header soldered to it. So in order to make connections easy, you can put a screw terminal and a screw header yourself. Or if you don't have these things around, you can also solder directly to the module.

Let's have a quick look at all the pins that are on the motor driver module. On the left hand side, we have direction and PWMA and direction and PWMB. The direction pin allows a microcontroller to control the polarity of the voltage that's driving the motor, in turn, driving it forwards or backwards. The PWM pins are pulse width modulation pins. These effectively allow a microcontroller to control the speed of the motor that's being driven. We also have a VM and a ground. This is a voltage input for the motor and a ground pin. Please note that the VM pin on the left is really only suited to about 1 amp total load.

On the right hand side, I've installed a screw terminal on this module. We have the channel B outputs on the top, the channel A outputs in the middle, and a screw terminal input for bulk power for the motors on the bottom two pins.

Let's do all of the wiring required to drive a single small DC motor. In this example, we're going to use a 4 AA battery pack to provide the power for our motor. Making sure that the battery pack is switched off, we're going to connect it to the VM and ground pins on the right hand side screw terminal.

With those two connections made, let's connect our motor. We're going to connect this to the A channel. You might be wondering what polarity you need to connect the motor to the motor driver. InAt Core Electronics, we believe in providing the best guidance to our customers for their DIY/maker electronics projects. Today we will be discussing how to connect a motor driver to a Raspberry Pi Pico. Firstly, we recommend to connect the motor wires to the A pins in one polarity, and if it does not spin in the right direction, swap them over. Once connected to the motor driver, it is time to connect the microcontroller. To get started, we will connect the ground connection from the Pico to the GND pin on the motor driver. Next, we connect the PWMA and DIR-A pins from GP0 and GP1 on the Pico respectively.

Now that we have the connection done, we can move forward with the programming part. We suggest heading over to the part of the guide that talks about downloading MicroPython modules. Once downloaded, load it onto your Raspberry Pi Pico with Thonny.

Following this, we can move to the first example outlined in the guide, which is basic enough and starts the motor spinning to ensure everything is wired up correctly. We can copy the code into Thonny, save it as 'main.py', and then run it by pressing Control-R. Before running the code, remember to turn the battery pack on.

As there is no command in the sample code to stop the motor, we will need to manually stop the motor using "my.stop" command. For a slightly more advanced example, we can find the next example in the guide that uses the drive method. This is a way of controlling both the speed and duration of the motor while it is running. We will use Control-C to copy it and paste it back into Thonny. Finally, we will run the code again by pressing Control-R and watch as the motor rotates again.

At the end of the day, we recommend experimenting and practicing! Feel free to contact us at Core Electronics for any further assistance or guidance on your next DIY/maker electronics project.You'll see that the motor runs for one second and then stops. We can control how long the motor runs for by adjusting the second argument. Let's say we only want to run for half a second. We'll change this argument here to 500 because this is a duration of drive in milliseconds.

Pressing Control-R again, we'll see the motor drive for half a second and then automatically stop. Moving on to the last example, here we have a loop that slowly ramps up the speed from minus 100 to positive 100. What this does is start off at full reverse, the negative numbers in the speed imply a reverse direction, then slows down to zero, and then speeds up again in the opposite direction up to full forward.

Again, we'll copy that example out of the guide, paste it into Thonny, and press Control-R. A stop command at the end of the code is what makes it stop once the example is finished running.

We're going to move on to driving bipolar stepper motors with the Makerverse 2-channel motor driver. We'll start by unscrewing the terminal block to remove our small DC motor and wiring in the DC stepper motor. To do this, we take the two phases of the stepper motor, the two coils, plug one into channel A and the other into channel B. If you don't know what polarity to use, just pick one at random and if it spins the wrong way, swap the polarity on one of the coils, and this will reverse the direction of the stepper motor.

With our two stepper motor coils wired up to the channels A and B on the motor driver, let's get the extra wiring on the Pico. All we need to do is add a PWM and direction signal from the Pico onto channel B on the motor driver. By default, the PWM B logic signal comes from GP2 on the Raspberry Pi Pico, and the DIR B comes from GP3.

With all the connections made, we can switch our battery pack back on, and then go to the guide and copy and paste the example code into Thonny. Once we do this, we can press Control-R to see the stepper motor move.Paste the stepper motor example code. This example covers a couple of crucial methods in the stepper motor class.

The first one is a rotate method. This can either take a single integer argument, which will rotate a certain number of steps or it can take a floating-point angle keyword argument, which will rotate the stepper motor a given angle. In order to make these two methods work, the constructor for the stepper motor class needs to take both an RPM to specify how fast the stepper motor can rotate and a steps per rotation so it can calculate the angle difference from one step to the next.

Pressing CTRL R will see the stepper motor rotate 50 steps in one direction, then 180-degrees in the other direction, before returning to where it started when we started the code. 50 steps forward, 180-degrees in reverse, and returning back to the start position.

We hope that this video has given you some cool ideas for your projects. If you make something cool or you have a question, leave a comment on the article for this video.

Comments


Loading...
Feedback

Please continue if you would like to leave feedback for any of these topics:

  • Website features/issues
  • Content errors/improvements
  • Missing products/categories
  • Product assignments to categories
  • Search results relevance

For all other inquiries (orders status, stock levels, etc), please contact our support team for quick assistance.

Note: click continue and a draft email will be opened to edit. If you don't have an email client on your device, then send a message via the chat icon on the bottom left of our website.

Makers love reviews as much as you do, please follow this link to review the products you have purchased.