User avatar
bgreat
Posts: 235
Joined: Mon Jan 23, 2012 2:09 pm

Re: Nokia Pi LCD

Tue Jan 15, 2013 9:58 pm

That's the package. I installed it using pip:

Code: Select all

sudo pip install spidev
I have been programming on Linux -- desktop and embedded -- for some time, but I am new to Python. Still, it was simple to get spidev working. I adapted some code I had found on the forums to use the SPI interface via spidev. I've been playing with it for the last week since my Nokia displays arrived. The code is listed below, but it's not pretty to look at right now. I have been hacking through it to see if I can use PIL for doing graphics and general rendering. All I can say is it works. :)

Code: Select all

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# code improvements
#  9/10/12
######
# WGG - picked up from Raspberry Pi forums and modified with a heavy hand
# -- added spidev support
# -- testing with PIL


import time
import wiringpi
import spidev
from PIL import Image,ImageDraw,ImageFont

# White backlight
CONTRAST = 0xa4

# Blue backlight
#CONTRAST = 0xb4

ROWS = 6
COLUMNS = 14
PIXELS_PER_ROW = 6
ON = 1
OFF = 0

#gpio's :
DC   = 3 # gpio pin 15 = wiringpi no. 3 (BCM 22)
RST  = 0 # gpio pin 11 = wiringpi no. 0 (BCM 17)
LED  = 1 # gpio pin 12 = wiringpi no. 1 (BCM 18)

# SPI connection
SCE  = 10 # gpio pin 24 = wiringpi no. 10 (CE0 BCM 8)
SCLK = 14 # gpio pin 23 = wiringpi no. 14 (SCLK BCM 11)
DIN  = 12 # gpio pin 19 = wiringpi no. 12 (MOSI BCM 10)

CLSBUF=[0]*(ROWS * COLUMNS * PIXELS_PER_ROW)

FONT = {
  ' ': [0x00, 0x00, 0x00, 0x00, 0x00],
  '!': [0x00, 0x00, 0x5f, 0x00, 0x00],
  '"': [0x00, 0x07, 0x00, 0x07, 0x00],
  '#': [0x14, 0x7f, 0x14, 0x7f, 0x14],
  '$': [0x24, 0x2a, 0x7f, 0x2a, 0x12],
  '%': [0x23, 0x13, 0x08, 0x64, 0x62],
  '&': [0x36, 0x49, 0x55, 0x22, 0x50],
  "'": [0x00, 0x05, 0x03, 0x00, 0x00],
  '(': [0x00, 0x1c, 0x22, 0x41, 0x00],
  ')': [0x00, 0x41, 0x22, 0x1c, 0x00],
  '*': [0x14, 0x08, 0x3e, 0x08, 0x14],
  '+': [0x08, 0x08, 0x3e, 0x08, 0x08],
  ',': [0x00, 0x50, 0x30, 0x00, 0x00],
  '-': [0x08, 0x08, 0x08, 0x08, 0x08],
  '.': [0x00, 0x60, 0x60, 0x00, 0x00],
  '/': [0x20, 0x10, 0x08, 0x04, 0x02],
  '0': [0x3e, 0x51, 0x49, 0x45, 0x3e],
  '1': [0x00, 0x42, 0x7f, 0x40, 0x00],
  '2': [0x42, 0x61, 0x51, 0x49, 0x46],
  '3': [0x21, 0x41, 0x45, 0x4b, 0x31],
  '4': [0x18, 0x14, 0x12, 0x7f, 0x10],
  '5': [0x27, 0x45, 0x45, 0x45, 0x39],
  '6': [0x3c, 0x4a, 0x49, 0x49, 0x30],
  '7': [0x01, 0x71, 0x09, 0x05, 0x03],
  '8': [0x36, 0x49, 0x49, 0x49, 0x36],
  '9': [0x06, 0x49, 0x49, 0x29, 0x1e],
  ':': [0x00, 0x36, 0x36, 0x00, 0x00],
  ';': [0x00, 0x56, 0x36, 0x00, 0x00],
  '<': [0x08, 0x14, 0x22, 0x41, 0x00],
  '=': [0x14, 0x14, 0x14, 0x14, 0x14],
  '>': [0x00, 0x41, 0x22, 0x14, 0x08],
  '?': [0x02, 0x01, 0x51, 0x09, 0x06],
  '@': [0x32, 0x49, 0x79, 0x41, 0x3e],
  'A': [0x7e, 0x11, 0x11, 0x11, 0x7e],
  'B': [0x7f, 0x49, 0x49, 0x49, 0x36],
  'C': [0x3e, 0x41, 0x41, 0x41, 0x22],
  'D': [0x7f, 0x41, 0x41, 0x22, 0x1c],
  'E': [0x7f, 0x49, 0x49, 0x49, 0x41],
  'F': [0x7f, 0x09, 0x09, 0x09, 0x01],
  'G': [0x3e, 0x41, 0x49, 0x49, 0x7a],
  'H': [0x7f, 0x08, 0x08, 0x08, 0x7f],
  'I': [0x00, 0x41, 0x7f, 0x41, 0x00],
  'J': [0x20, 0x40, 0x41, 0x3f, 0x01],
  'K': [0x7f, 0x08, 0x14, 0x22, 0x41],
  'L': [0x7f, 0x40, 0x40, 0x40, 0x40],
  'M': [0x7f, 0x02, 0x0c, 0x02, 0x7f],
  'N': [0x7f, 0x04, 0x08, 0x10, 0x7f],
  'O': [0x3e, 0x41, 0x41, 0x41, 0x3e],
  'P': [0x7f, 0x09, 0x09, 0x09, 0x06],
  'Q': [0x3e, 0x41, 0x51, 0x21, 0x5e],
  'R': [0x7f, 0x09, 0x19, 0x29, 0x46],
  'S': [0x46, 0x49, 0x49, 0x49, 0x31],
  'T': [0x01, 0x01, 0x7f, 0x01, 0x01],
  'U': [0x3f, 0x40, 0x40, 0x40, 0x3f],
  'V': [0x1f, 0x20, 0x40, 0x20, 0x1f],
  'W': [0x3f, 0x40, 0x38, 0x40, 0x3f],
  'X': [0x63, 0x14, 0x08, 0x14, 0x63],
  'Y': [0x07, 0x08, 0x70, 0x08, 0x07],
  'Z': [0x61, 0x51, 0x49, 0x45, 0x43],
  '[': [0x00, 0x7f, 0x41, 0x41, 0x00],
  '\\': [0x02, 0x04, 0x08, 0x10, 0x20],
  ']': [0x00, 0x41, 0x41, 0x7f, 0x00],
  '^': [0x04, 0x02, 0x01, 0x02, 0x04],
  '_': [0x40, 0x40, 0x40, 0x40, 0x40],
  '`': [0x00, 0x01, 0x02, 0x04, 0x00],
  'a': [0x20, 0x54, 0x54, 0x54, 0x78],
  'b': [0x7f, 0x48, 0x44, 0x44, 0x38],
  'c': [0x38, 0x44, 0x44, 0x44, 0x20],
  'd': [0x38, 0x44, 0x44, 0x48, 0x7f],
  'e': [0x38, 0x54, 0x54, 0x54, 0x18],
  'f': [0x08, 0x7e, 0x09, 0x01, 0x02],
  'g': [0x0c, 0x52, 0x52, 0x52, 0x3e],
  'h': [0x7f, 0x08, 0x04, 0x04, 0x78],
  'i': [0x00, 0x44, 0x7d, 0x40, 0x00],
  'j': [0x20, 0x40, 0x44, 0x3d, 0x00],
  'k': [0x7f, 0x10, 0x28, 0x44, 0x00],
  'l': [0x00, 0x41, 0x7f, 0x40, 0x00],
  'm': [0x7c, 0x04, 0x18, 0x04, 0x78],
  'n': [0x7c, 0x08, 0x04, 0x04, 0x78],
  'o': [0x38, 0x44, 0x44, 0x44, 0x38],
  'p': [0x7c, 0x14, 0x14, 0x14, 0x08],
  'q': [0x08, 0x14, 0x14, 0x18, 0x7c],
  'r': [0x7c, 0x08, 0x04, 0x04, 0x08],
  's': [0x48, 0x54, 0x54, 0x54, 0x20],
  't': [0x04, 0x3f, 0x44, 0x40, 0x20],
  'u': [0x3c, 0x40, 0x40, 0x20, 0x7c],
  'v': [0x1c, 0x20, 0x40, 0x20, 0x1c],
  'w': [0x3c, 0x40, 0x30, 0x40, 0x3c],
  'x': [0x44, 0x28, 0x10, 0x28, 0x44],
  'y': [0x0c, 0x50, 0x50, 0x50, 0x3c],
  'z': [0x44, 0x64, 0x54, 0x4c, 0x44],
  '{': [0x00, 0x08, 0x36, 0x41, 0x00],
  '|': [0x00, 0x00, 0x7f, 0x00, 0x00],
  '}': [0x00, 0x41, 0x36, 0x08, 0x00],
  '~': [0x10, 0x08, 0x08, 0x10, 0x08],
  '\x7f': [0x00, 0x7e, 0x42, 0x42, 0x7e],
}

