Re: Nokia Pi LCD
Didn't you buy one of my ready to go units?
Texy
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
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555
-
- Posts: 69
- Joined: Wed Sep 05, 2012 11:27 am
Re: Nokia Pi LCD
Yes, but one of the old ones, before the SPI code was released. I also got a 'bare' one from eBay (2.98!) -that's the one in the picture.
I'm going to try to patch your lcd connectors into my breadboard, but don't have the right leads (or a schematic of your old board - the silkscreen is hidden by the LCD!). I may just unsolder the LCD - though later - must get on with some 'proper' work first!
I'm going to try to patch your lcd connectors into my breadboard, but don't have the right leads (or a schematic of your old board - the silkscreen is hidden by the LCD!). I may just unsolder the LCD - though later - must get on with some 'proper' work first!
Re: Nokia Pi LCD
Hi,
I can't remember if you have the v1 board (blue pcb), or v2 board (green pcb). If its the green one I can post pictures of the track cuts and wire links required if you want. I believe my local sorting office has a package for me which will be the v3 pcb's - these will have the correct tracking in for SPI without mod's (if I got the layout correct
). If you are happy to desolder your lcd from it's original pcb, I could send you just the replacement new pcb, if you want. PM me if its of interest.
Cheers,
Texy
I can't remember if you have the v1 board (blue pcb), or v2 board (green pcb). If its the green one I can post pictures of the track cuts and wire links required if you want. I believe my local sorting office has a package for me which will be the v3 pcb's - these will have the correct tracking in for SPI without mod's (if I got the layout correct

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
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555
Re: Nokia Pi LCD
I seem to be having problems with my Nokia LCD - I am *SURE* it is me.
I've followed instructions in install Wiringpi, but note from a comment from Rattus that you need to change settings in setup.py ( case changes from Wiringpi to wiringPi I tthink) but can't seem to locate a file called setup.py anywhere. I've tried running the supplied code, but I get a syntax error at the line under GPIO's, starting SCE = 2 - i'm presuming this is related ?
Having a bad Pi related day today, as my airprint Pi seems to have taken a dislike to printing from an ipad, but will print from pretty much anything else.
I'd love to get this LCD board working
Thanks for any help.
Steve
I've followed instructions in install Wiringpi, but note from a comment from Rattus that you need to change settings in setup.py ( case changes from Wiringpi to wiringPi I tthink) but can't seem to locate a file called setup.py anywhere. I've tried running the supplied code, but I get a syntax error at the line under GPIO's, starting SCE = 2 - i'm presuming this is related ?
Having a bad Pi related day today, as my airprint Pi seems to have taken a dislike to printing from an ipad, but will print from pretty much anything else.
I'd love to get this LCD board working

Thanks for any help.
Steve
Re: Nokia Pi LCD
Hi babbage,
to for wiringpi, its easier to use the 'pip' install method, and to use PIL and spidev also, use the following:
If you haven't updated your repository lists lately, do a
prior to running the previous installs.
hope this helps,
Texy
to for wiringpi, its easier to use the 'pip' install method, and to use PIL and spidev also, use the following:
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 apt-get update && sudo apt-get upgrade
hope this helps,
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
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555
Re: Nokia Pi LCD
Hi Texy,
Thanks for the reply. I re-imaged a card, and then followed the instructions you gave and got the following error when doing sudo pip install wiringpi: Errorr: Command 'gcc' failed with exit status 1
There is also a massive log file, which I won't post here.
Is there a real idiots guide to setting this up, as I feel I may be a good test for it
Thanks for the reply. I re-imaged a card, and then followed the instructions you gave and got the following error when doing sudo pip install wiringpi: Errorr: Command 'gcc' failed with exit status 1
There is also a massive log file, which I won't post here.
Is there a real idiots guide to setting this up, as I feel I may be a good test for it

Re: Nokia Pi LCD
Which image did you use? Can you post the complete message?
T.
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
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555
Re: Nokia Pi LCD
Hi Text, sorry to be a pain. It#s been one of those days where I just shouldn't have switched any computer on, nothing I have tried has worked !!
I have used the Raspbian Wheezy image 2013-02-09. Error from the pip log file below....
Thanks again for any help
I have used the Raspbian Wheezy image 2013-02-09. Error from the pip log file below....
Thanks again for any help

