Drive 4 motors from Explorer pHat?


#1

I’ve seen an Explorer pHat driving 4 motors in a Bilge Tank video but I’m having mixed results.
I have this https://www.adafruit.com/product/2939 Mini Rover chassis with 4 of these DC Motor in Micro Servo Body https://www.adafruit.com/product/2941. While testing my code I powered it all with a 5V 2A power supply plugged into the Pi Zero. Some times they all run some times not? One side seems to stall quit often. With a little nudge they spin. But then sometimes run slower than the other side. With just 2 motors it seems to work fine. as near as I can tell anyway. Just don’t like having to use that stupid caster. Its tippy with the caster in place of the front wheels.
Anybody else trying something similar?


#2

We use these:

It looks like the DC motors you use have a free running current of 120mA at 6v, compared to a maximum of 90mA with our micro metal gearmotors. This might suggest that two of them paired into each channel of the Explorer pHAT might exceed the motor driver current limit of 200mA per channel.

IIRC the H-bridge motor driver has an overcurrent cut-off which could certainly explain some of the problems you’re having.

You might have some luck driving two wheels from the ULN2003A and sourcing +5v, but unfortunately that would only give you a single direction.

You could also get creative with an additional off-the-shelf motor driver, example:

But there are cheaper ones available like the ubiquitous SN7544 -

Not exactly a graceful solution, though, given Explorer pHAT lacks a breadboard for expansion.


#3

I had a feeling it may be a result of the type of motors I’m using. Seemed like a good idea at the time. Back to the drawing board. Replace motors or replace driver controller board. Hmm. Not sure those motors will work in my chassis. Anyway, thanks for the quick replay, I’ll figure something out at some point. It’s usable with just the two motors, indoors, on a flat surface. Not so good on my rug though. All this stuff is a learning process. I’ll have two rover’s by the time I’m done, lol.


#4

Tried to get sneaky fancy and free wheel two of the wheels. My plan was 4 wheels but 2 wheel drive. It went forward and back Ok, just wouldn’t turn. I pulled the motors and a couple of gears out of two gear motors. Only had to remove 4 screws to do it, no cutting etc. The pivot point shifted to the back axel from the center where it was with 4 wheel drive. It’s trying to drag the font wheels sideways. Just a heads up for any body else thinging along the same lines, ain’t going to work. =(


#5

Yeah that will give you a fair bit of friction since free-wheeling wheels will result in the pivot-point of oyur robot being between the two wheels that are driven.

What happens if you alternate the wheels, like so:

  []- M   -[]
   |       |
  []-    M-[]

That would, in theory, bring the pivot point of the robot closer to its true centre. Although I suspect it might have trouble driving in a straight line, and may still have issues with steering.


#6

Exactly. Wasn’t obvious when I thought it up in my brain. Painfully obvious in practice thoughl. My first time building something like this. I put the caster back in and its usable now. My dog and cat aren’t sure what to make of it, lol.


#7

@gadgetoid Looking at your gear motors, one wonders why the gears are exposed? I’m thinking even indoors lint and pet hair will get in there? They are greased right? The ones I have are all enclosed, gears motor, all of it. Plastic gears though, or Teflon maybe. I like that yours are all metal, just a bit nervous about them being out in the open. I plan on taking my rover outside. Any plans to make covers for the gear end? I like the nice beefy keyed axels too. Mine are plastic friction fit with one little screw to hold the wheel on. Seemed like a good idea at the time, not so much now though. I ask because I’m leaning heavily to buying this kit, https://shop.pimoroni.com/products/coretec-tiny-4wd-robot-rover


#8

Think I might have found what I’m looking for, https://shop.pimoroni.com/products/micro-gearmotor-enclosure
If there is enough room to use them with the kit I linked too above, and they are what I think they are? Can you confirm one or the other? ;)


#9