ORIGINAL_CUSTOM = FONT['\x7f']


def bit_reverse(value, width=8):
  result = 0
  for _ in xrange(width):
    result = (result << 1) | (value & 1)
    value >>= 1

  return result


BITREVERSE = map(bit_reverse, xrange(256))

spi = spidev.SpiDev()

def setup():
  # Set pin directions.
  wiringpi.wiringPiSetup()
  for pin in [DC, RST]:
    wiringpi.pinMode(pin, ON)

  wiringpi.pinMode(LED,2)
  wiringpi.pwmWrite(LED,128)

  spi.open(0,0)
  spi.max_speed_hz=5000000


def lcd_cmd(value):
  wiringpi.digitalWrite(DC, OFF)
  spi.writebytes([value])


def lcd_data(value):
  wiringpi.digitalWrite(DC, ON)
  spi.writebytes([value])


def gotoxy(x, y):
  wiringpi.digitalWrite(DC, OFF)
  spi.writebytes([x+128,y+64])


def cls():
  gotoxy(0, 0)
  wiringpi.digitalWrite(DC, ON)
  spi.writebytes(CLSBUF)
  


def begin(contrast):
  setup()
  # Toggle RST low to reset.
  wiringpi.digitalWrite(RST, OFF)
  wiringpi.digitalWrite(LED, ON)
  time.sleep(0.100)
  wiringpi.digitalWrite(RST, ON)
  # Extended mode, bias, vop, basic mode, non-inverted display.
  wiringpi.digitalWrite(DC, OFF)
  spi.writebytes([0x21, 0x14, contrast, 0x20, 0x0c])
  # cls()

def init():
  begin(CONTRAST)


def led(led_value):
  wiringpi.pwmWrite(LED,led_value)


def load_bitmap(filename, reverse=False):
  mask = 0xff if reverse else 0x00
  gotoxy(0, 0)
  with open(filename, 'rb') as bitmap_file:
    for x in xrange(6):
      for y in xrange(84):
        bitmap_file.seek(0x3e + y * 8 + x)
        lcd_data(BITREVERSE[ord(bitmap_file.read(1))] ^ mask)


def show_custom(font=FONT):
  display_char('\x7f', font)


def define_custom(values):
  FONT['\x7f'] = values


def restore_custom():
  define_custom(ORIGINAL_CUSTOM)


def alt_custom():
  define_custom([0x00, 0x50, 0x3C, 0x52, 0x44])


def pi_custom():
  define_custom([0x19, 0x25, 0x5A, 0x25, 0x19])


def display_char(char, font=FONT):
  try:
    wiringpi.digitalWrite(DC, ON)
    spi.writebytes(font[char]+[0])

  except KeyError:
    pass # Ignore undefined characters.


def text(string, font=FONT):
  for char in string:
    display_char(char, font)


def gotorc(r, c):
  lcd_cmd(c * 6 + 128)
  lcd_cmd(r + 64)


