paulie
Posts: 263
Joined: Thu Jan 19, 2012 6:51 pm

Re: Nokia Pi LCD

Sun Mar 03, 2013 10:46 pm

I have made some progress:
Loaded the file into idle, then erased the white space at the start of each line and the preceding newline, replaced the newline which restored the correct indentation.
Had enough success to run with no errors. (had to recheck wiringpi).
Program stops with ctrl-c, & reads button presses.
Backlight on & dips out when I restart.
No display of chars/bitmap despite tweaks to contrast.
Might be indents in main still chewed up....
Will try again when I have more time.
It has been my custom to use Xeyes

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

Re: Nokia Pi LCD

Mon Mar 04, 2013 7:35 am

Hi,
you shouldn't have to edit any of the indentation if you cut & paste from the listing here :
http://www.raspberrypi.org/phpBB3/viewt ... 00#p299351

You may have to adjust to CONTRAST value. If the default 0xb8 shows nothing, try 0xcf - that is way over what I have seen before, but if the screen goes black as opposed to white then it proves the system is good. You will then just need to find the value between 0xb8 and 0xcf to get an match.

Oh - and you did say that it correctly responds when you press a button, ie a 0 will change to a 1 ?
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

babbage
Posts: 123
Joined: Mon Aug 29, 2011 2:23 pm

Re: Nokia Pi LCD

Mon Mar 04, 2013 8:59 am

Morning all.
Re the comment above, I always have to remove white space when i'm posting from this board - normally end up with two spaces at least to take away. Easy enough to remove in Idle, but i'm not sure why it happens :o
I'm pretty sure I have installed SpiDev, using the following: sudo pip install spidev - that all seemed to go OK.
However, not sure about the Blacklist....haven't seen that mentioned before.
I'll search about editing the blacklist in the forum. Will it hurt if I do 'sudo pip install spidev' again ?
As always thanks for your patience and help.
Steve

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

Re: Nokia Pi LCD

Mon Mar 04, 2013 9:05 am

You should not need to re install spidev, but if the blacklist isn't sorted, then it wont work ;) . Instructions are earlier on in this thread here :
http://www.raspberrypi.org/phpBB3/viewt ... 00#p261609

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

babbage
Posts: 123
Joined: Mon Aug 29, 2011 2:23 pm

Re: Nokia Pi LCD

Mon Mar 04, 2013 12:32 pm

Thanks Texy, I'll sort the blacklist out and hopefully that will be it :-)
Cheers,

Steve

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

Re: Nokia Pi LCD

Mon Mar 04, 2013 4:35 pm

babbage wrote:Morning all.
Re the comment above, I always have to remove white space when i'm posting from this board - normally end up with two spaces at least to take away. Easy enough to remove in Idle, but i'm not sure why it happens :o
Steve,

Are you using the "CODE: SELECT ALL" at the top of the listing in the forum for selecting the text for copying? I have seen issues with copy/paste when trying to use the mouse to select the code text. Also, which browser are you using?

Enjoy!
Bill

babbage
Posts: 123
Joined: Mon Aug 29, 2011 2:23 pm

Re: Nokia Pi LCD

Mon Mar 04, 2013 9:20 pm

Hello Bill,
I do indeed use the 'Code:Select all' link at the top.
I am using Firefox, but also have Chrome, perhaps I should try that :idea:
Thank You
Steve

paulie
Posts: 263
Joined: Thu Jan 19, 2012 6:51 pm

Re: Nokia Pi LCD

Mon Mar 04, 2013 10:58 pm

Had another go tonight: tried a huge range of contrasts but still nothing displayed.
put a delay in the main, which shows that character set is printed in about a second or so.
Unfortunately nothing on lcd. Only sign of activity is backlight dipping out as script is rerun.
It has been my custom to use Xeyes

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

Re: Nokia Pi LCD

Mon Mar 04, 2013 11:06 pm

Sorry you are still having problems. If you can send it back to me with your sd card I can try to diagnose the problem.
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

babbage
Posts: 123
Joined: Mon Aug 29, 2011 2:23 pm

Re: Nokia Pi LCD

Thu Mar 07, 2013 8:44 am

Texy, now working fine, sorry I missed this before.
Thanks again for your help and patience
Steve
texy wrote:You should not need to re install spidev, but if the blacklist isn't sorted, then it wont work ;) . Instructions are earlier on in this thread here :
http://www.raspberrypi.org/phpBB3/viewt ... 00#p261609

