Controlling H-Bridge Motors

Dev Version Only

Previously in ScratchGPIO, support for H-Bridge (bi-directional ) motors was confined to specific robot controller addon boards from the likes of Simon Monk, 4Tronix, Hap-Pi, RyanTECK etc

However, one user specifically needed to control a 3rd motor using a PiRoCon board so I’ve added in generic control

This is alpha stuff

Current syntax is to create a variable called MotorHxx,yy

xx and yy are the pin numbers used to connect your Pi to your H-Bridge controller

You can then set the variable to values between -100 to 100 to control its speed and direction

When using this facility – your can’t use the AddOn variable as well (at the moment) so you’d need to find out what pins are used to control what facilities on your exisiting robot controller boards

You may also like...

7 Responses

  1. Stewart Dunn says:

    Simon this has to be the way to go to make life easier for all involved.

    This will avoid the need for special versions for specific add-ons /hats.

    Ideally I would like a H bridge version for robot steering + extra dc motor drive + ability to control servo

  2. Jon says:

    Hi Simon, Great addition – can you double check the syntax please. Set variable “MotorH11,12” to 100 but nothing happens. I then tested it by broadcasting pin11high and then pin12high and that got the motor working. Tested the jumper leads and get no voltage using the variable MotorH11,12 approach. Cheers, Jon

  3. poctob says:

    One way that I got TI SN754410 H bridge working with ScratchGPIO is to simply use 4 PWM outputs to drive motors. I have Pins 11 and 12 for one motor, Pins 15 and 16 for the other, with corresponding variables Motor11, Motor12, Motor15 and Motor16. Setting Motor11 and Motor15 from 0 to 100 will drive forward. Setting Motor12 and Motor16 from 0 to 100 will drive back. You will need to have a variable tracking direction if you want turning while driving backward. This is a simple, out of the box solution, without a need for any add-on boards, it only uses 4 GPIO pins and leaves plenty more for extra motors, LEDs, buzzers, or whatever. I’ll drop a wiring diagram and sample code at yep.xpresstek.net in the next couple days.

    Enjoy

    • cymplecy says:

      That’s basically what the new syntax is for – so you can specify which two pins need controlling.
      So instead of using motor11 and motor12 variables – you can just use a motorh11,12 variable and alter it from -100 to 100 to control the motor

      Its only in the dev version at the moment and the syntax may change depending on what people think
      http://simplesi.net/controlling-h-bridge-motors/

  4. Alan says:

    I am new to scratch GPIO, but not to any of the other technologies involved here.

    I have a Pi3 and up to date rasbian including stock scratch with built in GPIO support, I have a Pimoroni ExplorerHAT attached. The stock scratch knows about this HAT and it all works as far as it goes.

    I also have installed version 8.1.01 of your ScratchGPIO handler because I would like to use the server and sonar support it includes as well as the H bridge. Unfortunately I am failing to understand how to make it work.

    I am trying Motor19,20 and Motor21,26 as these are the GPIO pins the ExplorerHAT has it H Bridge chip. (DRV8833). If I fall back to the Stock scratch syntax gpio19on gpio20on then my motor spins as expected.

    I can see from netstat that stock scratch connects to pigpiod and to your python layer. I presume that the later since it runs as root talks to the kernel drivers directly. I can connect to scratch to with nc and see the messages its sending. I am running your code in a root terminal so I can see its output and its getting all the message. I don’t understand the implications of having both your code and pigpiod running at the same time, I can hardly imagine that this is going to be good. I have had a go a killing of pigpiod and starting stock scratch without that, it complains and does but I still don’t get any joy with the motor commands.

    What would be the best way to setup scratch so that ScratchGPIO works given my starting point is up to date rasbian?

    The other thing is that the pigpoid supports software PWM on any pin it’s not immediately obvious if yours does that or if it’s only the hardware pwm that is supported. That may matter using the ExplorerHAT as connects the H Bridges to 19,12 & 21,26.

    My other challenge with the Explorer HAT is that it inverts its outputs by using a ULN2003A, I have seen your library has the ability to invert a pin but would that also work in conjunction with servos erc?

    Many thanks
    Alan

Leave a Reply

Your email address will not be published. Required fields are marked *