def centre_word(r, word):
  gotorc(r, max(0, (COLUMNS - len(word)) // 2))
  text(word)

def put_image(im):
  # Rotate and mirror the image
  rim = im.rotate(-90).transpose(Image.FLIP_LEFT_RIGHT)

  # Change display to vertical write mode for graphics
  wiringpi.digitalWrite(DC, OFF)
  spi.writebytes([0x22])

  # Start at upper left corner
  gotoxy(0, 0)
  # Put on display with reversed bit order
  wiringpi.digitalWrite(DC, ON)
  spi.writebytes( [ BITREVERSE[ord(x)] for x in list(rim.tostring()) ] )

  # Switch back to horizontal write mode for text
  wiringpi.digitalWrite(DC, OFF)
  spi.writebytes([0x20])


def main():
 start, end = 32, 116
 print 'LCD Display Test: ASCII %d to %d' % (start, end)
 # do not include init() in the timing tests
 init()
 while 1:
  start_time = time.time()
  cls()
  led(768)
  for i in xrange(start, end):
    display_char(chr(i))
    
  finish_time = time.time()
  print 'Cls, LED on, %d chars, total time = %.3f' % (
    end - start, finish_time - start_time
    )
  print

  time.sleep(1)

  # Test a custom character for 0x7f (supposed to be a bell)
  # . . . - - - - -
  # . . . - - X - -
  # . . . - X X X -
  # . . . - X - X -
  # . . . X - - - X
  # . . . X X X X X
  # . . . - - X X -
  # . . . - - - - -
  define_custom([0x30,0x2c,0x66,0x6c,0x30])

  cls()
  text("\x7f \x7f \x7f \x7f \x7f \x7f \x7f ")
  text("    Hello     ")
  text(" Raspberry Pi")

  # Backlight PWM testing -- off -> 25% -> off
  #for i in range(0,255):
  #  led(i)
  #  time.sleep(0.025)
  #for i in range(255,0,-1):
  #  led(i)
  #  time.sleep(0.025)

  time.sleep(1)

  ## Generate an image with PIL and put on the display
  ## First time through is slow as the fonts are not cached
  ##
  start_time = time.time()
  # load an available True Type font
  font = ImageFont.truetype("/usr/share/fonts/truetype/freefont/FreeSansBold.ttf", 14)

  # New b-w image
  im = Image.new('1', (84,48))
  # New drawable on image
  draw = ImageDraw.Draw(im)
  # Full screen and half-screen ellipses
  draw.ellipse((0,0,im.size[0]-1,im.size[1]-1), outline=1)
  draw.ellipse((im.size[0]/4,im.size[1]/4,im.size[0]/4*3-1,im.size[1]/4*3-1), outline=1)
  # Some simple text for a test (first with TT font, second with default
  draw.text((10,10), "hello", font=font, fill=1)
  draw.text((10,24), "world", fill=1)
  # Check what happens when text exceeds width (clipped)
  draw.text((0,0), "ABCabcDEFdefGHIghi", fill=1)
  # Copy it to the display
  put_image(im)
  # clean up
  del draw
  del im

  finish_time = time.time()
  print 'PIL Drawing, total time = %.3f' % (
    finish_time - start_time
    )
  print

  time.sleep(1)
  # Dim the LED...
  #led(64)

  # To loop continuously, remove the break
  #break

if __name__ == '__main__':
  main()
You may need to update the pin assignments to match your configuration. When you run the code, it will cycle between three screens and print timing information. The first is the text dump as originally in the code. The second is a test of the custom characters on the first row. The third is a simple graphic with text from PIL.

Maybe it will be of some use...

Enjoy!
Bill

User avatar
malakai
Posts: 1382
Joined: Sat Sep 15, 2012 10:35 am

Re: Nokia Pi LCD

Tue Jan 15, 2013 11:56 pm

Very interested in this but I am getting an error any help where I went wrong?

Code: Select all

sudo apt-get install python-imaging python-imaging-tk
sudo apt-get install python-pip
sudo pip install wiringpi
sudo pip install spidev

Code: Select all

sudo ./lcdtest.py
LCD Display Test: ASCII 32 to 116
Traceback (most recent call last):
  File "./lcdtest.py", line 368, in <module>
    main()
  File "./lcdtest.py", line 287, in main
    init()
  File "./lcdtest.py", line 204, in init
    begin(CONTRAST)
  File "./lcdtest.py", line 192, in begin
    setup()
  File "./lcdtest.py", line 165, in setup
    spi.open(0,0)
IOError: [Errno 2] No such file or directory
http://www.raspians.com - always looking for content feel free to ask to have it posted. Or sign up and message me to become a contributor to the site. Raspians is not affiliated with the Raspberry Pi Foundation. (RPi's + You = Raspians)

User avatar
bgreat
Posts: 235
Joined: Mon Jan 23, 2012 2:09 pm

Re: Nokia Pi LCD

Wed Jan 16, 2013 12:31 am

Try running using:

Code: Select all

sudo python ./lcdtest.py
If that works, make it executable and try running:

Code: Select all

> chmod +x lcdtest.py
> sudo ./lcdtest.py
Enjoy!
Bill

User avatar
alexeames
Forum Moderator
Forum Moderator
Posts: 2876
Joined: Sat Mar 03, 2012 11:57 am
Location: UK

Re: Nokia Pi LCD

Wed Jan 16, 2013 9:20 am

malakai wrote:Very interested in this but I am getting an error any help where I went wrong?
Have you enabled spi? Once you've done it, it's easy to forget it's needed :lol:

Code: Select all

sudo nano /etc/modprobe.d/raspi-blacklist.conf
make sure there IS a # before blacklist spi-bcm2708, so it looks like this...

Code: Select all

#blacklist spi-bcm2708
Alex Eames RasPi.TV, RasP.iO

Rusakko
Posts: 35
Joined: Fri Dec 14, 2012 6:18 pm

Re: Nokia Pi LCD

Wed Jan 16, 2013 10:56 am

As mentioned I got text working and now I have IP address, free disk space and uptime on the display.
Then I tried to show bmp on the display but failed. I used code from texy's post and created bmp of my own. It should be 84x48 and monochrome. Made it with convert command from jpg. Display changed but showed only 4 lines, no image. Any idea why so?

texy
Forum Moderator
Forum Moderator
Posts: 5174
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: Nokia Pi LCD

Wed Jan 16, 2013 11:17 am

I used Windows Paint to create the file. Load you image (whatever format supported by Paint), alter the resolution to 48 x 84, tweak image as neccessary :) and then save the file as Monochrome Bitmap (if I remember correctly). So I didn't use a 'convertor program' as such.
Hope this helps.
Texy

PS can you post your code showing ip address, etc please. It may be useful for others ;)
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

Rusakko
Posts: 35
Joined: Fri Dec 14, 2012 6:18 pm

Re: Nokia Pi LCD

Wed Jan 16, 2013 11:37 am

Sure I will post those lines later today. I will also try to create new image with paint. I'll get back on this today.

User avatar
bgreat
Posts: 235
Joined: Mon Jan 23, 2012 2:09 pm

Re: Nokia Pi LCD

Wed Jan 16, 2013 12:41 pm

I misread your previous error post, so my chmod suggestion was nonsense in your case. :oops: Getting spidev module loaded is the key.

