Вы находитесь на странице: 1из 21

RASPBERRY PI

Rizwan Hassan , Mohammed Rashid, Prof. A.


R. Al-Ali
WHAT IS
RASPBERRY PI?
Credit card-sized microcontroller

Used for DIY (Do It Yourself)


projects

Mainly used as down-scaled


embedded systems.
512MB built in SDRAM
40 digital General Purpose Input

and Output (GPIO) pins


ADC PI
FEATURES
8 channel 17 bit ATD converter

Based on two ATD converters

each having 4 analog inputs

with up to 18 bit resolution

Control via Raspberry Pi I2C

port

[3
CONNECTER SPECIFICATIONS
5V and 2A micro USB socket powered board

4 USB 2.0 ports

Ethernet socket

3.5mm audio jack


CONNECTER SPECIFICATIONS
HDMI (High-Definition Multimedia Interface) port

It is a proprietary audio/video interface for transferring uncompressed video

data

And compressed or uncompressed digital audio data from an HDMI-

compliant source device, such as a display controller, to a compatible

computer monitor, video projector, digital television, or ...

HDMI male to HDMI male cable with transfer rate of up to 5Gbps

1.5 Feet, 3 Feet, 6 Feet, 10 Feet, 15 Feet, 25 Feet, 30 Feet, 50 Feet


RASPBERRY PI MODEL B+
ADC PI FEATURES
Onboard 2.048V reference voltage

Onboard programmable gain amplifier, with gains of 1,2,4 or 8

Programmable data rates of 17,15,13,11 bits

[4
SOME DIY PROJECTS USING
RASPBERRY
PiPhone
PI
Voice-activated coffee machine

[5
]

[6
SOME DIY PROJECTS USING
RASPBERRY PI
Pi-rate Radio

Supercomputers from Legos and Raspberry Pi

[7
]

[8
USAGE OF HEADER FILE
RPI_SERVER.PY
USED HEADER FILES
requests
http://www.python-requests.org/en/latest/ : Library for making requests to server

uuid
Library for getting Universally Unique Identifier

socket,fcntl,struct
socket: Library to provides access to socket interface
fcntl: Performs file control and I/O control on file descriptors. [Applicable to Unix
Systems Only]
struct: Functions for converting between strings of bytes and native Python data
types like strings and numbers
USED GLOBAL VARIABLES
1. uid=uuid.getnode()
# Stores Universally Unique Identifier of the device obtained from uuid library

2. ip='10.25.32.184'
#Default IP of the server

3. identity=0
#Id of the raspberry in the server
UTILITY FUNCTIONS
#To be called only if the server ip changes
def set_server_ip(ip_add):
global ip #Tells compiler that this ip is the ip referenced above in global scope
ip=ip_addr

#Return the ip address of a given interface


def get_ip(interface='eth0'):
SIOCGIFADDR = 0x8915
s= socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
#Creates an endpoint for communication and returns a descriptor
#Syntax : socket.socket(Address Family(IPv4,IPv6,etc),Socket Type(Datagram,stream communication,etc))
return socket.inet_ntoa(fcntl.ioctl(s.fileno(),SIOCGIFADDR
,struct.pack('256s',interface[:15]))[20:24])
#Return IPv4 address of the server
UTILITY FUNCTIONS
#Returns id of the raspberry pi as registered in the server
def get_id():
parameter={uid':uid}
#server uses uuid to uniquely identify each unit as ip address can
vary
post_response=requests.post(url='http://'+ ip
+'/embedded/get_id.php',data=parameter)
global identity
identity = post_response.text
return identity
1. REGISTER RASPBERRY PI WITH
SERVER BY PASSING IP ADDRESS
AND UUID ADDRESS TO THE
def register_pi():

SERVER parameter={uid':uid,'ip':get_ip('eth0')}
#Server takes parameters uuid and ip to register/update a device details in the server.

post_response=requests.post(url='http://'+ ip +'/embedded/register.php',data=parameter)
#Using post methode offered by request library to write values to the server

if(post_response.text=='OK'): #If server returns OK message go inside this block


global identity
identity = get_id() #Get Id from server by calling get_id() function in this file
return True
return False

Usage : rpi_server.register_pi() after importing the header file that contains all
2. REGISTER PORTS AS
INPUTS/OUTPUTS
#Registers rasberry pi ports in the server for use as input/output
#0 for output and 1 for input in the direction field
def register_port(port,direction):
global identity
parameter={'id':identity,'port':port,'io':direction}
#server takes parameters id,port and io to register/update a port in the server
post_response=requests.post(url='http://'+ ip +'/embedded/reg_port.php'
,data=parameter)
if(post_response.text=='OK'):
return True
return False
Usage : rpi_server.register_port(7,0) after importing the header for using pin 7 as
output port
READ PORT DATA FROM
SERVER
#Reads port data from server using unique id of the device and port number
#can be used to read port data from a different device using id of that device
def read_data(ids,port):
parameter={'id':ids,'port':port}
post_response=requests.post(url='http://'+ ip
+'/embedded/retrieve_data.php'
,data=parameter)
if(post_response.text=='error'):
print "Error Reading value !!!!\nNo record exists for the given port number"
else:
return post_response.text
Usage : rpi_server.read_data(rpi_server.get_id(),7) to read data of port 7 as stored in
the database server
WRITE DATA TO SERVER
#Sends data of the given port of the raspberry of given id to the
server
def write_data(ids,port,data):
parameter={'id':ids,'port':port,'data':data}
post_response=requests.post(url='http://'+ ip
+'/embedded/insert_data.php',data=parameter)
print post_response.text
if(post_response.text=='OK'):
return True
return False
Usage : rpi_server.write_data(rpi_server.get_id(),7) to write data of port 7 to database
server

Вам также может понравиться