Code: Select all
------------------------------------------------------------
/usr/bin/pip run on Sat Feb 23 20:38:13 2013
Downloading/unpacking wiringpi
Running setup.py egg_info for package wiringpi
running egg_info
writing pip-egg-info/wiringpi.egg-info/PKG-INFO
writing top-level names to pip-egg-info/wiringpi.egg-info/top_level.txt
writing dependency_links to pip-egg-info/wiringpi.egg-info/dependency_links.txt
warning: manifest_maker: standard file '-c' not found
reading manifest file 'pip-egg-info/wiringpi.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'pip-egg-info/wiringpi.egg-info/SOURCES.txt'
Installing collected packages: wiringpi
Running setup.py install for wiringpi
Running command /usr/bin/python -c "import setuptools;__file__='/home/pi/build/wiringpi/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --single-version-externally-managed --record /tmp/pip-eRf1Qi-record/install-record.txt
running install
running build
running build_py
running build_ext
building '_wiringpi' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c WiringPi/wiringPi/lcd.c -o build/temp.linux-armv6l-2.7/WiringPi/wiringPi/lcd.o
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c WiringPi/wiringPi/piHiPri.c -o build/temp.linux-armv6l-2.7/WiringPi/wiringPi/piHiPri.o
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c WiringPi/wiringPi/piThread.c -o build/temp.linux-armv6l-2.7/WiringPi/wiringPi/piThread.o
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c WiringPi/wiringPi/wiringPiFace.c -o build/temp.linux-armv6l-2.7/WiringPi/wiringPi/wiringPiFace.o
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c wiringpi_wrap.c -o build/temp.linux-armv6l-2.7/wiringpi_wrap.o
wiringpi_wrap.c:125:20: fatal error: Python.h: No such file or directory
compilation terminated.
error: command 'gcc' failed with exit status 1
Complete output from command /usr/bin/python -c "import setuptools;__file__='/home/pi/build/wiringpi/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --single-version-externally-managed --record /tmp/pip-eRf1Qi-record/install-record.txt:
running install
running build
running build_py
running build_ext
building '_wiringpi' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c WiringPi/wiringPi/lcd.c -o build/temp.linux-armv6l-2.7/WiringPi/wiringPi/lcd.o
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c WiringPi/wiringPi/piHiPri.c -o build/temp.linux-armv6l-2.7/WiringPi/wiringPi/piHiPri.o
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c WiringPi/wiringPi/piThread.c -o build/temp.linux-armv6l-2.7/WiringPi/wiringPi/piThread.o
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c WiringPi/wiringPi/wiringPiFace.c -o build/temp.linux-armv6l-2.7/WiringPi/wiringPi/wiringPiFace.o
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c wiringpi_wrap.c -o build/temp.linux-armv6l-2.7/wiringpi_wrap.o
wiringpi_wrap.c:125:20: fatal error: Python.h: No such file or directory
compilation terminated.
error: command 'gcc' failed with exit status 1
----------------------------------------
Command /usr/bin/python -c "import setuptools;__file__='/home/pi/build/wiringpi/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --single-version-externally-managed --record /tmp/pip-eRf1Qi-record/install-record.txt failed with error code 1 in /home/pi/build/wiringpi
Exception information:
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 104, in main
status = self.run(options, args)
File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 250, in run
requirement_set.install(install_options, global_options)
File "/usr/lib/python2.7/dist-packages/pip/req.py", line 1133, in install
requirement.install(install_options, global_options)
File "/usr/lib/python2.7/dist-packages/pip/req.py", line 577, in install
cwd=self.source_dir, filter_stdout=self._filter_install, show_stdout=False)
File "/usr/lib/python2.7/dist-packages/pip/__init__.py", line 256, in call_subprocess
% (command_desc, proc.returncode, cwd))
InstallationError: Command /usr/bin/python -c "import setuptools;__file__='/home/pi/build/wiringpi/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --single-version-externally-managed --record /tmp/pip-eRf1Qi-record/install-record.txt failed with error code 1 in /home/pi/build/wiringp
Re: Nokia Pi LCD
Apologies - I should of told you that you need to install python-dev before wiringpi
Texy
Code: Select all
sudo apt-get install python-dev
sudo pip install wiringpi
sudo pip install spidev
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
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555
Re: Nokia Pi LCD
Hi Texy, thanks for the response !
I won't get a chance to try this until the weekend, but i'm sure it will fix my problems, so thank you for being so patient
Steve
I won't get a chance to try this until the weekend, but i'm sure it will fix my problems, so thank you for being so patient