The same BMP code is in the version I posted. I used Paint in windows to make a B/W BMP and it worked as expected. I loaded an image in paint, changed the image to the correct size and converted it to a monochrome BMP. Doing it this way it is possible to see on Windows how it may appear on the LCD.

I'm still playing with it, but you can also use PIL to load, resize, and convert the image in Python within your program. Then display the image using the put_image() function in the code I posted. If the image is not monochrome, PIL can dither the image making it almost recognizable. To preserve the image aspect ratio use PIL.Image.thumbnail() instead of PIL.Image.resize().

Enjoy!
Bill

Rusakko
Posts: 35
Joined: Fri Dec 14, 2012 6:18 pm

Re: Nokia Pi LCD

Wed Jan 16, 2013 2:20 pm

I got images working. Paint is the keyword. Little bit disapointed, I should be able to use raspberry for creating images. Have to study more.

Then the code for IP, free space and uptime

Code: Select all

import commands
import os

  iposoite = commands.getoutput("/sbin/ifconfig").split("\n")[1].split()[1][5:]
  gotorc(3,0)
  text(iposoite)
  levytila = os.statvfs('/')
  levytila = levytila.f_bavail * levytila.f_frsize /1024000
  gotorc(4,0)
  levytila = "Free: %s Mb" %(levytila)
  text(levytila)
  up = "UP: %s." %(commands.getoutput("uptime").split()[2].replace(',',''))
  gotorc(5,0)
  text(up)
I don't know if this is the most elegant way but it works. Just add import lines at the beginning and rest of the stuff in main. Ip gets the ip-address, levytila gets the free disk space in sd card and finally up gets the uptime. There is also room for development, if raspberry is not connected to internet ip will print out "cast".

-rst-
Posts: 1317
Joined: Thu Nov 01, 2012 12:12 pm
Location: Dublin, Ireland

Re: Nokia Pi LCD

Wed Jan 16, 2013 3:34 pm

Rusakko wrote:I don't know if this is the most elegant way but it works. Just add import lines at the beginning and rest of the stuff in main. Ip gets the ip-address, levytila gets the free disk space in sd card and finally up gets the uptime. There is also room for development, if raspberry is not connected to internet ip will print out "cast".
Chaining commands ('getoutput(...).split(...).split(...)') is not the most readable and re-using the same variable to store different datatypes ('levytila' first struct -> integer -> string) is error-prone in anything bigger, but that's mostly 'pilkunnussimista' (nitpicking ;) ) and basically looks fine ...oh yeah, maybe majority of the reader-base would appreciate English variable names instead of Finnish :mrgreen:
http://raspberrycompote.blogspot.com/ - Low-level graphics and 'Coding Gold Dust'

Rusakko
Posts: 35
Joined: Fri Dec 14, 2012 6:18 pm

Re: Nokia Pi LCD

Wed Jan 16, 2013 3:39 pm

Sorry about variable names :D had to leave work and wanted to post thi first so I didn't have time to modify it. And you are correct it's not the most readable and I should not use same variables but all the same, it works :)

User avatar
bgreat
Posts: 235
Joined: Mon Jan 23, 2012 2:09 pm

Re: Nokia Pi LCD

Wed Jan 16, 2013 4:06 pm

Here is my first cut at turning the original code with additions into a Python class. It is incomplete as I am still working on making it more generic, but I do have a demonstration of using PIL to load an image with resize then threshold or dither for display. I am still experimenting, but it should also work with any ImageMagick converted BMP file. Please try it and let me know.

nokiaSPI.py

Code: Select all

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# code improvements
#  9/10/12
######
# WGG - picked up from Raspberry Pi forums and modified with a heavy hand
# -- added spidev support
# -- testing with PIL
# 16-Jan-2013
# -- initial NokiaSPI class

import time
import wiringpi
import spidev
from PIL import Image,ImageDraw,ImageFont

# White backlight
#CONTRAST = 0xa4

# Blue backlight
CONTRAST = 0xa4

ROWS = 6
COLUMNS = 14
PIXELS_PER_ROW = 6
ON = 1
OFF = 0

#gpio's :
DC   = 3 # gpio pin 15 = wiringpi no. 3 (BCM 22)
RST  = 0 # gpio pin 11 = wiringpi no. 0 (BCM 17)
LED  = 1 # gpio pin 12 = wiringpi no. 1 (BCM 18)

# SPI connection
SCE  = 10 # gpio pin 24 = wiringpi no. 10 (CE0 BCM 8)
SCLK = 14 # gpio pin 23 = wiringpi no. 14 (SCLK BCM 11)
DIN  = 12 # gpio pin 19 = wiringpi no. 12 (MOSI BCM 10)

CLSBUF=[0]*(ROWS * COLUMNS * PIXELS_PER_ROW)

