This code is discontinued - Check out our newer tutorial at: https://learn.adafruit.com/nokia-5110-3310-monochrome-lcd
The Nokia 5110/3310 display is a great inexpensive graphical display that's easy to use with an Arduino. Wouldn't it be nice to use this display with a modern Linux-based development board like the Raspberry Pi or Beaglebone Black too? Now you can, with the Adafruit Nokia LCD Python library!

This library allows you to connect the Nokia LCD to a Raspberry Pi or Beaglebone Black and display graphics using the Python programming language. Make the next great snake game, or maybe just display some stats for your Raspberry Pi/Beaglebone Black server--you're only limited by what you can imagine! Follow this guide to learn how to install and use the Nokia LCD python library.

To follow this guide you will need a Nokia 5110/3310 display and a Raspberry Pi (either model A or B) or Beaglebone Black. You will want to be running the latest Raspbian or Raspbian-derived operating system on your Pi, or the latest Debian image for the Beaglebone Black.

If you aren't familiar with the Nokia LCD, take a moment to read the Arduino guide for more information on the display too.
Connecting a Raspberry Pi or Beaglebone Black to the Nokia LCD is very simple because these boards use the same 3.3 volt I/O as the LCD. There's no need to use a level converter chip like with the Arduino!

In general you will need to connect the LCD's SCLK, DIN, and CS pins to the board's SPI pins, and the LCD's RST and D/C pins to two free digital I/O pins. With this setup you can use the very fast hardware SPI support built into your board.

However if you need more flexibility and don't require fast screen updates, the library also supports software SPI on any 5 digital I/O pins (SCLK, DIN, CS, RST, D/C). The example code on the next page describes how to enable software SPI. If you aren't sure what to use, start with hardware SPI since it's much more responsive at updating the display.

Raspberry Pi

To connect the LCD to a Raspberry Pi, the Pi's hardware SPI pins and two GPIO pins should be wired to the LCD as follows:
The above wiring will support talking to the LCD over the /dev/spidev0.0 interface.

Beaglebone Black

To connect to the Beaglebone Black, connect the SPI0 pins and two additional digital IO pins as follows:
The configuration above will enable communication with the LCD over the /dev/spidev1.0 interface.

Also if you are new to the Beaglebone Black, take a moment to review how the GPIO pins are laid out and numbered on the board. There are a lot of pins so be careful to connect the LCD to the right ones!

Once your LCD is connected to your hardware, power on your device and confirm the LCD backlight turns on. If you don't see the backlight turn on double check your ground and voltage wiring carefully.




sudo pip install RPi.GPIO


sudo pip install Adafruit_BBIO


sudo apt-get install python-imaging


sudo apt-get install git
git clone https://github.com/adafruit/Adafruit_Nokia_LCD.git
cd Adafruit_Nokia_LCD
sudo python setup.py install

Raspberry Pi SPI Setup


Beaglebone Black Device Tree Setup







Inside the examples subdirectory you'll find python scripts which demonstrate the usage of the library. To help you get started, I'll walk through the shapes.py code below:

Download: file
import time

import Adafruit_Nokia_LCD as LCD
import Adafruit_GPIO.SPI as SPI

import Image
import ImageDraw
import ImageFont
Download: file
# Raspberry Pi hardware SPI config:
DC = 23
RST = 24

# Raspberry Pi software SPI config:
# SCLK = 4
# DIN = 17
# DC = 23
# RST = 24
# CS = 8

# Beaglebone Black hardware SPI config:
# DC = 'P9_15'
# RST = 'P9_12'
# SPI_PORT = 1

# Beaglebone Black software SPI config:
# DC = 'P9_15'
# RST = 'P9_12'
# SCLK = 'P8_7'
# DIN = 'P8_9'
# CS = 'P8_11'



Uncomment and comment the pins appropriately to match your hardware configuration.
Download: file
# Hardware SPI usage:


# Initialize library.

# Clear display.




Download: file
# Create blank image for drawing.
image = Image.new('1', (LCD.LCDWIDTH, LCD.LCDHEIGHT))

# Get drawing object to draw on image.
draw = ImageDraw.Draw(image)

# Draw a white filled box to clear the image.

# Draw some shapes.
draw.line((68,22,81,2), fill=0)
draw.line((68,2,81,22), fill=0)

# Load default font.
font = ImageFont.load_default()

# Alternatively load a TTF font.
# Some nice fonts to try: http://www.dafont.com/bitmap.php
# font = ImageFont.truetype('Minecraftia.ttf', 8)

# Write some text.

# Display image.




To run the example execute the following command:

sudo python shapes.py


Examine and run the other example files such as image.py to see how to load and display an image file, or animate.py to see a simple text animation.