Texy

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

Re: Nokia Pi LCD

Thu Mar 07, 2013 9:08 am

No problemo ;)
T.
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

pmk
Posts: 21
Joined: Wed Jun 20, 2012 5:27 pm

Re: Nokia Pi LCD

Fri May 10, 2013 8:26 pm

Is there is way of running this display without using wiringpi ??

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

Re: Nokia Pi LCD

Fri May 10, 2013 8:44 pm

Of course - see the code in the first post of this thread ;)
However, I soon migrated to use wiringpi, mainly because of the pwm support (to drive the backlit LED).

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

User avatar
mrpi64
Posts: 931
Joined: Sat Feb 16, 2013 5:13 pm

Re: Nokia Pi LCD

Sat May 11, 2013 1:52 pm

My word, 239 replies... And stands to reason. Many people are looking for screens like this! Even me! :D
I'm happy to help.
https://www.raspberrypi.org/forums/viewtopic.php?f=78&t=51794 - List of games that work on the Pi.

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

Re: Nokia Pi LCD

Sat May 11, 2013 2:18 pm

Hmmm. Well it's been a while. This is the last batch I'll be producing. TFT prices are reasonable now and offer so much more.
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

chorlton2080
Posts: 124
Joined: Sun Dec 23, 2012 9:44 pm

Re: Nokia Pi LCD

Sun Jul 21, 2013 7:51 pm

Got this working - and so easy it was thanks to everyone's contributions. Below is a photo of the LCD displaying humidity and temperature data from a DHT 22.
2013-07-21 20.42.12.jpg
2013-07-21 20.42.12.jpg (39.26 KiB) Viewed 7633 times
I'm using the wiringpi code which appeared early in this thread. The problem I have is I don't seem to be able to switch the LED backlight off in software - it is not typically needed in ambient light. I've tried led(0) but with no effect.

Can anyone offer assistance?

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

Re: Nokia Pi LCD

Sun Jul 21, 2013 8:21 pm

Hi,
Show us your complete program and how is the led wired?
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

chorlton2080
Posts: 124
Joined: Sun Dec 23, 2012 9:44 pm

Re: Nokia Pi LCD

Sun Jul 21, 2013 8:39 pm

I've just posted the part of the code that outputs to the LCD initially, prior to polling the DHT22 (since that's not relevant). I did try to create an LCD class that existed in a seperate module which could be imported, but it proved unreliable. Thus I've crudely pasted the full code straight into the main humidity logging programme (which also outputs to Google Docs).

It's all wired up as per the description within the code. I know I could just pull the LED wire, but that would be cheating (wouldn't it?) :D

There is some legacy code within for driving some status LEDs, which have been commented out.

The code will look very familiar. I've adjusted the contrast for my screen. As I stated: it does work, but I don't always need the backlight.

Code: Select all

#!/usr/bin/python

import subprocess
import re
import sys
import time
import datetime
import gspread
import csv
#import RPi.GPIO as GPIO
import wiringpi

#GPIO.setmode(GPIO.BCM)
#GPIO.setup(17, GPIO.OUT)

# Nokia LCD setup

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

#gpio's :
SCE  = 2 # gpio pin 13 = wiringpi no. 2
SCLK = 5 # gpio pin 18 = wiringpi no. 5
DIN  = 4 # gpio pin 16 = wiringpi no. 4
DC   = 3  # gpio pin 15 = wiringpi no. 3
RST  = 0 # gpio pin 11 = wiringpi no. 0
LED  = 1  # gpio pin 12 = wiringpi no. 1

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))


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

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


def SPI(value):
  # data = DIN
  # clock = SCLK
  # MSB first
  for i in reversed(xrange(8)):
    wiringpi.digitalWrite(DIN, (value >> i) & 1)
    wiringpi.digitalWrite(SCLK, ON)
    wiringpi.digitalWrite(SCLK, OFF)


def lcd_cmd(value):
  wiringpi.digitalWrite(DC, OFF)
  SPI(value)


def lcd_data(value):
  wiringpi.digitalWrite(DC, ON)
  SPI(value)


def gotoxy(x, y):
  lcd_cmd(x + 128)
  lcd_cmd(y + 64)


