You are on page 1of 9

Raspberry pi Exp.

Board User Manual

Board Features:

123456789-

12volts regulated power supply


Three transistor output drived by MCP23017 (GPB2, GPB3, GPB4)
Sensor input or buttons
5v TTL Level Converter RX input and TX output from raspberry.
Analog input MCP3008 using the proper SPI pins and the hardware driver.
Raspberry Connector.
I2C 5v level converter ready to DS1307 Real Time Clock Module.
IC MCP23017 controled by I2C raspberry pi.
Ten relays drived by MCP23017 (GPA0, GPA1, GPA2, GPA3, GPA4, GPA5,
GPA6, GPA7, GPB0, GPB1).

2 - Three transistor output driver by MCP23017 (GPB2, GPB3, GPB4)

Through this output is possible to connect devices, that output can drive 12v at 800mA.
Example of code using Adafruit library https://github.com/adafruit/Adafruit-Raspberry-PiPython-Code
from Adafruit_I2C import Adafruit_I2C
import smbus
import time
import spidev
from Adafruit_MCP230xx import *
OUTPUT = 0
INPUT = 1
if __name__ == '__main__':
# Use busnum = 0 for older Raspberry Pi's (pre 512MB)
mcp = Adafruit_MCP230XX(busnum = 1, address = 0x20, num_gpios = 16)
# Use busnum = 1 for new Raspberry Pi's (512MB)
# Set pins 10, 11 and 12 to output (you can set pins 0..15 this way)
mcp.config(10, OUTPUT)
mcp.config(11, OUTPUT)
mcp.config(12, OUTPUT)
# Python speed test on output
while (True):
#mcp.output(Pin,State)
mcp.output(10, 1) # Pin 10
mcp.output(11, 1) # Pin 11
mcp.output(12, 1) # Pin 12
time.sleep(1.2)
mcp.output(10, 0) # Pin 10
mcp.output(11, 0) # Pin 11
mcp.output(12, 0) # Pin 12
time.sleep(1.2)

0 toggling at max speed


High
High
High
High
High
High

3 - Sensor input or button:

in0
in1
in2
in3
in4
in5
in6
in7

=
=
=
=
=
=
=
=

GPIO
GPIO
GPIO
GPIO
GPIO
GPIO
GPIO
GPIO

17 pull down to raspberry pi


18 pull down to raspberry pi
27 pull down to raspberry pi
22 pull down to raspberry pi
23 pull down to raspberry pi
24 pull down to raspberry pi
25 pull down to raspberry pi
4 pull down to raspberry pi

Example of code:
You will need to install the RPi.GPIO library
import time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(17,GPIO.IN) #GPIO0
GPIO.setup(18,GPIO.IN) #GPIO1
GPIO.setup(27,GPIO.IN) #GPIO2
GPIO.setup(22,GPIO.IN) #GPIO3
GPIO.setup(23,GPIO.IN) #gpio4
GPIO.setup(24,GPIO.IN) #GPIO5
GPIO.setup(25,GPIO.IN) #GPIO6
GPIO.setup(4,GPIO.IN) #GPIO7
print 'Start'
#initialise a previous input variable to 0 (assume button not pressed last)
prev_input0 = 0
while True:
#take a reading
input0 = GPIO.input(17)
input1 = GPIO.input(18)
input2 = GPIO.input(27)
input3 = GPIO.input(22)
input4 = GPIO.input(23)
input5 = GPIO.input(24)
input6 = GPIO.input(25)
input7 = GPIO.input(4)
#if the last reading was low and this one high, print
if (input0 == 1):
print("sensor0")
if (input1 == 1):
print("sensor1")
if (input2 == 1):
print("sensor2")
if (input3 == 1):
print("sensor3")
if (input4 == 1):

print("sensor4")
if (input5 == 1):
print("sensor5")
if (input6 == 1):
print("sensor6")
if (input7 == 1):
print("sensor7")
#slight pause to debounce
time.sleep(0.05)

4 5v TTL Level Converter RX input and TX output from raspberry.

In order to use the Pis serial port for anything else than as a console, you first need to
disable getty (the program that displays login seen) by commenting the serial line out
of Pis /etc/inittab:
1:2345:respawn:/sbin/getty 115200 tty1
# Line below commented out
# 2:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
3:23:respawn:/sbin/getty 115200 tty3
4:23:respawn:/sbin/getty 115200 tty4
5:23:respawn:/sbin/getty 115200 tty5
6:23:respawn:/sbin/getty 115200 tty6

If you dont want the Pi sending stuff over the serial line when it boots, you can also
remove the statements console=ttyAMA0,115200 and kgdboc=ttyAMA0,115200 from
/boot/cmdline.txt. Youll need to reboot the Pi in order for the changes to take effect.
If you have a 3.3V compatible serial adapter in your computer (or a MAX3232 and
normal RS-232 adapter, in which case see my tutorial on building one), its a good time
to try out if everything is working on the Pi side. Install minicom (sudo apt-get install
minicom) and attach is to serial terminal:
minicom -b 9600 -o -D /dev/ttyAMA0