FONT = {
  ' ': [0x00, 0x00, 0x00, 0x00, 0x00],
  '!': [0x00, 0x00, 0x5f, 0x00, 0x00],
  '"': [0x00, 0x07, 0x00, 0x07, 0x00],
  '#': [0x14, 0x7f, 0x14, 0x7f, 0x14],
  '$': [0x24, 0x2a, 0x7f, 0x2a, 0x12],
  '%': [0x23, 0x13, 0x08, 0x64, 0x62],
  '&': [0x36, 0x49, 0x55, 0x22, 0x50],
  "'": [0x00, 0x05, 0x03, 0x00, 0x00],
  '(': [0x00, 0x1c, 0x22, 0x41, 0x00],
  ')': [0x00, 0x41, 0x22, 0x1c, 0x00],
  '*': [0x14, 0x08, 0x3e, 0x08, 0x14],
  '+': [0x08, 0x08, 0x3e, 0x08, 0x08],
  ',': [0x00, 0x50, 0x30, 0x00, 0x00],
  '-': [0x08, 0x08, 0x08, 0x08, 0x08],
  '.': [0x00, 0x60, 0x60, 0x00, 0x00],
  '/': [0x20, 0x10, 0x08, 0x04, 0x02],
  '0': [0x3e, 0x51, 0x49, 0x45, 0x3e],
  '1': [0x00, 0x42, 0x7f, 0x40, 0x00],
  '2': [0x42, 0x61, 0x51, 0x49, 0x46],
  '3': [0x21, 0x41, 0x45, 0x4b, 0x31],
  '4': [0x18, 0x14, 0x12, 0x7f, 0x10],
  '5': [0x27, 0x45, 0x45, 0x45, 0x39],
  '6': [0x3c, 0x4a, 0x49, 0x49, 0x30],
  '7': [0x01, 0x71, 0x09, 0x05, 0x03],
  '8': [0x36, 0x49, 0x49, 0x49, 0x36],
  '9': [0x06, 0x49, 0x49, 0x29, 0x1e],
  ':': [0x00, 0x36, 0x36, 0x00, 0x00],
  ';': [0x00, 0x56, 0x36, 0x00, 0x00],
  '<': [0x08, 0x14, 0x22, 0x41, 0x00],
  '=': [0x14, 0x14, 0x14, 0x14, 0x14],
  '>': [0x00, 0x41, 0x22, 0x14, 0x08],
  '?': [0x02, 0x01, 0x51, 0x09, 0x06],
  '@': [0x32, 0x49, 0x79, 0x41, 0x3e],
  'A': [0x7e, 0x11, 0x11, 0x11, 0x7e],
  'B': [0x7f, 0x49, 0x49, 0x49, 0x36],
  'C': [0x3e, 0x41, 0x41, 0x41, 0x22],
  'D': [0x7f, 0x41, 0x41, 0x22, 0x1c],
  'E': [0x7f, 0x49, 0x49, 0x49, 0x41],
  'F': [0x7f, 0x09, 0x09, 0x09, 0x01],
  'G': [0x3e, 0x41, 0x49, 0x49, 0x7a],
  'H': [0x7f, 0x08, 0x08, 0x08, 0x7f],
  'I': [0x00, 0x41, 0x7f, 0x41, 0x00],
  'J': [0x20, 0x40, 0x41, 0x3f, 0x01],
  'K': [0x7f, 0x08, 0x14, 0x22, 0x41],
  'L': [0x7f, 0x40, 0x40, 0x40, 0x40],
  'M': [0x7f, 0x02, 0x0c, 0x02, 0x7f],
  'N': [0x7f, 0x04, 0x08, 0x10, 0x7f],
  'O': [0x3e, 0x41, 0x41, 0x41, 0x3e],
  'P': [0x7f, 0x09, 0x09, 0x09, 0x06],
  'Q': [0x3e, 0x41, 0x51, 0x21, 0x5e],
  'R': [0x7f, 0x09, 0x19, 0x29, 0x46],
  'S': [0x46, 0x49, 0x49, 0x49, 0x31],
  'T': [0x01, 0x01, 0x7f, 0x01, 0x01],
  'U': [0x3f, 0x40, 0x40, 0x40, 0x3f],
  'V': [0x1f, 0x20, 0x40, 0x20, 0x1f],
  'W': [0x3f, 0x40, 0x38, 0x40, 0x3f],
  'X': [0x63, 0x14, 0x08, 0x14, 0x63],
  'Y': [0x07, 0x08, 0x70, 0x08, 0x07],
  'Z': [0x61, 0x51, 0x49, 0x45, 0x43],
  '[': [0x00, 0x7f, 0x41, 0x41, 0x00],
  '\\': [0x02, 0x04, 0x08, 0x10, 0x20],
  ']': [0x00, 0x41, 0x41, 0x7f, 0x00],
  '^': [0x04, 0x02, 0x01, 0x02, 0x04],
  '_': [0x40, 0x40, 0x40, 0x40, 0x40],
  '`': [0x00, 0x01, 0x02, 0x04, 0x00],
  'a': [0x20, 0x54, 0x54, 0x54, 0x78],
  'b': [0x7f, 0x48, 0x44, 0x44, 0x38],
  'c': [0x38, 0x44, 0x44, 0x44, 0x20],
  'd': [0x38, 0x44, 0x44, 0x48, 0x7f],
  'e': [0x38, 0x54, 0x54, 0x54, 0x18],
  'f': [0x08, 0x7e, 0x09, 0x01, 0x02],
  'g': [0x0c, 0x52, 0x52, 0x52, 0x3e],
  'h': [0x7f, 0x08, 0x04, 0x04, 0x78],
  'i': [0x00, 0x44, 0x7d, 0x40, 0x00],
  'j': [0x20, 0x40, 0x44, 0x3d, 0x00],
  'k': [0x7f, 0x10, 0x28, 0x44, 0x00],
  'l': [0x00, 0x41, 0x7f, 0x40, 0x00],
  'm': [0x7c, 0x04, 0x18, 0x04, 0x78],
  'n': [0x7c, 0x08, 0x04, 0x04, 0x78],
  'o': [0x38, 0x44, 0x44, 0x44, 0x38],
  'p': [0x7c, 0x14, 0x14, 0x14, 0x08],
  'q': [0x08, 0x14, 0x14, 0x18, 0x7c],
  'r': [0x7c, 0x08, 0x04, 0x04, 0x08],
  's': [0x48, 0x54, 0x54, 0x54, 0x20],
  't': [0x04, 0x3f, 0x44, 0x40, 0x20],
  'u': [0x3c, 0x40, 0x40, 0x20, 0x7c],
  'v': [0x1c, 0x20, 0x40, 0x20, 0x1c],
  'w': [0x3c, 0x40, 0x30, 0x40, 0x3c],
  'x': [0x44, 0x28, 0x10, 0x28, 0x44],
  'y': [0x0c, 0x50, 0x50, 0x50, 0x3c],
  'z': [0x44, 0x64, 0x54, 0x4c, 0x44],
  '{': [0x00, 0x08, 0x36, 0x41, 0x00],
  '|': [0x00, 0x00, 0x7f, 0x00, 0x00],
  '}': [0x00, 0x41, 0x36, 0x08, 0x00],
  '~': [0x10, 0x08, 0x08, 0x10, 0x08],
  '\x7f': [0x00, 0x7e, 0x42, 0x42, 0x7e],
}

ORIGINAL_CUSTOM = FONT['\x7f']

def bit_reverse(value, width=8):
  result = 0
  for _ in xrange(width):
    result = (result << 1) | (value & 1)
    value >>= 1

  return result

BITREVERSE = map(bit_reverse, xrange(256))