def cls():
  gotoxy(0, 0)
  for _ in xrange(ROWS * COLUMNS * PIXELS_PER_ROW):
    lcd_data(0)


def begin(contrast):
  setup()
  # Toggle RST low to reset.
  wiringpi.digitalWrite(SCE, OFF)
  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.
  for value in [0x21, 0x14, contrast, 0x20, 0x0c]:
    lcd_cmd(value) # extended mode 
  cls()


def init():
  begin(0xa0)


def led(led_value):
  wiringpi.digitalWrite(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:
    for value in font[char]:
      lcd_data(value)

    lcd_data(0) # Space inbetween characters.
  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)

init()
led(0)
centre_word(2, "Setting Up")

I appreciate your help with this.

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

Re: Nokia Pi LCD

Mon Jul 22, 2013 6:49 am

Try wiringpi2 instead of wiringpi.
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

User avatar
Xav
Posts: 85
Joined: Thu May 09, 2013 7:52 am
Location: France
Contact: Website

Re: Nokia Pi LCD

Thu Aug 01, 2013 9:51 pm

I would like to thanks contributors of this post and let you know I used the source code found in this thread to create a python library availabie in github: https://github.com/XavierBerger/pcd8544.

I'll try to use this library into a new project RPi-Monitor-LCD which comes as an addition to RPi-Monitor. For the moment only one basic example is available showing how to extract information from RPi-Monitor and how to show them on screen.
If you don't know RPi-Monitor yet, I do invite you to have a look to my blog http://rpi-experiences.blogspot.fr/.

Enjoy and spread the word to your circle!

User avatar
Pest
Posts: 10
Joined: Sat Aug 03, 2013 11:38 am
Location: Auckland, New Zealand
Contact: Website

Re: Nokia Pi LCD

Sun Aug 04, 2013 12:01 am

Hi all,

Here's a version of bgreats excellent library (modified from the last one he posted) with some additions, comments and cleanups:

Code: Select all

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
######
# GLP - 03-Aug-2013 - Cleaned, expanded, commented
#       Added row and col tracking
#       Added next_row(), next_col(), char_col() and next_char_col()
#       Cleaned up COLUMNS and PER_PIXEL nomenclature
#       Made all data and cmd calls use lcd_data() and lcd_cmd()
#       Added set_contrast()
#       Added wrap logic to text()
#       Added validity assertions to functions that needed them
#       Updated LED brightness test in __main__
# 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
import os
import mmap
from PIL import Image,ImageDraw,ImageFont

# Display size
ROWS = 6 # Times 8 bits = 48 pixels
CHAR_COLUMNS = 14 # Times 6 pixels = 84 pixels
COLUMNS_PER_CHAR = 6 # Eash char is 6 cols wide
COLUMNS = CHAR_COLUMNS * COLUMNS_PER_CHAR
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)

# For SPI configuration test
BCM2708_PERI_BASE=0x20000000
GPIO_BASE=(BCM2708_PERI_BASE + 0x00200000)
BLOCK_SIZE=4096

CLSBUF=[0]*(ROWS * COLUMNS)

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):
        ''' Reverse the bits in a byte '''
        result = 0
        for _ in xrange(width):
                result = (result << 1) | (value & 1)
                value >>= 1

        return result

BITREVERSE = map(bit_reverse, xrange(256))

def _strto32bit_(str):
        ''' Convert a string to a 32 bit integer '''
        return ((ord(str[3])<<24) + (ord(str[2])<<16) + (ord(str[1])<<8) + ord(str[0]))

def _32bittostr_(val):
        ''' Convert a 32 bit intger to a string '''
        return chr(val&0xff) + chr((val>>8)&0xff) + chr((val>>16)&0xff) + chr((val>>24)&0xff)

