unit4-open platform
unit4-open platform
Raspberry-Pi Architecture
Raspberry pi is the name of the “credit card-sized computer board
Raspberry Pi is a small single-board computer (SBC).
It is a credit card-sized computer that can be plugged into a monitor.
It acts as a minicomputer by connecting the keyboard, mouse, and
display.
Raspberry Pi has an ARM processor and 512MB of RAM.
Used:
It also provides a set of general purpose input/output pins allowing you to control
electronic components for physical computing and explore the Internet of Things .
2. Click Looks.
USING PYTHON:
Print(“hello world”)
import serial
import time
def blink(pin):
GPIO.output(pin,GPIO.HIGH) time.sleep(1)
GPIO.output(pin,GPIO.LOW) time.sleep(1)
return
while True:
read_ser=ser.readline() print(read_ser)
blink(11)
Now open Arduino IDE and upload the following code to your Arduino. String data="Hello From
Arduino!";
void setup()
void loop()
{
// put your main code here, to run repeatedly: Serial.println(data);//data that is being Sent
delay(200);
RASPBERRY PI INTERFACES
Raspberry pi has Serial, SPI and I2C interfaces for data transfer.
Serial : The Serial interface on Raspberry Pi has receive (Rx) and transmit (Tx) pins for
communication with serial peripherals.
SPI : Serial Peripheral Interface (SPI) is a synchronous serial data protocol used for
communicating with one or more peripheral devices. in an SPI connection, there are five
pins on Raspberry Pi for SPI interface :
MISO (Master in slave out) – Master line for sending data to the peripherals.
MOSI (Master out slave in) – Slave line for sending data to the master.
SCK (Serial Clock) – Clock generated by master to synchronize data transmission
CE0 (Chip Enable 0) – To enable or disable devices
CE0 (Chip Enable 1) – To enable or disable devices
I2C :
The I2C interface pins on Raspberry Pi allow you to connect hardware modules. I2C
interface allows synchronous data transfer with just two pins – SDA (data line) an SCL
(Clock Line).
SPI SCHEME:
The GPIO pins allow the Raspberry Pi to control and monitor the outside world by
being connected to electronic circuits. The Pi is able to control LEDs, turning them on or off,
run motors, and many other things. It's also able to detect whether a switch has been
pressed, the temperature, and light.
Once we have configured the GPIO pins, we can start controlling them using Python
code. There are two main functions that we can use to control the GPIO pins:
GPIO.output() and GPIO.input().
The GPIO.output() function is used to set the state of an output GPIO pin. The function
takes two arguments: the GPIO pin number and the state (either GPIO.HIGH or
GPIO.LOW).
Here's an example of how to set GPIO pin 18 to HIGH:
GPIO.output(18, GPIO.HIGH)
The GPIO.input() function is used to read the state of an input GPIO pin. The function takes one
argument: the GPIO pin number.
Here's an example of how to read the state of GPIO pin 17:
state = GPIO.input(17)
code to switch the LED on. Turn on your Raspberry Pi and open the terminal
window.
nano LED.py
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(18,GPIO.OUT)
print "LED on"
GPIO.output(18,GPIO.HIGH)
time.sleep(1)
print "LED off"
GPIO.output(18,GPIO.LOW)