class NokiaSPI:
    def __init__(self, dev=(0,0),speed=5000000, brightness=256, contrast=CONTRAST):
        self.spi = spidev.SpiDev()
        self.speed = speed
        self.dev = dev
        self.spi.open(self.dev[0],self.dev[1])
        self.spi.max_speed_hz=self.speed

        # Set pin directions.
        self.dc = DC
        self.rst = RST
        wiringpi.wiringPiSetup()
        for pin in [self.dc, self.rst]:
            wiringpi.pinMode(pin, 1)

        self.contrast=contrast
        self.brightness=brightness
        
        # Toggle RST low to reset.
        wiringpi.digitalWrite(self.rst, OFF)
        time.sleep(0.100)
        wiringpi.digitalWrite(self.rst, ON)
        # Extended mode, bias, vop, basic mode, non-inverted display.
        wiringpi.digitalWrite(self.dc, OFF)
        self.spi.writebytes([0x21, 0x14, self.contrast, 0x20, 0x0c])
        # cls()

        self.ledpin = LED
        if self.ledpin == 1:
            wiringpi.pinMode(self.ledpin, 2)
            wiringpi.pwmWrite(self.ledpin, self.brightness)
        else:
            wiringpi.pinMode(self.ledpin, 1)
            wiringpi.digitalWrite(self.ledpin, ON)



    def lcd_cmd(self,value):
        wiringpi.digitalWrite(self.dc, OFF)
        self.spi.writebytes([value])


    def lcd_data(self,value):
        wiringpi.digitalWrite(self.dc, ON)
        self.spi.writebytes([value])


    def gotoxy(self, x, y):
        wiringpi.digitalWrite(self.dc, OFF)
        self.spi.writebytes([x+128,y+64])


    def cls(self):
        self.gotoxy(0, 0)
        wiringpi.digitalWrite(self.dc, ON)
        self.spi.writebytes(CLSBUF)


    def led(self, led_value):
        if self.ledpin == 1:
            wiringpi.pwmWrite(self.ledpin,led_value)
        else:
            if led_value == 0:
                wiringpi.digitalWrite(self.ledpin, OFF)
            else:
                wiringpi.digitalWrite(self.ledpin, ON)


    def load_bitmap(self, filename, reverse=False):
        mask = 0xff if reverse else 0x00
        self.gotoxy(0, 0)
        with open(filename, 'rb') as bitmap_file:
            for x in xrange(6):
              for y in xrange(84):
                bitmap_file.seek(0x3e + y * 8 + x)
                self.lcd_data(BITREVERSE[ord(bitmap_file.read(1))] ^ mask)


    def show_custom(self, font=FONT):
        self.display_char('\x7f', font)


    def define_custom(self, values):
        FONT['\x7f'] = values


    def restore_custom(self):
        self.define_custom(ORIGINAL_CUSTOM)


    def alt_custom(self):
        self.define_custom([0x00, 0x50, 0x3C, 0x52, 0x44])


    def pi_custom(self):
        self.define_custom([0x19, 0x25, 0x5A, 0x25, 0x19])


    def display_char(self, char, font=FONT):
        try:
            wiringpi.digitalWrite(self.dc, ON)
            self.spi.writebytes(font[char]+[0])

        except KeyError:
            pass # Ignore undefined characters.


    def text(self, string, font=FONT):
        for char in string:
            self.display_char(char, font)


    def gotorc(self, r, c):
        self.gotoxy(c*6,r)


    def centre_word(self, r, word):
        self.gotorc(r, max(0, (COLUMNS - len(word)) // 2))
        self.text(word)

    def show_image(self,im):
        # Rotate and mirror the image
        rim = im.rotate(-90).transpose(Image.FLIP_LEFT_RIGHT)

        # Change display to vertical write mode for graphics
        wiringpi.digitalWrite(DC, OFF)
        self.spi.writebytes([0x22])

        # Start at upper left corner
        self.gotoxy(0, 0)
        # Put on display with reversed bit order
        wiringpi.digitalWrite(DC, ON)
        self.spi.writebytes( [ BITREVERSE[ord(x)] for x in list(rim.tostring()) ] )

        # Switch back to horizontal write mode for text
        wiringpi.digitalWrite(DC, OFF)
        self.spi.writebytes([0x20])

if __name__ == '__main__':
    start, end = 32, 116
    print 'LCD Display Test: ASCII %d to %d' % (start, end)
    # do not include init() in the timing tests
    ## init()
    noki = NokiaSPI()
    start_time = time.time()
    noki.cls()
    noki.led(768)
    for i in xrange(start, end):
        noki.display_char(chr(i))

    finish_time = time.time()
    print 'Cls, LED on, %d chars, total time = %.3f' % (
        end - start, finish_time - start_time
        )

    time.sleep(1)

    # Test a custom character for 0x7f (supposed to be a bell)
    # . . . - - - - -
    # . . . - - X - -
    # . . . - X X X -
    # . . . - X - X -
    # . . . X - - - X
    # . . . X X X X X
    # . . . - - X X -
    # . . . - - - - -
    noki.define_custom([0x30,0x2c,0x66,0x6c,0x30])

    noki.cls()
    noki.text("\x7f \x7f \x7f \x7f \x7f \x7f \x7f ")
    noki.text("    Hello     ")
    noki.text(" Raspberry Pi")

    # Backlight PWM testing -- off -> 25% -> off
    #for i in range(0,255):
    #  noki.led(i)
    #  time.sleep(0.025)
    #for i in range(255,0,-1):
    #  noki.led(i)
    #  time.sleep(0.025)

    time.sleep(1)

    ## Generate an image with PIL and put on the display
    ## First time through is slow as the fonts are not cached
    ##
    start_time = time.time()
    # load an available True Type font
    font = ImageFont.truetype("/usr/share/fonts/truetype/freefont/FreeSansBold.ttf", 14)

    # New b-w image
    im = Image.new('1', (84,48))
    # New drawable on image
    draw = ImageDraw.Draw(im)
    # Full screen and half-screen ellipses
    draw.ellipse((0,0,im.size[0]-1,im.size[1]-1), outline=1)
    draw.ellipse((im.size[0]/4,im.size[1]/4,im.size[0]/4*3-1,im.size[1]/4*3-1), outline=1)
    # Some simple text for a test (first with TT font, second with default
    draw.text((10,10), "hello", font=font, fill=1)
    draw.text((10,24), "world", fill=1)
    # Check what happens when text exceeds width (clipped)
    draw.text((0,0), "ABCabcDEFdefGHIghi", fill=1)
    # Copy it to the display
    noki.show_image(im)
    # clean up
    del draw
    del im

    finish_time = time.time()
    print 'PIL Drawing, total time = %.3f' % (finish_time - start_time)
You can run nokiaSPI.py and see a simple test.

Here is another Python file for load_bitmap() and PIL image loading, resize, display, and threshold.

raspiLCD.py

Code: Select all

#!/usr/bin/python
# Quick test for nokiaSPI class with images

import time

import nokiaSPI

from PIL import Image,ImageDraw,ImageFont


noki = nokiaSPI.NokiaSPI()

start_time = time.time()
noki.load_bitmap("raspi.bmp")
finish_time = time.time()
print 'BMP Load, total time = %.3f' % (finish_time - start_time)

time.sleep(1)

start_time = time.time()
noki.load_bitmap("raspi.bmp", True)
finish_time = time.time()
print 'BMP Load, total time = %.3f' % (finish_time - start_time)

time.sleep(1)

start_time = time.time()
noki.load_bitmap("raspi.bmp")
finish_time = time.time()
print 'BMP Load, total time = %.3f' % (finish_time - start_time)

time.sleep(1)

start_time = time.time()
noki.load_bitmap("raspi.bmp", True)
finish_time = time.time()
print 'BMP Load, total time = %.3f' % (finish_time - start_time)

time.sleep(1)

# Let's try some image manipulation
#start_time = time.time()
im = Image.open("lenna.png")
im = im.convert("L")
im.thumbnail((84,48))
for t in range(1,255):
    tim = im.point(lambda p: p > t and 255, "1")
    noki.cls()
    noki.show_image(tim)
    noki.gotorc(0,8)
    noki.text("Thresh:")
    noki.gotorc(1,10)
    noki.text("%3d" % t)
    time.sleep(0.01)
    del tim

#finish_time = time.time()
#print 'PIL Image, total time = %.3f' % (finish_time - start_time)

# Let's try some image manipulation
start_time = time.time()
im = Image.open("lenna.png")
#im = im.resize((84,48))
im.thumbnail((84,48))
im = im.convert("1")
noki.cls()
noki.show_image(im)
noki.gotorc(0,8)
noki.text("Dither")

finish_time = time.time()
print 'PIL Image, total time = %.3f' % (finish_time - start_time)
The forum will not let me attach the BMP or PNG I am using for testing, so I have uploaded them on my server and posted the links below.

raspi.bmp
Image
lenna.png
Image
Note: I used the large color image specifically for testing the PIL and image performance.

Please try this and let me know if it works for you.

Enjoy!
Bill

User avatar
malakai
Posts: 1382
Joined: Sat Sep 15, 2012 10:35 am

Re: Nokia Pi LCD

Wed Jan 16, 2013 7:28 pm

Doh! thanks yes it was the spi-bcm2708 not commented out. Too many SD Card images.

When I run it I get a white screen.

My pins are a bit different so this is what I have:

Code: Select all

#gpio's :
DC   = 3 # gpio pin 15 = wiringpi no. 3 (BCM 22)
RST  = 0 # gpio pin 11 = wiringpi no. 0 (BCM 17)
LED  = 1 # gpio pin 12 = wiringpi no. 1 (BCM 18)

# SPI connection
SCE  = 2 # gpio pin 24 = wiringpi no. 21
SCLK = 5 # gpio pin 23 = wiringpi no. 24
DIN  = 4 # gpio pin 19 = wiringpi no. 23
And the contrast CONTRAST = 0xa4
works best for the display I have.

I get no errors now when I run any of the scripts but it won't display on screen? I am lost last time this happened I had to change contrast but 0xa4 is what worked with all the other sample codes so that's weird.?

I have tested the raspi.bmp image and it loads with an earlier example from Texy
http://www.raspians.com - always looking for content feel free to ask to have it posted. Or sign up and message me to become a contributor to the site. Raspians is not affiliated with the Raspberry Pi Foundation. (RPi's + You = Raspians)

Cromarty
Posts: 64
Joined: Thu Jan 03, 2013 5:03 pm
Location: Godalming, South-east UK

Re: Nokia Pi LCD

Wed Jan 16, 2013 7:43 pm

Hello. What are the model numbers of these screen? Is catching gestures as easy as it sounds to make graphics?
--
Michael Ray
Analyst/Programmer
Surrey, UK
4xB, 1xB+,
Creator and admin of:
[email protected]
Ham radio call: G4XBF
'Suddenly I am become death, destroyer of SD cards'

User avatar
bgreat
Posts: 235
Joined: Mon Jan 23, 2012 2:09 pm

Re: Nokia Pi LCD

Wed Jan 16, 2013 8:00 pm

To use hardware SPI (required by my class file/examples), you must use the SPI pins. The SCLK and DIN are required as defined. The only optional connection is SCE which I have connected to CE0. You can use CE1 if you update the defaults or pass 'dev=(0,1)' to the class initializer.

Code: Select all

# SPI connection
SCE  = 10 # gpio pin 24 = wiringpi no. 10 (CE0 BCM 8)
SCLK = 14 # gpio pin 23 = wiringpi no. 14 (SCLK BCM 11)
DIN  = 12 # gpio pin 19 = wiringpi no. 12 (MOSI BCM 10)
The other code examples posted on the forum use software bit banging to emulate an SPI interface. My goal with this class was for hardware SPI support. This is faster and it should have less processor overhead.

I did put some intelligence in my code to recognize if the LED was not connected to the PWM, but nothing equivalent for the SPI connection. Maybe I'll go back this weekend and but some more intelligence in the code... :idea:

So, to use my example class, you must connect DIN and SCLK as is currently in the code. SCE can be connected to CE0 or CE1 (with appropriate change to code/call).

Enjoy!
Bill

User avatar
malakai
Posts: 1382
Joined: Sat Sep 15, 2012 10:35 am

Re: Nokia Pi LCD

Wed Jan 16, 2013 8:49 pm

Sweet thanks a couple jumper wires and I'm in business. That code is slick. Love the image effects.

Thanks all so much :) well worth all the head banging on my desk
http://www.raspians.com - always looking for content feel free to ask to have it posted. Or sign up and message me to become a contributor to the site. Raspians is not affiliated with the Raspberry Pi Foundation. (RPi's + You = Raspians)

User avatar
williamhbell
Posts: 291
Joined: Mon Dec 26, 2011 5:13 pm

Re: Nokia Pi LCD

Wed Jan 16, 2013 8:53 pm

bgreat wrote:In case you want to use SPI instead of bit banging the communication, I would use the following pins:

CE -- pin 24 (SPI_CE0) or pin 26 (SPI_CE1)
DIN -- pin 19 (SPI_MOSI)
CLK -- pin 23 (SPI_SCLK)
LED -- pin 12 (PWM0) to allow varying the brightness, otherwise any free GPIO
RST -- pin 8, otherwise any free GPIO
DC -- pin 10, otherwise any free GPIO
VCC -- pin 1 (3v3)
GND -- whichever pin is convenient
Hi Bill,

Would it be possible to confirm which Nokia board you are using? Would it be correct to assume your CE pin is the CS pin on,
http://www.adafruit.com/products/338
Image

?

Thanks and best regards,

Will

User avatar
williamhbell
Posts: 291
Joined: Mon Dec 26, 2011 5:13 pm

Re: Nokia Pi LCD

Wed Jan 16, 2013 9:33 pm

Adafruit refers to: CS = chip select

whereas
Sparkfun calls it CE = chip enable
https://www.sparkfun.com/products/10168

and the Philips PCD8544 data sheet calls it
SCE: CHIP ENABLE
The enable pin allows data to be clocked in. The signal is active LOW.

User avatar
bgreat
Posts: 235
Joined: Mon Jan 23, 2012 2:09 pm

Re: Nokia Pi LCD

Wed Jan 16, 2013 11:21 pm

I have two Hong Kong specials (one white backlight and one blue backlight). Less than US$3.50 each.

Here's a photo of the back side of one:
LCD_SPI_sm.jpg
SPI LCD
LCD_SPI_sm.jpg (40.42 KiB) Viewed 26594 times
Same signals, brought out in a different order with differing silk screen. The same controller chip and glass, just a different breakout board.

CS and CE are interchangeable names for the same signal.

Enjoy!
Bill
Last edited by bgreat on Wed Jan 16, 2013 11:30 pm, edited 1 time in total.

User avatar
bgreat
Posts: 235
Joined: Mon Jan 23, 2012 2:09 pm

Re: Nokia Pi LCD

Wed Jan 16, 2013 11:28 pm

malakai wrote:Sweet thanks a couple jumper wires and I'm in business. That code is slick. Love the image effects.

Thanks all so much :) well worth all the head banging on my desk
Glad you liked it. I'm still working on improvements. Just finished a font display test and some pie chart displays that are coming along. I need to spend some time now on getting pattern tiling working plus some image math for text overlays. Fun things for my spare time to help learn Python. PIL is great for what I need. No kernel recompile. No special managers. But, you have to design each element... :D

