This tutorial explains how to interface DC motor with Beaglebone black where DC motor acts as an actuator device. Due to insufficient current, it’s not possible to drive the motor directly from BBB and hence a motor driver IC is needed. Program is written in python script with Adafruit GPIO library.
- Beaglebone Black
- DC motor
- Driver IC (i.e. L293D)
- Push button
- 1 kΩ Resistor
- 0.1 uF capacitor
- Female to Female connectors
Setup of Software environment
Install the latest python version in BBB as explained in tutorial How to make first python program with Beaglebone Black. Install the Adafruit python-GPIO library named adafruit_BBIO.
I have interfaced DC motor and switch with the Beaglebone black’s GPIO pin. When the script is executed, it enters in a continuous loop. One press on the switch will start rotating the motor in a clockwise direction while another press will turn it off. Press ctrl+C to stop the execution of program form SSH command terminal.
Let’s first prepare the circuit connection. Take a breadboard and provide VCC and ground from BBB to breadboard line. L293D operates on at least 4.5 V while Switch and GPIO work on 3.3 V. BBB has on chip system 5 V and 3.3 V pin header. So you can draw both supplies from Beaglebone Black. System 5 V is drawn for L293D and 3.3V is drawn for switch and GPIO.
On one side of breadboard, connect supply 3.3 V from pin number 3rd of header P9 and ground from pin number 2nd of header P8. On the other connect supply system 5 V from pin number 8th of header P9 and make ground common with pin number 2nd of header P8.
Push button has two terminals. Any one of them connects with ground. Provide the VCC 3.3 V through 1k ohm resistor to another terminal of push button. Common end of resistor and push button, connect with pin number 30th of header P9.
L293D is motor driver IC that allows driving the motor in both directions. DC motor drive is on high current capacity but BBB’s GPIO pin cannot generate sufficient current to drive DC motor. L293D IC overcomes this problem and it is required to interface between BBB and DC motor. L293D also protect BBB from damage due to back emf generated by DC motor.
Output of BBB is connected with input of L293D. Pin number 8th and 9th of header P8 act as motor’s positive and negative terminals respectively. Take input from these pins and connect with input1 (2nd pin of L293D) and input2 (7th pin of L293D) Pin of L293D respectively. Interface the DC motor between output1 (3rd pin of L293D) and output2 (6th pin of L293D) pin of L293D. Provide system 5 V to both VCC (16th pin of L293D) and VSS (8th pin of L293D) pin of L293D. VCC is supply for internal logic translation in L293D and VSS is power for driver 5V.
I attached 0.1 uF capacitor between output1 and output2 terminals for alignment and back emf protection purpose. Provide the supply to Beaglebone black by connecting with PC through USB cable. Now your circuit is prepared.
Open the command terminal and take an access of Beaglebone black through SSH as explained in the tutorial getting started with Beaglebone black. Create a new file using touch command with .py extension (i.e. led.py). Open the file with any text editor (i.e. nano, vim etc.) and write a code in python language.
Configuration of GPIO pin
Import the GPIO library from adafruit Beaglebone black library by calling following line in program:
import Adafruit_BBIO.GPIO as GPIO
Configuration and function of GPIO already I explained in tutorial LED interfacing with Beaglebone Black and switch interfacing with Beaglebone black.
Run the script from terminal:
Enter the following command with file name from command prompt:
i.e. python dcMotor.py
Filed Under: BeagleBone, Electronic Projects, Tutorials