def spiConfig():
        ''' Check and update SPI configuration '''
        # Use /dev/mem to gain access to peripheral registers
        mf=os.open("/dev/mem", os.O_RDWR|os.O_SYNC)
        m = mmap.mmap(mf,BLOCK_SIZE, mmap.MAP_SHARED,
                mmap.PROT_READ|mmap.PROT_WRITE,offset=GPIO_BASE)
        # can close the file after we have mmap
        os.close(mf)
        # Read first two registers (have SPI pin function assignements)
        # GPFSEL0
        m.seek(0)
        reg0=_strto32bit_(m.read(4))
        # GPFSEL1
        m.seek(4)
        reg1=_strto32bit_(m.read(4))
        # print bin(reg0)[2:].zfill(32)[2:]
        # print bin(reg1)[2:].zfill(32)[2:]

        # GPFSEL0 bits --> x[2] SPI0_MISO[3] SPI0_CE0[3] SPI0_CE1[3] x[21]
        # We only use SPI0_CEx depending on setup, but make sure all are set up
        m0 = 0b00111111111000000000000000000000
        s0 = 0b00100100100000000000000000000000
        b0 = reg0 & m0
        if b0 <> s0:
                print "SPI reg0 configuration not correct. Updating."
                reg0 = (reg0 & ~m0) | s0
                m.seek(0)
                m.write(_32bittostr_(reg0))

        # GPFSEL1 bits --> x[26] SPI0_MOSI[3] SPI0_SCLK[3]
        m1 = 0b00000000000000000000000000111111
        s1 = 0b00000000000000000000000000100100
        b1 = reg1 & m1
        if b1 <> s1:
                print "SPI reg1 configuration not correct. Updating."
                reg1 = (reg1 & ~m1) | s1
                m.seek(4)
                m.write(_32bittostr_(reg1))

        # No longer need the mmap
        m.close()

