Sheldon robot: controlling the motors

Many beginners’ guides to electronics teach you how to build motor controllers using mosfets, H-bridge circuits and all that good stuff. And maybe I’ll get around to doing that one day. But to get this robot project up and rolling, I decided to go for an off-the-shelf motor controller.

I’ve used many before, including Arduino shields from Adafruit and Snootlab. For my earlier Farfel robot, I settled on the MD22 24V 5A controller from Robot Electronics. It’s easy to use, operating via an I2C interface. But damn it’s expensive, at around £50 including tax and shipping.

The first one I used stopped working, and I could never figure out why. The second was still mounted to the carcass of Farfel, which was sitting in a cupboard, gathering dust. I figured I could simply dismount it and hook it up to Sheldon. I was wrong. That too had died.

I was reluctant to drop another £50 on one of these things. In any case, finding stuff like motor controllers has become so much easier in past few years. So I did what any cheapskate electronics experimenter does in these situations – headed over to eBay and AliExpress.

The 7A dual motor controller board.

In the end I plumped for two dual controllers – a 10A model, capable of handling 30A peak and a 7A model (allegedly 50A peak). The two 9V motors in my T300 robot are going to pull a total of about 6A when stalled and much less than that in normal use, so either of these controllers should be up to the job if the specifications are to be believed. Both boards are up to handling 12V or 24V input for the motor. I’m actually running mine at 9V but I couldn’t see that that would be a problem. (Spoiler alert: it wasn’t.) What attracted me most were the prices – $13.39 and $9.87 respectively, including shipping. That’s a lot better than £50.

Neither board came with much in the way of instructions or technical data, but the connections looked simple enough.

With the 10A board, for each motor you connect one GPIO from your microcontroller to a direction pin. Setting this to high (5V) or low (0V) sets the motor direction to ‘forward’ or ‘reverse’. Those words are in quotes because such notions are a bit arbitrary with DC motors. The point is that setting which way the motor turns is very simple.

To control the speed of the motor, you connect a GPIO pin capable of pulse width modulation (PWM) output on your microcontroller to the PWM pin on the controller board. Then, in the Arduino IDE, just use analogWrite(n) with ‘n’ being a value of 0 (stopped) to 255 (full speed).

The 7A motor controller board mounted underneath the robot’s top plate.

I had this up and running in no time, and even wrote a small Arduino library for it. But then I hit a snag.

My idea was to mount the board on the underside of the robot’s top plate, just ahead of the motors. It would then be neatly tucked out of the way. But this board was too big. So on to the next one.

Smaller option

The 7A board is much smaller. It boasts opto-isolation between the logic control part of the board and the motor power part.

Like before, speed is controlled using a PWM signal. But the direction controlled is more involved. For each motor there are two digital input pins. Set one high and the other low and you get movement in one direction. Invert those settings – so the first is now low and the other high – and the motor turns the other way. If you set both to high, the board ignores you. If you set both to low, the board is in ‘brake’ mode, although as far as I can see that’s just ‘off’.

It took me a while to get this working properly – until I noticed a mistake I’d made. The pins on the Teensy 3.5 I’d used for the left motor weren’t PWM-capable. The motor would kick in only when the value I’d used in analogWrite() was sufficiently high to make the output of the pin effectively a logic 1. Moving the connections to PWM pins solved the issue.

The downside of the 7A board is that it demands six GPIO pins, against the four of the 10A board and the two I2C connections of the Robot Electronics device. Luckily, the Teensy 3.5 has lots of I/O.

The board also has one quirk. The power input for the logic section of the board is marked as +5V. However, when I first tried using it with the Teensy, nothing happened. Then I re-read the Chinglish description on the website and twigged that if you’re using 3.3V control signals – which is what the Teensy’s GPIO pins put out – then you also need to power it with 3.3V, not 5V.

And yes, I will have a go at diagnosing the problems with the Robot Electronics controllers to see if I can bring them back to life. In the meantime, Sheldon is moving about happily.

Never miss a post

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.