Raspberry Pi Endeavors 5 – Building The Car

Unfortunately both Mr.Basic 4wd chassis’ that I got had such high resistance in them, they could barely spin their own wheels, let alone drive along the floor. I got these sent back and went for a larger vehicle made from 2 pieces of acrylic and 4 motors connected directly to 4 wheels, that I picked up from ebay for about ¬£20 [from China].

clear chassis photo

I then followed Adafruit’s guide: Lesson 9. Controlling a DC Motor. This is a great guide to power one motor – to power another, just connect another 2 input wires¬†symmetrically on the other side, same with the outputs to the motor. You also must connect the PWM pin 18 to the EN2 [right hand side PWM pin on the chip] to allow the Pi to control the speed of both motors. If you wanted them to go different speeds, you would have to use software to emulate a PWM pin, and then connect that to the chip – as the Pi only has one PWM pin.

L293D Chip

Picture: Adafruit Learning System (Lesson 9 DC Motor)

I then used a Raspberry Pi Cobbler from Adafruit to gain easy access to all of the Pi’s GPIO pins on a breadboard. On the breadboard, I placed the cobbler, L293D motor chip, and connected them both up with jumper wires, adding the batteries for the motors to the positive and negative rails. [Follow Adafruit’s guide!]

Wiring diagram

Picture: Adafruit Learning System (Lesson 9 DC Motor)

So now the Pi is connected to the breadboard, on which is a motor chip that controls the motors using inputs from the GPIO pins. If your batteries are charged [like mine weren't first time - diagnosed by putting an LED on the motor wires, and it glowing very dimly], you are ready to start asking the motor chip to power the motors. Again, follow the Adafruit instructions that get you putting e.g pin 4 high, which signals the chip to drive the left motor in one direction. You must also set the PWM (value of 0-1024 I believe) that controls the speed of the motor. I use at least 500, but normally closer to 1000 – as the if it is to low, the motors ‘stall’ and wont turn.

All you need now is some software to control it. Me and my housemate use an index.html file hosted on the Pi that calls a bash script whenever a directional key is pressed, then when it is let go, it runs an off script that turns all control pins back to 0. You can also use Python. I used Python to make the script to control the flashing emergency LEDs [superbright blue LEDs].

More soon!