Nokia5110-LCD/LCD.py

130 lines
3.0 KiB
Python

import time
import spidev
import RPi.GPIO as GPIO
import glyph
spi = spidev.SpiDev()
spi.open(0,0)
spi.max_speed_hz=5000000
#gpio pin definitions
DC = 23
RST = 24
DIN = 19
SPI_PORT = 0
SPI_DEVICE = 0
#gpio setup
GPIO.setmode(GPIO.BCM)
GPIO.setup(RST, GPIO.OUT)
GPIO.setup(DC, GPIO.OUT)
#pulse reset
GPIO.output(RST, False)
time.sleep(0.1)
GPIO.output(RST, True)
#LED setup
GPIO.setup(18, GPIO.OUT)
GPIO.output(18, False)
#command test
#DC low for commands
GPIO.output(DC, False)
#resp = spi.xfer2([0x21, 0xB8, 0x04, 0x14, 0x20,0x09])
spi.writebytes([0x21])
spi.writebytes([0xB8])
spi.writebytes([0x04])
spi.writebytes([0x14])
spi.writebytes([0x20])
spi.writebytes([0x09])
spi.writebytes([0x0C])
#test transmit data
GPIO.output(DC, True)
spi.writebytes(glyph.I)
spi.writebytes(glyph.R)
spi.writebytes(glyph.O)
spi.writebytes(glyph.N)
spi.writebytes(glyph.SPACE)
spi.writebytes(glyph.S)
spi.writebytes(glyph.E)
spi.writebytes(glyph.R)
spi.writebytes(glyph.V)
spi.writebytes(glyph.E)
spi.writebytes(glyph.R)
spi.writebytes(glyph.SPACE)
spi.writebytes(glyph.SPACE)
spi.writebytes(glyph.SPACE)
spi.writebytes(glyph.SPACE)
spi.writebytes(glyph.SPACE)
spi.writebytes([0x00, 0x00, 0x00, 0x00])
spi.writebytes(glyph.D)
spi.writebytes(glyph.E)
spi.writebytes(glyph.L)
spi.writebytes(glyph.U)
spi.writebytes(glyph.G)
spi.writebytes(glyph.E)
spi.writebytes(glyph.SPACE)
spi.writebytes(glyph.SPACE)
spi.writebytes(glyph.SPACE)
spi.writebytes(glyph.SPACE)
spi.writebytes(glyph.SPACE)
spi.writebytes(glyph.SPACE)
spi.writebytes(glyph.SPACE)
spi.writebytes(glyph.SPACE)
spi.writebytes(glyph.SPACE)
spi.writebytes(glyph.SPACE)
spi.writebytes([0x00,0x00,0x00,0x00])
spi.writebytes(glyph.M)
spi.writebytes(glyph.U)
spi.writebytes(glyph.R)
spi.writebytes(glyph.M)
spi.writebytes(glyph.U)
spi.writebytes(glyph.R)
spi.writebytes(glyph.SPACE)
spi.writebytes(glyph.SPACE)
spi.writebytes(glyph.SPACE)
spi.writebytes(glyph.SPACE)
spi.writebytes(glyph.SPACE)
spi.writebytes(glyph.SPACE)
spi.writebytes(glyph.SPACE)
spi.writebytes(glyph.SPACE)
spi.writebytes(glyph.SPACE)
spi.writebytes(glyph.SPACE)
spi.writebytes([0x00,0x00,0x00,0x00])
spi.writebytes(glyph.S)
spi.writebytes(glyph.A)
spi.writebytes(glyph.M)
spi.writebytes(glyph.B)
spi.writebytes(glyph.A)
spi.writebytes(glyph.SPACE)
spi.writebytes(glyph.SPACE)
spi.writebytes(glyph.SPACE)
spi.writebytes(glyph.SPACE)
spi.writebytes(glyph.SPACE)
spi.writebytes(glyph.SPACE)
spi.writebytes(glyph.SPACE)
spi.writebytes(glyph.SPACE)
spi.writebytes(glyph.SPACE)
spi.writebytes(glyph.SPACE)
spi.writebytes(glyph.SPACE)
spi.writebytes([0x00,0x00,0x00,0x00])
spi.writebytes(glyph.N)
spi.writebytes(glyph.G)
spi.writebytes(glyph.I)
spi.writebytes(glyph.N)
spi.writebytes(glyph.X)
spi.writebytes(glyph.SPACE)
spi.writebytes(glyph.SPACE)
spi.writebytes(glyph.SPACE)
spi.writebytes(glyph.SPACE)
spi.writebytes(glyph.SPACE)
spi.writebytes(glyph.SPACE)
spi.writebytes(glyph.SPACE)
spi.writebytes(glyph.SPACE)
spi.writebytes(glyph.SPACE)
spi.writebytes(glyph.SPACE)
spi.writebytes(glyph.SPACE)
spi.writebytes([0x00,0x00,0x00,0x00])
spi.close()