There is also a white bracket shown here, https://shop.pimoroni.com/products/optical-encoder-pair-kit-for-micro-metal-gearmotors-3-3v but I can’t find it listed anywhere?


#10

The gears are quite exposed, and can definitely pick up lint. We only have our black enclosure though, and not the white one that better covers them: https://shop.pimoroni.com/products/pimoroni-gearmotor-bracket-pair

This is actually the first time I’ve seen the full enclosure- I wonder if it works with our jumper backplates.


#11

Me again, one last question, can you tell me which motors are used in that rover kit? 20:1?
I think I have a plan to save my current rover. My plan is to get four of those motors, four wheels, and four of those enclosures I linked too above. Going by the posted dimensions they will fit my current chassis. I may have to drill a few mounting holes but that’s no big deal. It’s cheaper to just replace my motors and wheels than start all over. I don’t need another explorer pHat or the solderless breadboard that’s in the other kit. I’d put them to use, just would rather buy some other stuff I don’t have. ;)


#12

I’ll enquire about the Coretec kit motor ratio.

I have a motor on my desk that I’ve mummified in electrical tape. I’m going to solder on some wires and see how it runs. I’m pretty sure just wrapping tape around the gearbox- avoiding squashing it into the gears- would provide an effective barrier against dust/fluff ingress. I wish I’d thought of this before, though :D


#13

The Coretec kit motors are 50:1 I’m told.


#14

The ones I have now are •No load speed: 110RPM (4.8v) / 130RPM (6v) with 60mm wheels.
I’m leaning towards the 50:1 420 rpm motors, and the 47mm moon buggy wheels. I like the looks of the black ones but 42 mm may be too small for my setup. Trying to pay attention to the specs this time around so I get it right. ;)
Tape may work, I’ll probably just get the covers and then not have to keep checking things. ;) No worrying about wet grass etc mucking things up.


#15

Ordered 4 of the 50:1 motors, 4 moon buggy wheels (2 sets of 2), and 4 of the motor covers. And a few other odds and ends. Hopefully everything works as planed this time around. I’ll reuse the chassis I have now. I may have to drill some holes in it etc but that’s no big deal. I’ve already done some of that to it.


#16

@gadgetoid
Can’t see how to delete a post? Was going remove all the side topic on the free component kit. Looks like I screwed up. Page was set to show in CAD dollars not GBP so my order was actually 74.71 GBP. So I’m guessing I missed the free kit by 29 cents. And that’s why it wasn’t listed in my order. My bad sorry. You can delete this post after you read it. Insert embarrassed smiley here, =(


#17

Looks like your order is tagged with “Free SideKick Component Kit!” anyway, so you might find there’s one tucked in there when your order arrives.


#18

Ok, I’ll let you know when it arrives. That will be neat if it was included. The tracking just says on its way to Montreal Canada. It won’t update until I actually sign for it, lol. Should be here end of this week or early next week. Usually takes 10+ days or so. It will be fun to get back tinkering. Haven’t done a whole lot of Pi related stuff lately.


#19

Just got my stuff, Sidekick Components Pack was in the box. You guys and gals rock. =) The small solderless bread board is just right for use with my Micro Bit breakout board. Most of what’s in there will likely be used with my Micro Bit. Can’t wait to play with the servo. =)


#20

I having very disappointing results with the new motors. It runs forward and back ok but will not turn. If its stopped and I do turn, one side forward and the other in reverse it just buzzes and doesn’t move. If I pick it up off of the floor the motors turn as they should. They stall very easily with just light finger pressure though.

While moving I set it to reduce one side to 90% speed to do a gentle turn. It turns right but hardly ever left. I think I may have an issue with my explorer pHat?

My original code was as follows.

import os
import usb.core
import usb.util
import explorerhat
import time
import RPi.GPIO as GPIO


GPIO.setmode(GPIO.BCM)  
GPIO.setwarnings(False)
GPIO.setup(27, GPIO.IN, pull_up_down = GPIO.PUD_UP)  