Steve
Re: Nokia Pi LCD
Texy,
Am running test code as suggested, but it won't start
Getting syntax error in line 19:
(All after RST line has been snipped)
I have edited raspi-blacklist.conf to remove blacklisting of I2C & SPI, and installed python-dev python-imaging python-imaging-tk python-pip
Then did a pip install of wiringpi and spidev
where else am I going wrong?
Am running test code as suggested, but it won't start

Getting syntax error in line 19:
Code: Select all
!/usr/bin/env python
# -*- coding: utf-8 -*-
# lcd nokia switch shield v1
# by Texy and the raspberry pi community
# bitmap display routine by POSitality
# 2/2/13
import time
import wiringpi
ROWS = 6
COLUMNS = 14
PIXELS_PER_ROW = 6
OUT = ON = 1
IN = OFF = 0
CONTRAST = 0xb8
#gpio's :
SCE = 2 # gpio pin 13 = wiringpi no. 2 # <-- syntax error right here after SCE
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
I have edited raspi-blacklist.conf to remove blacklisting of I2C & SPI, and installed python-dev python-imaging python-imaging-tk python-pip
Then did a pip install of wiringpi and spidev
where else am I going wrong?
It has been my custom to use Xeyes
Re: Nokia Pi LCD
.....looks like you've missed out the # at the very begining of the program.
The first line should be
This is important because it tells the system what language to use.
Texy
The first line should be
Code: Select all
#!/usr/bin/env python
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
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555
Re: Nokia Pi LCD
Just double checked : it does start with #!
The missing hash was a artefact of cut 'n' paste so that's not the problem.
The missing hash was a artefact of cut 'n' paste so that's not the problem.
It has been my custom to use Xeyes
Re: Nokia Pi LCD
Hi Paulie,
didn't you buy the 'shield' type add-on board? The test code for that is in this thread :
http://www.raspberrypi.org/phpBB3/viewt ... 32&t=32183
In any case you shouldn't be getting syntax errors with just declaring constants/variables. How are you running the program?
Also note that the v1 shield doesn't use hardware SPI, so editing the blacklist will not effect the running of test program.
It sounds like something else more fundamental is wrong with your setup. Can you run any other code?
Rather than showing us where the error message is showing up, are you able to post the actuall commands used to run the program and all of the error message display.
Thanks,
Texy
didn't you buy the 'shield' type add-on board? The test code for that is in this thread :
http://www.raspberrypi.org/phpBB3/viewt ... 32&t=32183
In any case you shouldn't be getting syntax errors with just declaring constants/variables. How are you running the program?
Also note that the v1 shield doesn't use hardware SPI, so editing the blacklist will not effect the running of test program.
It sounds like something else more fundamental is wrong with your setup. Can you run any other code?
Rather than showing us where the error message is showing up, are you able to post the actuall commands used to run the program and all of the error message display.
Thanks,
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
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555
Re: Nokia Pi LCD
Texy,
have copy/pasted the 'code' section from the link into a file in /usr/local/bin and did chmod +x
and for good measure:
have copy/pasted the 'code' section from the link into a file in /usr/local/bin and did chmod +x
Code: Select all
pi@raspberrypi /usr/local/bin $ ls
miniterm.py nokia_shield_test.py r.bmp
pi@raspberrypi /usr/local/bin $ ./nokia_shield_test.py
File "./nokia_shield_test.py", line 19
SCE = 2 # gpio pin 13 = wiringpi no. 2
^
SyntaxError: invalid syntax
pi@raspberrypi /usr/local/bin $ ls -l
total 40
-rwxr-xr-x 1 root staff 23349 Oct 18 14:30 miniterm.py
-rwxr-xr-x 1 root pi 9718 Feb 28 18:21 nokia_shield_test.py
-rw-r--r-- 1 pi pi 734 Feb 1 19:28 r.bmp
pi@raspberrypi /usr/local/bin $
Code: Select all
pi@raspberrypi /usr/local/lib $ find . -depth -name wiring* -print
./python2.7/dist-packages/wiringpi.py
./python2.7/dist-packages/wiringpi-1.0.5.egg-info
./python2.7/dist-packages/wiringpi.pyc
pi@raspberrypi /usr/local/lib $ ls -l /usr/bin/python
lrwxrwxrwx 1 root root 9 Feb 8 21:29 /usr/bin/python -> python2.7
pi@raspberrypi /usr/local/lib $
It has been my custom to use Xeyes
Re: Nokia Pi LCD
I,m far from a linux or python expert. So can you navigate to the directory where nokia_shield_test.py is and type
and see what happens.
Texy
Code: Select all
sudo python nokia_shield_test.py
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
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555
Re: Nokia Pi LCD
Nope, that didn't work either - same error as before
is it anything to do with labelling of the pins?
( chip select vs. chip enable or whatever the manufacturers call them)
different versions of wiringpi for each one perhaps? Yes i know the LCD is not read by the software, but.....
only other thought is [space] vs. [tab] character, or is python blind to the difference?
I expect others have run this code with no problems. uname -a gives:
Linux raspberrypi 3.6.11+ #371 PREEMPT Thu Feb 7 16:31:35 GMT 2013 armv6l GNU/Linux
Code: Select all
pi@raspberrypi /usr/local/bin $ sudo python nokia_shield_test.py
File "nokia_shield_test.py", line 19
SCE = 2 # gpio pin 13 = wiringpi no. 2
^
SyntaxError: invalid syntax
pi@raspberrypi /usr/local/bin $
( chip select vs. chip enable or whatever the manufacturers call them)
different versions of wiringpi for each one perhaps? Yes i know the LCD is not read by the software, but.....
only other thought is [space] vs. [tab] character, or is python blind to the difference?
I expect others have run this code with no problems. uname -a gives:
Linux raspberrypi 3.6.11+ #371 PREEMPT Thu Feb 7 16:31:35 GMT 2013 armv6l GNU/Linux
It has been my custom to use Xeyes
Re: Nokia Pi LCD
It should not be anything to with the labelling. I have just cut and pasted the test program from the link above :
I have ssh'ed into my pi and pasted the program into a new test.py file and run it :
As you can see, it runs without problems.
If this doesn't work, i would suggest trying another python example program.
Texy
Code: Select all
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# lcd nokia switch shield v1
# by Texy and the raspberry pi community
# bitmap display routine by POSitality
# 2/2/13
import time
import wiringpi
ROWS = 6
COLUMNS = 14
PIXELS_PER_ROW = 6
OUT = ON = 1
IN = OFF = 0
CONTRAST = 0xb8
#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
#switches
UP = 13 # gpio pin 21
RIGHT = 10 # gpio pin 24
DOWN = 11 # gpio pin 26
LEFT = 12 # gpio pin 19
SELECT = 14 # gpio pin 23
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']
bitreverse =[
0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0, 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8, 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8,
0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4, 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4,
0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC, 0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC,
0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2, 0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2,
0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA, 0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA,
0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6, 0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6,
0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE, 0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE,
0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1, 0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1,
0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9, 0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9,
0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5, 0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5,
0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED, 0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD,
0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3, 0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3,
0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB, 0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB,
0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7, 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,
0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF, 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF
]
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_gpio():
wiringpi.wiringPiSetup()
# Set pin directions.
# outputs :
for pin in [DIN, SCLK, DC, RST, SCE]:
wiringpi.pinMode(pin, OUT)
# inputs :
for pin in [UP, RIGHT, DOWN, LEFT, SELECT]:
wiringpi.pinMode(pin, IN)
# enable pull downs for the switches
wiringpi.pullUpDnControl(UP, wiringpi.PUD_DOWN)
wiringpi.pullUpDnControl(RIGHT, wiringpi.PUD_DOWN)
wiringpi.pullUpDnControl(DOWN, wiringpi.PUD_DOWN)
wiringpi.pullUpDnControl(LEFT, wiringpi.PUD_DOWN)
wiringpi.pullUpDnControl(SELECT, wiringpi.PUD_DOWN)
wiringpi.pinMode(LED,2) # pwm mode
wiringpi.pwmWrite(LED,128) # mid-level
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 init(contrast):
setup_gpio()
# Toggle RST low to reset.
wiringpi.digitalWrite(SCE, OFF)
wiringpi.digitalWrite(RST, OFF)
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 load_bitmap(file):
gotoxy(0,0)
f = open(file,'r')
for x in range(6):
for y in range(84):
f.seek(0x3e + y*8 + x)
b = ord(f.read(1))
rev = bitreverse[b]
lcd_data(rev ^ 0xff)
f.close()
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)
def main():
start, end = 32, 116
print 'LCD Display Test: ASCII %d to %d' % (start, end)
start_time = time.time()
init(CONTRAST)
load_bitmap('r.bmp')
finish_time = time.time()
print 'Init, LED on, %d chars, total time = %.2f' % (
end - start, finish_time - start_time
)
print
while 1==1:
input_value1 = wiringpi.digitalRead(UP)
input_value2 = wiringpi.digitalRead(RIGHT)
input_value3 = wiringpi.digitalRead(DOWN)
input_value4 = wiringpi.digitalRead(LEFT)
input_value5 = wiringpi.digitalRead(SELECT)
print "SW1 = ",input_value1,'\n'
print "SW2 = ",input_value2,'\n'
print "SW3 = ",input_value3,'\n'
print "SW4 = ",input_value4,'\n'
print "SW5 = ",input_value5,'\n'
time.sleep(1)
if __name__ == '__main__':
main()
Code: Select all
pi@raspberrypi /home/shares/public/lcd_shield $ sudo nano test.py
pi@raspberrypi /home/shares/public/lcd_shield $ sudo python test.py
LCD Display Test: ASCII 32 to 116
Init, LED on, 84 chars, total time = 0.36
SW1 = 0
SW2 = 0
SW3 = 0
SW4 = 0
SW5 = 0
SW1 = 0
If this doesn't work, i would suggest trying another python example program.
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
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555
Re: Nokia Pi LCD
I'm not certain, but I would consider that there is an extra non-printing character on the line with "SCE" that is causing the syntax error. Looking at your error message, it shows a pointer immediately after "SCE" before the "=". Try deleting and retyping the line:
I've seen this happen before depending on the copy/paste and editor used.
Enjoy!
Bill
Code: Select all
SCE = 2 # gpio pin 13 = wiringpi no. 2
Enjoy!
Bill
Re: Nokia Pi LCD
First of all, to the point above I would agree, I had the same problem and it was a non printing character that had got copied over. I ended up getting rid of the problem by doing what Texy did, and copying the code into Nano from an SSH session, that seemed to solve that problem.
I have tried again today to get my 3310 working and although I get no syntax error now (Texy, you were right, I need the additional step you mention) I still can't get anything to appear on the screen, although I can see a backlight come on, that is about it. This is using the code further back up this thread.
I also tried using the code from bgreat, but get the following error:
Any help gratefully received 
I have tried again today to get my 3310 working and although I get no syntax error now (Texy, you were right, I need the additional step you mention) I still can't get anything to appear on the screen, although I can see a backlight come on, that is about it. This is using the code further back up this thread.
I also tried using the code from bgreat, but get the following error:
Code: Select all
Traceback (most recent call last):
File "/home/pi/nokialcd4.py", line 296, in <module>
noki = NokiaSPI()
File "/home/pi/nokialcd4.py", line 158, in __init__
self.spi.open(self.dev[0],self.dev[1])
IOError: [Errno 2] No such file or directory

