Does your next project need some seriously Torque-y, Fast or Powerful DC Motors? Then the goBILDA Yellow Jackets are the perfect ticket. This will demonstrate exactly how to whirl any of these Large DC Motors with a Raspberry Pi Single Board Computer. And we'll even decide the speed with a 8bitdo Pro+ Controller!

Transcript

I am controlling this large DC motor with a Bluetooth controller all through the Raspberry Pi and this is all thanks to the Pololu Motoron HAT. Hey gang, Tim here at Core Electronics and today I show you how.

A large DC motor runs at 12 plus volts and has a greater than 5 amp stall current. Our range of goBILDA Yellow Jacket DC motors perfectly fits my large DC motor criteria. Now 12 volts straight into our Raspberry Pi Single-Board Computer would break it, so we need to have an intermediate component.

The Pololu Motoron Dual High-Power Motor Controller is the perfect HAT to control two large motors just like this one through a Raspberry Pi single board computer. These motor controllers come pre-assembled, thus this is going to be a solder-free guide, and they have the form factor to perfectly fit on top of a Raspberry Pi 4 Model B. The Raspberry Pi communicates directly to the Motoron controller using I2C, so only two GPIO pins are required regardless of how many Pololu Motoron HATs you stack on.

The table before me is everything you need to create a similar DC motor control system in your megaverse. Naturally, you're going to need the Motoron motor controller. Today, we're using the goBILDA 5203 series Yellow Jacket Planetary Gear Motor. For today, we're going to use this 12 volt DC 10 amp switching power supply as it's perfect for the job. We will also require a DC Barrel Jack Adapter and some thick 16 AWG wire for the connections. We have a guide on selecting the correct AWG for your projects, check the description if you need. We will also require a flathead screwdriver to connect wires to the screw down terminals on the Motoron HAT. Finally, we're also going to need everything to run this Raspberry Pi as a desktop computer.

You're going to need to bring your favourite Bluetooth controller to control this system. Here I have mine, an 8-bit do Pro Plus controller, and I'm pairing it with an 8-bit do USB wireless adapter too. Let's begin.

First, we're going to attach the Pololu Motor on Hat to the top of the Raspberry Pi single board computer. Use the metal standoffs and screws that come with the Motor on Hat to do so. Make sure to line up the GPIO pins correctly with each other and push gently both boards together, doing so connects them securely together.

With that complete, let's turn our attention to attaching the Go Build a Motor to the Motor on Hat's M2 slot. Orient your system so it's the same as mine and attach the red wire to the furthest right blue screw down terminal. After that, connect the black wire from the DC motor to the second furthest right blue screw down terminal. Once you have done that, attach the female power jack adapter to the Pololu Motor on Hat. Make sure that the black wire goes from the ground blue screw down terminal that has GND written on it to the negative (it's got a minus symbol written on it) screw down terminal on the female power jack adapter. Then make sure that the red wire goes from the positive blue screw down terminal named BIN to the positive (the plus symbol) screw down terminal on the power jack adapter.

Continuing on, we will attach power to the motor through the Hat by attaching the 12 volt power supply to the female jack adapter. Now, ground and voltage are required for each Motor on Hat, so if you have a stack of Motor on Hats, you're going to need to connect power and ground to each unique Hat.

We will now set up our Raspberry Pi as a desktop computer. And with that done, assembly is complete. Now, the Pololu Motor on Hat requires I2C communication to work. By following these steps, you should have your system up and running in no time. connection is working correctly

The default communication method on Raspberry Pi OS is turned off, so the first step is to turn it on. To do this, open up the Raspberry Pi configuration menu found using the top left menu and scrolling over preferences, then enable the I²C connection found underneath the Interfaces tab. With your system connected to the internet, it's now time to open up a new terminal window by pressing the black button on the top left of the screen.

Jump to the written-up article, scroll down to Software Setup and locate these command lines. Now copy and paste them one by one into the terminal to get all the packages that we will need. Once completed, we have fully set up our Raspberry Pi Single-Board Computer to work with the MotorOn Hat. We also have all the packages required to control our DC motor with a Bluetooth controller.

From the main article, scroll to the Simple Code to Drive Motor section and copy and paste that script straight into the coding area of Python. Also note that you can download all these scripts direct from the guide. The link is at the very bottom of the full article. The exact script name is bigmotorcontrol.py and I'm going to save my version here exactly the same.