I was working on a version of Conway's Life, but it is just too slow for words with the default Python implementation I tried. Anything above a 24x24 board and the updates are glacial. After I get some more Python knowledge, I am going to tackle optimizing the performance. This could turn into a head banger for me :lol:

Enjoy!
Bill

User avatar
malakai
Posts: 1382
Joined: Sat Sep 15, 2012 10:35 am

Re: Nokia Pi LCD

Thu Jan 17, 2013 7:54 am

Just so people can see how sweet your code is here's a little YouTube video

http://youtu.be/kBHRh9dZXm0

I sent a message to 9030plc on eBay. I am using his board from http://www.Mypishop.com in the video. He may knock out a few test boards with the SPI pin outs to see how they come out. (I am still waiting on my boards from Texy I think dolphins are swimming them over :) ) I imagine if enough interest appears either may be able to stock some to use with your code.
http://www.raspians.com - always looking for content feel free to ask to have it posted. Or sign up and message me to become a contributor to the site. Raspians is not affiliated with the Raspberry Pi Foundation. (RPi's + You = Raspians)

texy
Forum Moderator
Forum Moderator
Posts: 5174
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: Nokia Pi LCD

Thu Jan 17, 2013 8:04 am

Hopefully the boards will get to you soon ;)

The work with SPI has seen fantastic improvements. Shame I,ve just sent an order for an updated pcb (with switches and as a shield rather than with ribbon cable). Maybe I can stop the order and redesign to use the SPI.
In the mean time I need to replicate the wiring and setup instructions.
cheers
Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

