-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnoritake-bitmap-display.py
100 lines (82 loc) · 3.05 KB
/
noritake-bitmap-display.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env python
# encoding: utf-8
"""
Bus Pirate Noritake Serial VFD display demo
Created by Edouard Lafargue on 2010-02-22
Copyright 2010 Edouard Lafargue <edouard@lafargue.name>
This demo is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this demo script. If not, see <http://www.gnu.org/licenses/>.
"""
import os, sys
import Image
import serial
from pyBusPirateLite.UART import *
from pyBusPirateLite.BitBang import *
# This utility takes a 140x32 GIF black and white image file and
# displays it on a Noritake "Show and Tell" VFD.
# Takes the filename as the single argument, connects to the
# VFD through the Bus Pirate.
# The VFD display is a Noritake GU140x32F-7002, hooked to the bus pirate
# through its serial connector, all with default jumper settings: async serial
# 38400 Baud. The AUX Pin on the BP is connected to the Reset pin so that the display
# can be reset easily.
for infile in sys.argv[1:]:
f, e = os.path.splitext(infile)
if e == ".gif":
try:
im = Image.open(infile)
print "Picture size: " , im.size
except IOError:
print "cannot open source bitmap", infile
# Now parse the bitmap to transform it into a bitstream
# as expected by the display.
# Data is sent by column, one byte per 8 rows of 1 pixel, MSB on top
# So the data size is:
# bitmapsize = im.size[0]*(im.size[1])//8
print "Converting bitmap..."
picturebitmap = []
# BW GIF pixels have a 0 value for white and 1 value for black.
for col in range (0,im.size[0]):
for row in range (0,im.size[1]//8):
pixblock = 0
for subrow in range (0,8):
pixblock = pixblock | ( im.getpixel((col,row*8+subrow)) << (7-subrow))
picturebitmap.append(pixblock)
# Now initialize the display: we want to display a full screen picture, so
# we will clear the screen, place the cursor home.
uart = UART("COM4",115200)
print "Entering binmode: ",
if uart.BBmode():
print "OK."
else:
print "failed."
sys.exit()
print "Entering binary UART mode: ",
if uart.enter_UART():
print "OK."
else:
print "failed."
sys.exit()
print "Reset display (toggle AUX): ",
uart.cfg_pins(0x00)
uart.cfg_pins(PinCfg.POWER | PinCfg.AUX | PinCfg.PULLUPS)
print "OK."
print "Setting UART speed to 38400",
if uart.set_speed(UARTSpeed._38400):
print "OK."
else:
print "failed"
sys.exit()
# Last, cross fingers and send the bitmap
# Command is: 1F 28 66 11 xL xH yL yH 01 [bitmap]
# We assume width is < 256, so xH is 0x00. Likewise, yH is always 0x00 on a 140x32 display
initstring = [ 0x0C, 0x1F, 0x28, 0x66, 0x11, im.size[0], 0x00, im.size[1]//8, 0x00, 0x01]
uart.bulk_trans(len(initstring), initstring)
print "send Bitmap"
for i in range((len(picturebitmap)/16)):
print ".",
uart.bulk_trans(16, picturebitmap[i*16:i*16+16])