class NokiaSPI:
        def __init__(self, dev=(0,0),speed=5000000, brightness=256, contrast=0xc0):
                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
                spiConfig()

                # 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)

                # Initialise LCD
                # 0x21 = Function set (0x20) + Power-down mode (0x04) + Vertical addressing (0x02) + Extended instruction set (0x01)
                # 0x14 = Bias system (0x10) + BS2 (0x04) + BS1 (0x02) + BS0 (0x01)
                # 0xXX = Vop (Operation Voltage) = 0x80 + 7 bits
                # 0x20 = Back to basic instruction set
                # 0x0c = Display Control = 0x08 + 3 bits: D,0,E. 0x04 = Normal mode
                self.lcd_cmd([0x21, 0x14, self.contrast, 0x20, 0x0c])

                self.row = -1
                self.col = -1
                # Clear the screen. This will also initialise self.row and self.col
                self.cls()

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


        def lcd_cmd(self,value):
                ''' Write a value or list of values to the LCD in COMMAND mode '''
                wiringpi.digitalWrite(self.dc, OFF)
                if type(value) != type([]):
                        value = [value]
                self.spi.writebytes(value)


        def lcd_data(self,value):
                ''' Write a value or list of values to the LCD in DATA mode '''
                wiringpi.digitalWrite(self.dc, ON)
                if type(value) != type([]):
                        value = [value]
                self.spi.writebytes(value)
                # Calculate new row/col
                # Writing off the end of a row proceeds to the next row
                # Writing off the end of the last row proceeds to the first row
                self.row = (self.row + ((self.col + len(value)) // COLUMNS)) % ROWS
                self.col = (self.col + len(value)) % COLUMNS


        def gotoxy(self, x, y):
                ''' Move the cursor (in memory) to position x, y '''
                assert(0 <= x <= COLUMNS)
                assert(0 <= y <= ROWS)
                # 0x80 = Set X ram address
                # 0x40 = Set Y ram address
                self.lcd_cmd([x+128,y+64])
                self.col = x
                self.row = y


        def cls(self):
                ''' Clear the entire display '''
                self.gotoxy(0, 0)
                self.lcd_data(CLSBUF)
                # Note, we wrote EXACTLY the right number of 0's to return to 0,0


        def fill(self,pattern=0xff):
                fillbuf=[pattern]*(ROWS * COLUMNS)
                self.gotoxy(0, 0)
                self.lcd_data(fillbuf)


        def set_brightness(self, led_value):
                '''
                Set the backlight LED brightness. Valid values are 0 <-> 1023
                When not connected to the PWM port, any value > 0 will turn the LED on full
                '''
                assert(0 <= led_value <= 1023)

                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)
                self.brightness = led_value


        def set_contrast(self, value):
                ''' Set the contrast. Valid values are 0x80 <-> 0xFF '''
                assert(0x80 <= value <= 0xFF)
                self.lcd_cmd([0x21, value, 0x20])
                self.contrast = value


        def load_bitmap(self, filename, reverse=False):
                ''' Load and display a bitmap from a file. reverse displays a negative image '''
                mask = 0xff if reverse else 0x00
                self.gotoxy(0, 0)
                with open(filename, 'rb') as bitmap_file:
                        for x in xrange(ROWS):
                                for y in xrange(COLUMNS):
                                        bitmap_file.seek(0x3e + x + (y * 8))
                                        self.lcd_data(BITREVERSE[ord(bitmap_file.read(1))] ^ mask)


        def show_custom(self, font=FONT):
                ''' Display the custom char from [font] '''
                self.display_char('\x7f', font)


        def define_custom(self, values):
                ''' Overwrite the custom char value in the default font '''
                FONT['\x7f'] = values


        def restore_custom(self):
                ''' Restore the custom char value to it's default in the default font '''
                self.define_custom(ORIGINAL_CUSTOM)


        def alt_custom(self):
                ''' Use an alternate custom char in the default font '''
                self.define_custom([0x00, 0x50, 0x3C, 0x52, 0x44])


        def pi_custom(self):
                ''' Use a raspberry pi icon as the custom char in the default font '''
                self.define_custom([0x19, 0x25, 0x5A, 0x25, 0x19])


        def next_row(self):
                ''' Return the next row, accounting for page wrapping '''
                return (self.row + 1) % ROWS

        def next_col(self):
                ''' Return the next pixel column, accounting for line wrapping '''
                return (self.col + 1) % COLUMNS

        def char_col(self):
                ''' Return the cahracter column (as opposed to self.col which is a pixel column counter) '''
                return self.col / COLUMNS_PER_CHAR

        def next_char_col(self):
                ''' Return the next character column, accounting for line wrapping '''
                return (self.char_col() + 1) % CHAR_COLUMNS


        def display_char(self, char, font=FONT):
                ''' Display a single character. Carriage return clears the remainder of the line and proceeds to the next row '''
                try:
                        if char == '\n':
                                # Clear the rest of the line. This also puts the cursor at the beginning of the next line.
                                self.lcd_data([0] * (COLUMNS - self.col))
                        else:
                                self.lcd_data(font[char]+[0])

                except KeyError:
                        pass # Ignore undefined characters.


        def text(self, string, font=FONT, wrap=True):
                '''
                Display a string of text.
                If wrap is False lines longer than COLUMNS will be truncated and lines beyond ROWS will be discarded
                '''
                def truncate(s):
                        ''' Cut off anything beyond CHAR_COLUMNS '''
                        s = s[:CHAR_COLUMNS]
                        if len(s) == CHAR_COLUMNS:
                                return s
                        else:
                                # We only need a carriage return if we were'nt at the end of the line
                                return s+'\n'

                if not wrap:
                        # The following would go strangely if we were in the middle of a char
                        assert(self.col % COLUMNS_PER_CHAR == 0)
                        # We need padding if we're not already at the start of the line
                        pad = '0'*self.char_col()
                        # There a lot going on in this next line, so for those who're having trouble following:
                        #  Combine the pad and the string
                        #  Split it into a list of lines (carriage returns are discarded)
                        #  Throw away any lines beyond ROWS, accounting for the number of rows already displayed
                        #  Run truncate() on each line (this re-provides the carriage returns if required)
                        #  Join the list back together into a string
                        #  Cut off the pad we added at the start
                        string = ''.join([truncate(s) for s in (pad+string).splitlines()[:ROWS-self.row]])[len(pad):]
                for char in string:
                        self.display_char(char, font)


        def gotorc(self, r, c):
                ''' Move to character row, column '''
                self.gotoxy(c*6,r)


        def centre_word(self, r, word):
                ''' Display 'word' centered in row 'row' '''
                self.gotorc(r, max(0, (CHAR_COLUMNS - len(word)) // 2))
                self.text(word)


        def show_image(self,im):
                ''' Display an 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)
                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__':
        # Test all the things!

        start, end = 32, 116
        print 'LCD Display Test: ASCII %d to %d' % (start, end)

        noki = NokiaSPI()

        start_time = time.time()
        noki.cls()
        noki.set_brightness(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")

        time.sleep(1)

        # Contrast
        noki.cls()
        old_contrast = noki.contrast
        for i in range(0x80,0xFF):
                noki.set_contrast(i)
                noki.gotorc(2,0)
                noki.text('Contrast:\n%s\n' % hex(i))
                time.sleep(0.1)
        noki.set_contrast(old_contrast)

        time.sleep(1)

        # brightness PWM testing -- off -> 100%
        noki.cls()
        for i in range(0,1023,16):
                noki.set_brightness(i)
                noki.gotorc(2,0)
                noki.text("Brightness:\n%s\n" % i)
                time.sleep(0.1)
        noki.set_brightness(1023)
        noki.gotorc(2,0)
        noki.text("Brightness:\n%s\n" % 1023)

        time.sleep(1)

        noki.set_brightness(768)

        ## 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)

        if (os.path.exists("raspi.bmp")):
                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)

        if os.path.exists("lenna.png"):
                # 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)

I've added:
  • row and column tracking so you can ask the object where the cursor is
  • clarified the language around pixel-column versus char-column
  • added next-row/next-col functions which handle line and page wrapping
  • made all data and cmd calls use lcd_data and lcd_cmd
  • added a set_contrast function
  • added value checks to functions that needed them
  • combined the 2 test suites (with checks to see if the images are present)
  • added no-wrap logic to the text() function

honda4life
Posts: 75
Joined: Thu Mar 15, 2012 7:27 pm

Re: Nokia Pi LCD

Fri Aug 23, 2013 5:57 pm

I've used this tutorial as a starting point:
http://binerry.de/post/25787954149/pcd8 ... qus_thread

It works, after some try and error, but I have a strange reset issue.
When the reset is connected, the display works very short as is should be, and is blank afterwards.
When disconnecting the reset, it works (at this moment reset is 3.3V, so should be OK).
Same problem when connecting the reset to te 3.3V power terminal.

Okay... let's connect this pin to GND. This is the reset, display is blank, even after disconnecting.
When connecting back to 3.3V, the screens stays blank. (should be OK).

It seems the RST must be in "tri-state" modus after the reset. Nothing found on this issue on the internet.

Another strange thing, when measuring the voltage on the RST pin, it's about 6.5V :shock:
Seems like this is a voltage from the voltage doubler... But the current when connecting to 3.3V or GND is barely measureable.

When reading the datasheet:
Immediately following power-on, the contents of all internal
registers and of the RAM are undefined.
A
RES pulse
must be applied
. Attention should be paid to the
possibility that the
device may be damaged
if not properly
reset.
All internal registers are reset by applying an external
RES
pulse (active LOW) at pad 31, within the specified time.
However, the RAM contents are still undefined. The state
after reset is described in Section 8.2.
The
RES input must be

0.3V
DD
when V
DD
reaches V
DDmin
(or higher) within a maximum time of 100 ms after V
DD
goes HIGH (see Fig.16).
About the specified time... Is that the problem, why nobody else has this issue?

User avatar
mobilebaz
Posts: 16
Joined: Sat Sep 28, 2013 8:46 am
Location: IR

Re: Nokia Pi LCD

Sat Oct 05, 2013 6:55 am

How can an analog clock on the Nokia 5110 display?
I used the following example
mcpipy.wordpress.com/2013/02/14/analoganalogue-clock/‎
, but I did not succeed.

Pilume
Posts: 5
Joined: Sat Dec 07, 2013 8:27 am

Re: Nokia Pi LCD

Sat Dec 07, 2013 8:34 am

Hi,

how can I show a variable on the lcd screen ? Ip adress is on the computer, but on the nokia screen is printed "0".

Code: Select all

!/usr/bin/python

import os
from nokiaSPI import *
var = "ifconfig wlan0 | grep \"inet ad\" | cut -f2 -d: | awk '{print $1}'"
#ip = os.system(var)
noki = NokiaSPI()
noki.define_custom([0x30,0x2c,0x66,0x6c,0x30])
noki.cls()
noki.text("              ")
noki.text("              ")
noki.text(str(os.system(var)))
noki.text("              ")
noki.text("              ")
noki.text("              ")
Thanks for your scripts and sorry for my english

Pilume
Posts: 5
Joined: Sat Dec 07, 2013 8:27 am

Re: Nokia Pi LCD

Sun Dec 08, 2013 3:24 am

Ok it's resolve,

solution is os.popen(cmd).read(), pas os.system(cmd)

Return to “Python”