DesignSpark Electrical Logolinkedin
Menu Search
Ask a Question

Raspberry Pi Controlling a Motor via GPIO

The aim of this exercise is to show students how to the Raspberry Pi may be used in conjunction with a L293D chip to control the direction of rotation a DC motor, and how the speed of a DC motor may be controlled using Pulse Width Modulation (PWM). The exercise will also demonstrate how a simple human machine interface can be programmed to control the system in various different ways.

Learning Objectives

The exercise is split in to three “Steps” of increasing complexity

Step 1 introduces the student to the L293D motor control chip and explains in simple terms how the chip can be used to control a DC motor. It also introduces the student to the IDLE integrated development environment and to the Python programming language by asking them to enter commands directly at the Python prompt. These commands are used to turn a DC motor “On” and “Off” by means of the L293D chip.

Step 2 introduces the concept of creating a file containing a series of Python commands, saving this file as a “computer program”, and “running” the program. The concept of Pulse Width Modulation (PWM) as a means of controlling the speed of a DC motor is introduced and it is shown how the Duty Cycle relates to the power delivered to the motor. The definition and use of functions in Python is introduced as a means of simplifying code and reducing repetition.

Step 3 introduces the concept of human-machine interaction via a simple user interface and shows how the user interface can be reprogrammed by altering the Python Code to control the system in different ways. The idea of writing a description of how a system should behave and drawing a system flowchart as an aid to designing the system and writing the Python code is also introduced.

Note- These exercises were created using a Raspberry Pi Model B with a 26 Way GPIO Pin header.  Newer models have a 40 Way GPIO header, but the first 26 pins ae the same.  

Please see attached files for exercises and Raspberry Pi Setup guides

 

Geek, Blogger, Gadget Junkie, Crisp Junkie, Technology Evangelist. ***If you meet me, ask me for the Pete and Greet Badge code.*** DesignSpark Team twitter - @petenwood

11 Aug 2016, 9:50

Comments

[Comment was deleted]