You are on page 1of 5

Experiment 2.

Circuit diagram:
Aim:

To display “Hello World” message in the OLED display using Raspberry Pi board.

Apparatus Required:

S
Name of the item Type Range Quantity
.No.

1. Raspberry Pi board Type 3 - 1

2. OLED display SSD1306 - 1

3. Bread Board - 1 1

4. Connecting wires - - 10

Connection diagram

1. Connections are given as per circuit diagram.


2. Connect 3.3V supply pin 1 from raspberry pi board to Vcc pin of the OLED display.
3. Connect ground pin 6 from the raspberry pi board to Gnd of the OLED display.
4. Connect pin 3 from the raspberry pi board to SDA on the OLED display.
5. Connect pin 5 from the raspberry pi board to SCL on the OLED display.

Procedure for accessing raspberry pi through PC.

1. Open Putty on your desktop.


2. Enter the ip address of the raspberry pi.
3. Select the connection type SSH and press open.
4. Raspberry pi is connected through Putty terminal.
5. Enter default user name : pi
6. Enter default password: raspberry
7. Configuration setup is done if needed.

The following steps are followed to open an example in a particular folder:

To select the folder Adafruit_Python_SSD1306

cd Adafruit_Python_SSD1306 and press enter

To select folder examples

cd examples and press enter

To see the list of files

ls and press enter


To open a file

sudo nano shapes.py and press enter

To run a file

Python shapes.py and press enter

----------------- ---------------------------------------------------------------------------------------

Code:

import time

import Adafruit_GPIO.SPI as SPI

import Adafruit_SSD1306

from PIL import Image

from PIL import ImageDraw

from PIL import ImageFont

# Raspberry Pi pin configuration:

RST = 24

# Note the following are only used with SPI:

DC = 23

SPI_PORT = 0

SPI_DEVICE = 0

# Beaglebone Black pin configuration:

# RST = 'P9_12'

# Note the following are only used with SPI:

# DC = 'P9_15'

# SPI_PORT = 1

# SPI_DEVICE = 0
# 128x32 display with hardware I2C:

disp = Adafruit_SSD1306.SSD1306_128_32(rst=RST)

# Initialize library.

disp.begin()

# Clear display.

disp.clear()

disp.display()

# Create blank image for drawing.

# Make sure to create image with mode '1' for 1-bit color.

width = disp.width

height = disp.height

image = Image.new('1', (width, height))

draw = ImageDraw.Draw(image)

padding = 2

shape_width = 20

top = padding

bottom = height-padding

# Move left to right keeping track of the current x position for drawing shapes.

x = padding

# Load default font.

font = ImageFont.load_default()

draw.text((x+30, top+30), 'Hello World', font=font, fill=255,)

# Display image.

disp.image(image)

disp.display()
Output inference:

Result:

You might also like