x=(2) #shutdown variable
S=(60) #speed default value.
M=(0) # 0 = Not moving, 1 = Moving Forward, 2 = Moving Backward,



USB_VENDOR  = 0x1997 # Rii
USB_PRODUCT = 0x2433 # Mini Wireless Keyboard

USB_IF      = 0 # Interface
USB_TIMEOUT = 5 # Timeout in MS

BTN_LEFT  = 80 # <
BTN_RIGHT = 79 # >
BTN_DOWN  = 81 # V
BTN_UP    = 82 # ^
BTN_STOP  = 44 # Space
BTN_EXIT  = 41 # ESC
BTN_OK    = 40 # OK
BTN_ONE   = 30 # 1
BTN_TWO   = 31 # 2
BTN_THREE = 32 # 3
BTN_FOUR  = 33 # 4
BTN_FIVE  = 34 # 5
BTN_SIX   = 35 # 6
BTN_SEVEN = 36 # 7
BTN_EIGHT = 37 # 8
BTN_NINE  = 38 # 9
BTN_ZERO  = 39 # 0

dev = usb.core.find(idVendor=USB_VENDOR, idProduct=USB_PRODUCT)
endpoint = dev[0][(0,0)][0]

if dev.is_kernel_driver_active(USB_IF) is True:
  dev.detach_kernel_driver(USB_IF)

usb.util.claim_interface(dev, USB_IF)

def Shutdown(channel):  
    global x
    x = (0)


GPIO.add_event_detect(27, GPIO.FALLING, callback = Shutdown, bouncetime = 2000)

while True:
    control = None
    try:
        control = dev.read(endpoint.bEndpointAddress, endpoint.wMaxPacketSize, USB_TIMEOUT)
        print(control)
    except:
        pass

    if control != None:
        if BTN_ONE in control:
          S = (10)

        if BTN_TWO in control:
          S = (20)

        if BTN_THREE in control:
          S = (30)

        if BTN_FOUR in control:
          S = (40)

        if BTN_FIVE in control:
          S = (50)
            
        if BTN_SIX in control:
          S = (60)

        if BTN_SEVEN in control:
          S = (70)

        if BTN_EIGHT in control:
          S = (80)

        if BTN_NINE in control:
          S = (90) 

        if BTN_ZERO in control:
          S = (100)

        if BTN_DOWN in control and M != 1: # Go into reverse if not moving forward, and stop turning if turning.
            explorerhat.motor.backwards(S)
            M = 2
            
        if BTN_UP in control and M != 2: # Go into forward if not moving in reverse, and stop turning if turning.
            explorerhat.motor.forwards(S)
            M = 1
            
        if BTN_LEFT in control and M == 0: # Turn left while stoped
            explorerhat.motor.two.forwards(50)
            explorerhat.motor.one.backwards(50)
            
        if BTN_RIGHT in control and M == 0: # Turn right while stoped
            explorerhat.motor.two.backwards(50)
            explorerhat.motor.one.forwards(50)
            
        if BTN_LEFT in control and M == 1: # Turn left while moving forwards
            explorerhat.motor.two.forwards(S)
            explorerhat.motor.one.forwards(S/2)
            
        if BTN_RIGHT in control and M == 1: # Turn right while moving forwards
            explorerhat.motor.two.forwards(S/2)
            explorerhat.motor.one.forwards(S)
            
        if BTN_LEFT in control and M == 2: # Turn left while moving backwards
            explorerhat.motor.two.backwards(S)
            explorerhat.motor.one.backwards(S/2)
            
        if BTN_RIGHT in control and M == 2: # Turn right while moving backwards
            explorerhat.motor.two.backwards(S/2)
            explorerhat.motor.one.backwards(S)
            
        if BTN_OK in control: # Stop moving and stop turning 
            explorerhat.motor.stop()
            M = 0
            
        if BTN_EXIT in control:
            raise SystemExit

    time.sleep(0.02)

    if x == 0:
        os.system("sudo shutdown now -P")
    elif x == 1:
        raise SystemExit