Rusakko
Posts: 35
Joined: Fri Dec 14, 2012 6:18 pm

Re: Nokia Pi LCD

Thu Jan 17, 2013 10:21 pm

I just got convert to work. It's like this. I have jpg images of applications in folder and I would like to show black and white image in LCD when that application is started. So how to convert those images to bmp with as little effort so possible. Imagemagick is becoming my new best friend.

Code: Select all

convert image.jpg 
-rotate 90 (if needed) 
-crop 144x252+0+0 (to get dimensions correct, first two are image width and height, and last two and place where to start the crop, dimensions should be multiples of 48x84) 
-edge 15 (try with different values to get best result) 
-thumbnail 48x84! 
-colors 2 
-type palette 
BMP3:image.bmp
So rotate to turn image to match LCD rotation.
Crop if you what only part of the image. I find it best to use on portion of the image to minimize details in the image. This way you could simply focus on one detail, like face or text.
Edge to find edges of the different colors. Value increases thickness of the edge.
And others to get correct size and colors.

Hope this helps. Of course this will work best with simple images without too much stuff in it, like logos or clipart and similar.

gastly
Posts: 2
Joined: Sat Jan 19, 2013 7:28 am

Re: Nokia Pi LCD

Sat Jan 19, 2013 7:40 am

bgreat wrote:I have two Hong Kong specials (one white backlight and one blue backlight). Less than US$3.50 each.

Here's a photo of the back side of one:
LCD_SPI_sm.jpg
Hi!
I have a similar screen for Nokia 5110 with the same pins in the same order but I can't seem to get it working :/
I wired it up exactly like it's mentioned in your code and wired the screen by using jumper cables to the GPIO directly. But when I turn the RPi on the screen doesn't turn on, no led's nothing. When running the nokiaLCD.py script I get the following error:

Code: Select all

LCD Display Test: ASCII 32 to 116
Traceback (most recent call last):
  File "nokiaLCD.py", line 296, in <module>
    noki = NokiaSPI()
  File "nokiaLCD.py", line 158, in __init__
    self.spi.open(self.dev[0],self.dev[1])
IOError: [Errno 2] No such file or directory
Clearly it's not detecting the screen :cry:
I've checked the wiring a few times but nothing works. Could it be that my screen is bad? Is there any way to test if it's bad?
I'm new to RPi and electronics in general (just know a few basics :mrgreen:) and I would appreciate any help :)

Thanks!

User avatar
malakai
Posts: 1382
Joined: Sat Sep 15, 2012 10:35 am

Re: Nokia Pi LCD

Sat Jan 19, 2013 7:58 am

Without any code if you run power to the screen the back light as far as I know should light up you would want a resistor and what is on my board is a 2n7000 mosfet I think Texy used the same mosfet.
http://www.raspians.com - always looking for content feel free to ask to have it posted. Or sign up and message me to become a contributor to the site. Raspians is not affiliated with the Raspberry Pi Foundation. (RPi's + You = Raspians)

Return to “Python”