Then open Putty or similar serial terminal on PC side. Everything you type into minicom
should appear in the serial terminal on PC side, and characters typed to serial terminal
should appear on minicom.
Tutorial from: http://codeandlife.com/2012/07/29/arduino-and-raspberry-pi-serialcommunication/

5 - Analog input MCP3008 using the proper SPI pins and the hardware driver
(3.3 max input voltage):

The connections from the board to the MCP3008 are as follows:


MCP3008
MCP3008
MCP3008
MCP3008
MCP3008
MCP3008
MCP3008
MCP3008

VDD -> 3.3V


VREF -> 3.3V
AGND -> GND
CLK -> SCLK
DOUT -> MISO
DIN -> MOSI
CS
-> CE0
DGND -> GND

This project was built using Occidentalis v0.2 from Adafruit which takes the hassle out of
fiddling with Linux. It comes with the hardware SPI driver ready to go. A couple of packages
are required to complete this project.
sudo apt-get install mpg321
and secondly the Python wrapper for SPI:
cd ~
git clone git://github.com/doceme/py-spidev
cd py-spidev/
sudo python setup.py install

Full tutorial in: ( http://jeremyblythe.blogspot.com.br/2012/09/raspberry-pi-hardwarespi-analog-inputs.html )

Example of code:
import spidev
import time
import os
spi = spidev.SpiDev()
spi.open(0,0)
# read SPI data from MCP3008 chip, 8 possible adc's (0 thru 7)
def readadc(adcnum):
if ((adcnum > 7) or (adcnum < 0)):
return -1
r = spi.xfer2([1,(8+adcnum)<<4,0])
adcout = ((r[1]&3) << 8) + r[2]
return adcout
# 10k trim pot connected to adc #0
potentiometer_adc = 0;
while True:
# read the analog pin
trim_pot = readadc(potentiometer_adc)
print trim_pot
time.sleep(0.5)

6 - Raspberry Connector.

9 - Ten relays drived by MCP23017 (GPA0, GPA1, GPA2, GPA3, GPA4, GPA5,
GPA6, GPA7, GPB0, GPB1).

With relays available in this board you can drive engines, lamps, locks, sirens, water
pumps.Through these loads can throw 110 or 220 volts AC, not exceeding 12A at 110V
and 7A at 250V.
Example of code using Adafruit library https://github.com/adafruit/Adafruit-Raspberry-PiPython-Code
from Adafruit_I2C import Adafruit_I2C
import smbus
import time
import spidev
from Adafruit_MCP230xx import *
OUTPUT = 0
INPUT = 1
if __name__ == '__main__':
# Use busnum = 0 for older Raspberry Pi's (pre 512MB)
mcp = Adafruit_MCP230XX(busnum = 1, address = 0x20, num_gpios =
16)
# Use busnum = 1 for new Raspberry Pi's (512MB)
# Set pins 0,
mcp.config(0,
mcp.config(1,
mcp.config(2,
mcp.config(3,
mcp.config(4,
mcp.config(5,
mcp.config(6,
mcp.config(7,
mcp.config(8,
mcp.config(9,
#
#
#
#

1 and 2 to output (you can set pins 0..15 this way)


OUTPUT)
OUTPUT)
OUTPUT)
OUTPUT)
OUTPUT)
OUTPUT)
OUTPUT)
OUTPUT)
OUTPUT)
OUTPUT)

Set pin 3 to input with the pullup resistor enabled


mcp.pullup(3, 1)
Read pin 3 and display the results
print "%d: %x" % (3, mcp.input(3) >> 3)

# Python speed test on output 0 toggling at max speed


while (True):
#mcp.output(Pin,State)
mcp.output(1, 1) # Pin 0 High

mcp.output(0, 1)
mcp.output(2, 1)
mcp.output(3, 1)
mcp.output(4, 1)
mcp.output(5, 1)
mcp.output(6, 1)
mcp.output(7, 1)
mcp.output(8, 1)
mcp.output(9, 1)
time.sleep(1.2)
mcp.output(1, 0)
mcp.output(0, 0)
mcp.output(2, 0)
mcp.output(3, 0)
mcp.output(4, 0)
mcp.output(5, 0)
mcp.output(6, 0)
mcp.output(7, 0)
mcp.output(8, 0)
mcp.output(9, 0)
time.sleep(1.2)

#
#
#
#
#
#
#
#
#

Pin
Pin
Pin
Pin
Pin
Pin
Pin
Pin
Pin

0
0
0
0
0
0
0
0
0

High
High
High
High
High
High
High
High
High

#
#
#
#
#
#
#
#
#
#

Pin
Pin
Pin
Pin
Pin
Pin
Pin
Pin
Pin
Pin

1
1
0
0
0
0
0
0
0
0

Low
Low
High
High
High
High
High
High
High
High

You might also like