Académique Documents
Professionnel Documents
Culture Documents
TITLE PROJECT:
December, 2014.
umi Dalibor
Content:
1
Introduction ............................................................................................................................................. 3
2.1
Rasbperry Pi ........................................................................................................................................... 4
2.2
GPIO ....................................................................................................................................................... 5
2.3
DC Motor ............................................................................................................................................... 6
2.4
2.5
2.6
3.2
3.3
3.4
Software ................................................................................................................................................ 12
4.1
Raspbian .............................................................................................................................................. 12
4.2
Python 3 ............................................................................................................................................... 12
5.2
5.3
The code............................................................................................................................................... 14
Results ................................................................................................................................................... 19
Conclusion ............................................................................................................................................. 19
References ............................................................................................................................................. 19
www.ibu.edu.ba
2
umi Dalibor
1 Introduction
This project is based on a DC motor that is used as a mechanism for control, that
is, opening and closing the garage door. In order to do this, to control the DC motor is
needed a drive that works on the principle of H - bridge, in this case, reversing the
direction of the DC motor and switching off the engine. The most suitable driver for such
a project such as this, is L293D driver. As the main controller , in this project is used
Raspberry Pi, which is among the smallest computer in the world. Raspberry Pi in
hardware part communicates with the L293D driver via GPIO (General Purpose Input
Output), which consists of 26 pins, and in software part communicates via one of the
most popular programming languages - Python 3. For controlling by hand, here is
remote wirelles device (RF remote) which has 4 buttons. For indication of status of the
garage door, here is used LCD 2x16 display. In the continuation it will shown how to
prepare the Raspberry Pi, bindings scheme and ,at the end, the program code.
www.ibu.edu.ba
3
umi Dalibor
2 Hardware part
2.1 Rasbperry Pi
RPI is a mini computer on whose board
the size of a credit card are Broadcom 32-bit
processor with a clock speed of 700MHz,
Broadcom Video Core IV GPU and 512 MB of
RAM (Model B) or 256 MB RAM (Model A),
which means that is at the heart of RPI's is the
same processor that powered the iPhone 3G
and Kindle 2nd Graphics is equivalent to that
of the first generation Xbox. In addition to
Broadcom's chips, there are also:
Figure 1. Rasbperry PI model B
HDMI out,
audio out
Ethernet port
GPIO pins,
5 status LEDs.
www.ibu.edu.ba
4
umi Dalibor
2.2 GPIO
One powerful feature of the Raspberry Pi is the row of GPIO (general purpose
input/output) pins along the edge of the board, next to the yellow video out socket.
These pins are a physical interface between the Pi and the outside world. They
are used to turn on or off (input) or by Pi turn on / off (output). Seventeen of the 26 pins
are GPIO pins; the others are power or ground pins.
www.ibu.edu.ba
5
umi Dalibor
2.3 DC Motor
A DC motor relies on the fact that like
magnet poles repel and unlike magnetic poles
attract each other. A coil of wire with a current
running
through
it
generates
an electromagnetic field aligned with the center
of the coil.
Figure 5. DC motor
The total amount of current sent to the coil, the coil's size and what it's wrapped
around dictate the strength of the electromagnetic field created. The sequence of turning
a particular coil on or off dictates what direction the effective electromagnetic fields are
pointed. By turning on and off coils in sequence a rotating magnetic field can be created.
These rotating magnetic fields interact with the magnetic fields of the magnets
(permanent or electromagnets) in the stationary part of the motor (stator) to create a
force on the armature which causes it to rotate. In some DC motor designs the stator
fields use electromagnets to create their magnetic fields which allow greater control
over the motor. At high power levels, DC motors are almost always cooled using forced
air.
www.ibu.edu.ba
6
umi Dalibor
Figure 7. RF module
www.ibu.edu.ba
7
umi Dalibor
A register select (RS) pin that controls where in the LCD's memory can be writed
data.
A Read/Write (R/W) pin that selects reading mode or writing mode.
An Enable pin that enables writing to the registers
8 data pins (D0 -D7). The states of these pins (high or low) are the bits that it is
writed to a register when you write, or readed the values.
There's also a display constrast pin (Vo), power supply pins (+5V and
Gnd) and LED Backlight (Bklt+ and BKlt-) pins that can be used to power the LCD,
control the display contrast, and turn on and off the LED backlight, respectively. The
process of controlling the display involves putting the data that form the image of what
you want to display into the data registers, then putting instructions in the instruction
register.
www.ibu.edu.ba
8
umi Dalibor
3 Hardware realization
In this project these items are used:
2 breadboards;
Raspberry Pi
RPi Cobbler and jumper wire
DC motor 3 V
4-channel RF module and 6 resistors (three 1.5 k and three 3k)
L293D driver
www.ibu.edu.ba
9
umi Dalibor
The reason why is used battery is that Raspberry Pi doesn't have enough power
to run LCD display, driver, DC motor and RF module at the same time. DC motor spends
a lot of power so battery is used to supply DC motor. Pin Vcc1 is connected to 5V. Pin In4
is connected to 26 pin of GPIO. Pin Out4 is connected to the first pin of DC motor. Pin
Out3 is connected to the second pin of the DC motor. Pin In3 is connected to pin 24 of
GPIO. Pin En1 is connected to pin 10 of GPIO. The Vcc2 pin is connected to pin 12 of
GPIO.
For controlling the speed of rotation of DC mtoor, for that is used Pulse-Width
Modulation which works by pulsing in time intervals.
www.ibu.edu.ba
10
umi Dalibor
RF module XY-DJM-5V has 7 pins. Two of them are for supply ( 5V ) and ground, other
four are for signalling and last one is for indication output status. First pin is connected to GND.
Second pin is connected to 5V. Pins D0, D1, D2 and D3 are connected to pins 10, 22 , 8 and 19 on
GPIO. Resistor are used to divide the outputs from RF module ( from 5V to 3.3V ) to converting
normal signal to logical "1" (3.3V).
www.ibu.edu.ba
11
umi Dalibor
4 Software
4.1 Raspbian
Raspbian is a free operating system based on Debian optimized for the Raspberry Pi
hardware. An operating system is the set of basic programs and utilities that make your
Raspberry Pi run. However, Raspbian provides more than a pure OS: it comes with over 35,000
packages, pre-compiled software bundled in a nice format for easy installation on your
Raspberry Pi.
The initial build of over 35,000 Raspbian packages, optimized for best performance on
the Raspberry Pi, was completed in June of 2012. However, Raspbian is still under active
development with an emphasis on improving the stability and performance of as many Debian
packages as possible.
4.2 Python 3
Python is a widely-used high level programming language. Its
elegant syntax allows you to clearly define application behaviour using
fewer lines of code than would be required in other languages like VB. It
supports multiple programming paradigms including imperative,
functional and object oriented styles, allowing a wide range of tasks to
be performed.
www.ibu.edu.ba
12
umi Dalibor
5 Software realizing
5.1 Installing Python and GPIO library to Raspbian
The installation of Python is perfomed by this command and it must be runned in LXTerminal ( Linux
Console) :
sudo apt-get install python-dev
www.ibu.edu.ba
13
= 18
LCD_D4 = 16
LCD_D5 = 11
LCD_D6 = 13
LCD_D7 = 15
# Define some device constants
LCD_WIDTH = 16
LCD_CHR = True
LCD_CMD = False
LCD_LINE_1 = 0x80 # LCD RAM address for the 1st line
LCD_LINE_2 = 0xC0 # LCD RAM address for the 2nd line
# Timing constants
E_PULSE = 0.00005
E_DELAY = 0.00005
def main():
# Main program block
GPIO.setmode(GPIO.BOARD)
GPIO.setup(LCD_E, GPIO.OUT)
GPIO.setup(LCD_RS, GPIO.OUT) # RS
GPIO.setup(LCD_D4, GPIO.OUT) # DB4
GPIO.setup(LCD_D5, GPIO.OUT) # DB5
GPIO.setup(LCD_D6, GPIO.OUT) # DB6
GPIO.setup(LCD_D7, GPIO.OUT) # DB7
GPIO.setup(26,GPIO.OUT) #Pin4 L293D
www.ibu.edu.ba
14
umi Dalibor
umi Dalibor
")
lcd_byte(LCD_LINE_2,LCD_CMD)
lcd_string("
watching ! :)
")
time.sleep(5)
#if pressed C button
www.ibu.edu.ba
15
STATUS :
")
lcd_byte(LCD_LINE_2, LCD_CMD)
lcd_string("
opening...
")
time.sleep(5)
GPIO.output(26,0)
lcd_byte(LCD_LINE_1,LCD_CMD)
lcd_string("
STATUS :
")
lcd_byte(LCD_LINE_2,LCD_CMD)
lcd_string("
opened
")
STATUS :
")
lcd_byte(LCD_LINE_2, LCD_CMD)
lcd_string("
closing...
")
time.sleep(5)
GPIO.output(24,0)
lcd_byte(LCD_LINE_1, LCD_CMD)
lcd_string("
STATUS :
")
lcd_byte(LCD_LINE_2, LCD_CMD)
lcd_string("
closed
")
def lcd_init():
# Initialise display
www.ibu.edu.ba
16
umi Dalibor
def lcd_string(message):
# Send string to display
for i in range(LCD_WIDTH):
lcd_byte(ord(message[i]),LCD_CHR)
for character
GPIO.output(LCD_RS, mode) # RS
# High bits
GPIO.output(LCD_D4, False)
GPIO.output(LCD_D5, False)
GPIO.output(LCD_D6, False)
GPIO.output(LCD_D7, False)
if bits&0x10==0x10:
GPIO.output(LCD_D4, True)
if bits&0x20==0x20:
GPIO.output(LCD_D5, True)
if bits&0x40==0x40:
GPIO.output(LCD_D6, True)
if bits&0x80==0x80:
GPIO.output(LCD_D7, True)
www.ibu.edu.ba
17
umi Dalibor
# Low bits
GPIO.output(LCD_D4, False)
GPIO.output(LCD_D5, False)
GPIO.output(LCD_D6, False)
GPIO.output(LCD_D7, False)
if bits&0x01==0x01:
GPIO.output(LCD_D4, True)
if bits&0x02==0x02:
GPIO.output(LCD_D5, True)
if bits&0x04==0x04:
GPIO.output(LCD_D6, True)
if bits&0x08==0x08:
GPIO.output(LCD_D7, True)
if __name__ == '__main__':
main()
www.ibu.edu.ba
18
umi Dalibor
umi Dalibor
6 Results
When is pressed for example button A, RF module generates signal of 5V, but 5V is not regular high
signal and Raspberry Pi can't recognise this signal, so it's divided by resistors 1.5k and 3k to 3.3 V
which is logical "1". Raspberry Pi recognise this divided signal and perfoms the action : from GPIO pin
26 send high signal or logical"1" to L293D driver and from GPIO pin 24 sends low signal or logical "0"
to L293D driver. This means that L293D driver runs the DC motor in clock direction. Of course, when
is recognised that divided signal is high, Python program sends some data string to LCD library and it
outputs to LCD Display.
On the same way, B buttons run the same action, but runs the DC motor in clockwise direction.
7 Conclusion
The usage of DC motor is unlimited. It can be used everywhere. This garage door opener is
one example of a lot. DC motors can be used in elevators, industry, building, technology and
enternainment ( for joystick vibrators). It's very useful item.
8 References
DC MOTOR : http://en.wikipedia.org/wiki/DC_motor
CONTROLLING DC MOTOR: http://www.rsonline.com/designspark/designshare/eng/projects/313/view/stage
/brief/
L293D driver : http://www.engineersgarage.com/electroniccomponents/l293d-motor-driver-ic
RF 4 channel module : http://www.libremechanics.com/?q=node/30
LCD display : http://arduino.cc/en/Tutorial/LiquidCrystal
Python and GPIO library: https://learn.adafruit.com/playingsounds-and-using-buttons-with-raspberry-pi/install-pythonmodule-rpi-dot-gpio
www.ibu.edu.ba
19