YOU’LL NEED THIS
• Robot kit
• Pi 3B+ or 4 4GB
• 2x L298D motor controllers
• 12x female- to-female jumper wires
• USB battery for testing
• Code: tinyurl.com/ APC518ROBOT
PART 2/3
Don’t miss next issue, subscribe on page 21!
At the end of part one, we had built our robot from a kit and soldered wires from the motor terminals. In this part, we move on to writing code that will control the motors and move our robot. As our robot has four motors, we need to use two motor controllers. One for the rear motors, the other for the front. But which are the best choice for this project, and how do we interface the Raspberry Pi to them? We will create our own Python module (a library of prewritten code) to control the motors and create a test script to ensure it all works.
This part can get quite complex – we are working with four motors. Take your time, tackle just one motor at once, and double-check your connections before moving on. Sure, we want to get to the bit where our robot runs around under our command, but we need to put some work in before we reach those giddy delights.
Motor controllers
We can’t just connect the GPIO of the Raspberry Pi to the motors. The amount of current consumed by a motor is many times what the Pi GPIO can produce. Instead we need something that sits between the Pi and the motors: a motor controller. The controller receives the signal from the Raspberry Pi’s GPIO and triggers its output pins