This worked fine with just the two original motors and the caster. Adding two more of the same motors caused the issues in my first post. Switching to the other motors hasn’t made any difference that I can tell. I even revised my code to this:

import os
import usb.core
import usb.util
import explorerhat
import time
import RPi.GPIO as GPIO


GPIO.setmode(GPIO.BCM)  
GPIO.setwarnings(False)
GPIO.setup(27, GPIO.IN, pull_up_down = GPIO.PUD_UP)  

x=(2) #shutdown variable
M=(0) # 0 = Not moving, 1 = Moving Forward, 2 = Moving Backward,

USB_VENDOR  = 0x1997 # Rii
USB_PRODUCT = 0x2433 # Mini Wireless Keyboard

USB_IF      = 0 # Interface
USB_TIMEOUT = 5 # Timeout in MS

BTN_LEFT  = 80 # <
BTN_RIGHT = 79 # >
BTN_DOWN  = 81 # V
BTN_UP    = 82 # ^
BTN_STOP  = 44 # Space
BTN_EXIT  = 41 # ESC
BTN_OK    = 40 # OK

dev = usb.core.find(idVendor=USB_VENDOR, idProduct=USB_PRODUCT)
endpoint = dev[0][(0,0)][0]

if dev.is_kernel_driver_active(USB_IF) is True:
  dev.detach_kernel_driver(USB_IF)

usb.util.claim_interface(dev, USB_IF)

def Shutdown(channel):  
    global x
    x = (0)


GPIO.add_event_detect(27, GPIO.FALLING, callback = Shutdown, bouncetime = 2000)

while True:
    control = None
    try:
        control = dev.read(endpoint.bEndpointAddress, endpoint.wMaxPacketSize, USB_TIMEOUT)
        print(control)
    except:
        pass

    if control != None:
        if BTN_DOWN in control and M != 1: # Go into reverse if not moving forward, and stop turning if turning.
            explorerhat.motor.backwards(100)
            M = 2
            
        if BTN_UP in control and M != 2: # Go into forward if not moving in reverse, and stop turning if turning.
            explorerhat.motor.forwards(100)
            M = 1
            
        if BTN_LEFT in control and M == 0: # Turn left while stoped
            explorerhat.motor.two.forwards(100)
            explorerhat.motor.one.backwards(100)
            
        if BTN_RIGHT in control and M == 0: # Turn right while stoped
            explorerhat.motor.two.backwards(100)
            explorerhat.motor.one.forwards(100)
            
        if BTN_LEFT in control and M == 1: # Turn left while moving forwards
            explorerhat.motor.two.forwards(100)
            explorerhat.motor.one.forwards(85)
            
        if BTN_RIGHT in control and M == 1: # Turn right while moving forwards
            explorerhat.motor.two.forwards(85)
            explorerhat.motor.one.forwards(100)
            
        if BTN_LEFT in control and M == 2: # Turn left while moving backwards
            explorerhat.motor.two.backwards(100)
            explorerhat.motor.one.backwards(85)
            
        if BTN_RIGHT in control and M == 2: # Turn right while moving backwards
            explorerhat.motor.two.backwards(85)
            explorerhat.motor.one.backwards(100)
            
        if BTN_OK in control: # Stop moving and stop turning 
            explorerhat.motor.stop()
            M = 0
            
        if BTN_EXIT in control:
            raise SystemExit

    time.sleep(0.02)

    if x == 0:
        os.system("sudo shutdown now -P")
    elif x == 1:
        raise SystemExit

I set the speed to max and took out the adjusting it part. Hasn’t helped. I’m using a powerboost 1000c with a 6600 MAH battery to run everything. To disconnect two motors I will have to cut some wires, I soldered them together with out any headers, other than on the Explorer pHat. Not sure what to do now?