Re: Nokia Pi LCD
Hi,babbage wrote:First of all, to the point above I would agree, I had the same problem and it was a non printing character that had got copied over. I ended up getting rid of the problem by doing what Texy did, and copying the code into Nano from an SSH session, that seemed to solve that problem.
I have tried again today to get my 3310 working and although I get no syntax error now (Texy, you were right, I need the additional step you mention) I still can't get anything to appear on the screen, although I can see a backlight come on, that is about it. This is using the code further back up this thread.
I also tried using the code from bgreat, but get the following error:
Any help gratefully receivedCode: Select all
Traceback (most recent call last): File "/home/pi/nokialcd4.py", line 296, in <module> noki = NokiaSPI() File "/home/pi/nokialcd4.py", line 158, in __init__ self.spi.open(self.dev[0],self.dev[1]) IOError: [Errno 2] No such file or directory
please bare in mind that Paulie has the shield type board, which doesn't support SPI and is therefore wired differently to the cabled type that you have. This means that the python program will have different declarations for the GPIO lines. The following program will work with the SPI wiring, but doesn't utilise hardware SPI, just bit-banging :
Code: Select all
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# by Texy and the raspberry pi community
# bitmap display routine by POSitality
# this version using the SPI pins, but not
# using spidev
# 19/1/2013
import time
import wiringpi
ROWS = 6
COLUMNS = 14
PIXELS_PER_ROW = 6
ON = 1
OFF = 0
CONTRAST = 0xba
#gpio's :
SCE = 10 # gpio pin 13 = wiringpi no. 2
SCLK = 14 # gpio pin 18 = wiringpi no. 5
DIN = 12 # 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']
bitreverse =[
0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0, 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8, 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8,
0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4, 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4,
0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC, 0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC,
0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2, 0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2,
0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA, 0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA,
0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6, 0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6,
0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE, 0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE,
0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1, 0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1,
0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9, 0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9,
0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5, 0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5,
0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED, 0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD,
0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3, 0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3,
0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB, 0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB,
0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7, 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,
0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF, 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF
]
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(CONTRAST) # contrast value
def led(led_value):
wiringpi.digitalWrite(LED, led_value)
def load_bitmap(file):
gotoxy(0,0)
f = open(file,'r')
for x in range(6):
for y in range(84):
f.seek(0x3e + y*8 + x)
b = ord(f.read(1))
rev = bitreverse[b]
lcd_data(rev ^ 0xff)
f.close()
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)
def main():
start, end = 32, 116
print 'LCD Display Test: ASCII %d to %d' % (start, end)
start_time = time.time()
init()
led(1)
load_bitmap('r.bmp')
finish_time = time.time()
print 'Init, LED on, %d chars, total time = %.2f' % (
end - start, finish_time - start_time
)
print
if __name__ == '__main__':
main()
Run that code and see how you get on. If that works, try the following code that does utilise hard SPI, so you will need to have spidev installed.
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 = 0xb8
# 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))
class NokiaSPI:
def __init__(self, dev=(0,0),speed=4000000, 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)
Hope this helps,
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
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555
Re: Nokia Pi LCD
Hello Texy, Thank you again for your patience and swift response !
I've ran the first bit of code and I now have a picture of a Raspberry Pi on the screen, thank you
My time has run out yet again this weekend, but i'll try the second code extract - i'm sure it will work now !
Thank you again for your help.
Steve
Edit: Changed the contrast too, I had tried before by using wildly varied values but I guess they were *too* varied
I've ran the first bit of code and I now have a picture of a Raspberry Pi on the screen, thank you

My time has run out yet again this weekend, but i'll try the second code extract - i'm sure it will work now !
Thank you again for your help.
Steve
Edit: Changed the contrast too, I had tried before by using wildly varied values but I guess they were *too* varied
Re: Nokia Pi LCD
Great!
Now that you have got the ballpark figure for the contrast value, you can adjust it by a few points to get it just right
Texy
Now that you have got the ballpark figure for the contrast value, you can adjust it by a few points to get it just right

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
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555
Re: Nokia Pi LCD
Ok, I'm really having to go now!
Tried the second bit of code and I still get the same errors so I guess this is pointing to something SPI related ?
Is it just worth re-imaging and starting from scratch ?
Steve
Tried the second bit of code and I still get the same errors so I guess this is pointing to something SPI related ?
Is it just worth re-imaging and starting from scratch ?
Steve
Re: Nokia Pi LCD
No. Are you sure you have installed spidev and edited the blacklist file?
T.
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
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555