With that done, let's press play. Nice! So as you can see when I run this script, it causes the DC motor which is attached to the MotorOn M2 slot to start to rotate. It then goes through a series of little routines rotating at all different speeds and directions. Let's jump into the code and see the levers and mechanisms that make this work. To start, we just import the needed packages that being time and our most recently installed MotorOn package. Next, we start the I²C communication of this HAT and provide it with a variable name. Then we reinitialize the MotorOn controller just to ensure our connection is working correctly. sleep command for 4 seconds

The motor controller is running the default settings. The next two lines are just to prevent extraneous warning messages popping up when we run our Python scripts. After that, we configure the Max and Min deceleration rates for our DC attached motor. The first number value in the brackets identifies which slot we're targeting; in this case, slot number two. The second number in the bracket is the speed value; this can be any value from zero to eight hundred (eight hundred is Max acceleration). Here, I've selected 200 for acceleration and 300 for de-acceleration.

Next, here are two methods that you can use to tinker with the timeout values either to provide a timeout time for the motors or to prevent timing out altogether. Motors are going to stop rotating once this timeout value is reached if no constant rotate command is getting received. It's good to set a value here when you're testing around with the code because that prevents you having a runaway DC motor. The default value is 1.5 seconds and I have it set here to 5 seconds.

Then, I'll first rotate command you can see it right here: mc.set speed 2 to represent motor Slot 2 and 800 to represent full speed in the clockwise Direction. The second number value decides the speed at which the motor will rotate; this can be any number between negative 800 and 800. Here, I've used 800 which will rotate motor 2 at the maximum speed clockwise. Continuing on, I utilized a simple sleep function which then provides a break for 4 seconds until the next command is sent. The motor continues to spin at top speed during this break as the timeout command was set to 5 Seconds.

Progressing deeper, the next command rotates the motor attached to Slot 2 at half speed. This is because the value was set at 400; that is half the maximum value, thus half the maximum speed. Then, there is another sleep command for 4 seconds. controller now connected to the Raspberry Pi you can now run the Bluetooth controller motor control.py script

The previous Python script is great to test your hardware and to just double check that everything's assembled and performed correctly. However, it can leave the maker wanting more, particularly with regard to a remote control via Bluetooth controllers. To address this, I have created the Bluetooth controller motor control.py script to make this a reality.

Allow me to introduce the 8-Bit do Pro Plus Bluetooth controller. I set this controller to emulate as a generic Xbox controller, so my Python script is going to work without customization for any 8-bit do Pro Plus controller or generic Xbox controller. To connect your 8-bit do Bluetooth controller easily to a Raspberry Pi single board computer, I recommend using an 8-bit do wireless adapter 2 dongle. Connect this dongle to the powered up Raspberry Pi system by using one of the USB 3.0 ports.

The next step is to emulate this Pro Plus controller as an Xbox controller. Hold the start and x button together, the indicator lights on the back of it are going to start flashing two out of four. Then press the sync button on the very top and the sync button on your dongle. Hold both of these simultaneously for two seconds and then let go. Both will display a blinking LED response. Once Bluetooth connection has been established, your controller will vibrate once and the indicator bar will have one out of four of the display LEDs permanently lit.

So with your controller now connected to the Raspberry Pi, you can now run the Bluetooth controller motor control.py script. A very useful command to know is mc.coast. This command energizes all DC motors, allowing them all to freely spin. If you added a number value inside the brackets like so, you could target a particular motor slot to coast instead of all of them. The final rotation will go at quarter speed anti-clockwise as determined by the negative 200 value provided.

Bluetooth controller attached to our Raspberry Pi system, we are good to go! Jump to the article and copy and paste the Bluetooth controller motor controller.py script into funny IDE. I'm going to save it and run it just like before and just check this out: whenever I press a button, or any of the triggers, or even the joystick, we're going to get our DC motor to rotate at different speeds. Very nice: slow speed, medium speed, higher speed, here we have all the way up goes at medium speed, bring it back down, lower, high speed, high speed in reverse, faster speed.

I also have two toggles here, so if we press the select button, we've now swapped it to max speed and then our joystick will go faster. If you want to revert that, just press start. So with the script functioning like me, you'll be smooth sailing. We have a guide explicitly on using USB and Bluetooth controllers with Python, which is a great place to learn more and exactly how I'm doing this. After checking that out (link in the description), you should feel comfortable altering my script here to fit your exact project. You're going to be controlling DC motors with Bluetooth devices wherever you go!

And that is all for today folks. We are full-time makers and we are here to help, so if you have any questions feel free to pop me a message down in the comments or come to our rad for electronics Forum to really get a monster. So with that, until next time, stay close!

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.