├── Documentation.txt ├── README.md ├── bl.bmp ├── example-tft144-fonts.py ├── example-tft144-grfx.py ├── example-tft144-rpi-only.py ├── example-tft144-vgpio-only.py ├── example-tft144.py ├── gpio.bmp ├── lcdfonts.py ├── lib_tft144.py ├── rpi2.bmp └── smartGPIO.py /Documentation.txt: -------------------------------------------------------------------------------- 1 | lib_tft144 2 | ========= 3 | 4 | V1.6 5 | 6 | Python library for a 128x128 LCD-TFT module with ILI9163 controller chip. 7 | This library works wirh Raspberry Oi or with Virtual-GPIO 8 | 9 | Raspberry Pi pin numbers are in BCM numbering. 10 | SCLK and MISO go to SCK and SDA on module. 11 | The module is write-only, so MOSI is not used. 12 | VCC of module goes to Raspberry Pi +5V. 13 | Logic pins are 3.3V. 14 | RPi.GPIO and SpiDev are required installed at Raspberry Pi. 15 | The python2.7 and python3.3 are supported. 16 | 17 | Fonts are coded 1=4x6 2=8x12 3=6x8=default 4=12x16 5=8x12 6=16x24 7=8x16 8=16x32 (V1.1) 18 | Screen pixel coordinates are x: 0 to 127 y: 0 to 127 l-r, t-b 19 | 20 | 21 | IMPORT the library module: 22 | 23 | from lib_tft144 import TFT144 24 | 25 | 26 | CONSTRUCTOR: 27 | 28 | * myTFT = TFT144(GPIO, SpiDev, CE_num, A0_pin, RST_pin, LED_pin, Orientation, isRedBoard, spi_speed) 29 | ---- where CE_num = 0 or 1 (CE0/CE1) on Raspberry Pi, actual CE pin# on virtual-GPIO, 30 | ---- "A0" (address line 0??) is also known as DC (data/command), 31 | ---- RST_pin may be declared or defaulted as 0 (and then tie RST to +3.3V), 32 | ---- LED_pin may be declared or defaulted as 0 (and then tie LED to +3.3V), 33 | ---- Orientation defaults to 0 degrees, but may be: 34 | TFT144.ORIENTATION0, or ...90 or ...180 or ...270 35 | ---- isRedBoard must be True for correct compensation for RED board error. Default False. 36 | ---- spi_speed. Raspberry Pi max is 32000000. Black board seems to accept 32000000, but red board may need lower. 37 | Default 16000000 38 | 39 | Constructor examples: 40 | 41 | * myTFT = TFT144(GPIO, spidev.SpiDev(), 0, 22) # RPi 42 | * myLCD = TFT144(GPIO, GPIO.SpiDev(), 1, 22, 18, 23, TFT144.ORIENTATION270) # virtGPIO 43 | 44 | 45 | OBJECT PROPERTIES: 46 | 47 | * ORIENTATION90 etc 48 | * Prenamed colours: BLUE GREEN RED PINK VIOLET LIGHTGREEN 49 | WHITE GREY LIGHTBLUE YELLOW BLACK 50 | * fontW and fontH: width and height of last output character V1.1 51 | 52 | 53 | OBJECT FUNCTIONS: 54 | 55 | * led_on(True/False) Turns screen on/off (if LED pin is controlled!) 56 | * reset_LCD() Hard or soft reset of module, depending whether RST pin is active. 57 | * clear_display(colour) 58 | * invert_screen() Reverse every colour 59 | * normal_screen() Back to normal colours 60 | * rgb(red, green, blue) From 3 (5-bit) primary colours, return a 16-bit “colour” 61 | * put_char(char, x, y, foregroundColour, backgroundColour, font) Font defaults to 3 (6x8) 62 | * put_string(string, x, y, fgColour, bgColour, font) Wraps (to similar start column) to next line 63 | * textX(X, font) Return pixel x-column matching X character-sizes across 64 | * textY(Y, font) Return pixel y-row matching Y character-sizes down 65 | * draw_dot(x, y, colour) At pixel coordinates x:y 66 | * draw_line(x0, y0, x1, y1, colour) Line 1 pixel wide from x0:y0 to x1:y1 67 | * draw_rectangle(x0, y0, x1, y1, colour) Single pixel frame 68 | * draw_filled_rectangle(x0, y0, x1, y1, colour) 69 | * draw_circle(x0, y0, radius, colour) 1 pixel wide 70 | * draw_bmp(filename, x0, y0) If .bmp file is found, load at top/left = x0:y0. No rescaling. 71 | Save your BMP file vertically "flipped". Ensure your x0:y0 origin allows pixel space on display. 72 | 73 | 74 | EXAMPLE APPLICATION (Raspberry Pi): 75 | 76 | import RPi.GPIO as GPIO 77 | import spidev 78 | spi = spidev.SpiDev() 79 | from lib_tft144 import TFT144 80 | TFT = TFT144(GPIO, spi, 0, 22) 81 | TFT.clear_display(TFT.BLUE) 82 | TFT.put_string(“Hello”, 50, 30, TFT.WHITE, TFT.BLUE, 4) 83 | # This example uses CE0 on the SPI, and GPIO pin22 to “A0” on the module. 84 | # It prints “Hello” near centre of screen, white lettering on all blue background, large font 4. 85 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # lib_tft144 2 | 3 | ## May 2018 - This is no longer being maintained by the original author. 4 | ## Please feel free to fork, copy, adapt if you find it useable 5 | 6 | V1.6 April 2015 7 | 8 | LCD-TFT-1.44 128x128px. An SPI library for Raspberry Pi or Virtual GPIO. 9 | 10 | The "BLACK" 1.44 board from eBay - eg http://www.ebay.com.au/itm/141239781210 - under $4! 11 | 12 | The "RED" version. eg. http://www.ebay.com.au/itm/400685907981 13 | 14 | RED board has a hardware mistake that preconfigures to 128x160 instead of 128x128. 15 | V1.6 of this library corrects for the red board error, but YOU MUST SET "isRedBoard=True" in the TFT144 object constructor. 16 | Otherwise some display modes have screen contents jumbled. 17 | 18 | Board has inbuilt 5V-3V (2.9?) regulator (which does NOT break out the 3V!!) 19 | As far as I can discern, logic level is still 3.3V limit, despite supply is 5V. 20 | Currently the code here is designed simply for case of 128x128 pixels. 21 | Brian Lavery (C) Oct 2014 brian (at) blavery (dot) com 22 | Free software, derived from: 23 | (1) ILI9163 128x128 LCD library - parallel I/O AVR C code 24 | Copyright (C) 2012 Simon Inns 25 | http://www.waitingforfriday.com/index.php/Reverse_Engineering_a_1.5_inch_Photoframe 26 | (2) ... then Antares python/parallel Raspberry Pi code: 27 | http://www.raspberrypi.org/forums/viewtopic.php?t=58291&p=450201 28 | 29 | Added: SPI access, BMP file load, double size fonts, python class, python3/2.7 compatibility 30 | Works on: Rasp Pi GPIO, or "virtual GPIO" 3.3V (identical library for both) 31 | 32 | On Raspberry Pi, uses SpiDev and RPi.GPIO. 33 | 34 | 35 | THIS BOARD WORKS A TREAT !!!! 36 | 37 | 38 | 39 | See examples files for Raspberry Pi use, virtual-GPIO use, and "smart" GPIO selection (RPi or virtual) 40 | -------------------------------------------------------------------------------- /bl.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BLavery/LIBtft144/HEAD/bl.bmp -------------------------------------------------------------------------------- /example-tft144-fonts.py: -------------------------------------------------------------------------------- 1 | 2 | # example-tft144-fonts.py V1.1 3 | 4 | from smartGPIO import GPIO 5 | from lib_tft144 import TFT144 6 | from time import sleep 7 | 8 | 9 | # My tests. Two configurations. 10 | 11 | if GPIO.RPI_REVISION == 0: # VIRTUAL-GPIO 12 | RST = 8 13 | CE = 10 # VirtGPIO: the chosen Chip Select pin#. (different from rpi) 14 | DC = 9 15 | LED = 7 16 | spidev = GPIO 17 | 18 | else: # RPI 19 | GPIO.setwarnings(False) 20 | GPIO.setmode(GPIO.BCM) 21 | RST = 18 # RST may use direct +3V strapping, and then be listed as 0 here. (Soft Reset used instead) 22 | CE = 0 # RPI GPIO: 0 or 1 for CE0 / CE1 number (NOT the pin#) 23 | DC = 22 # Labeled on board as "A0" Command/Data select 24 | LED = 23 # LED may also be strapped direct to +3V, (and then LED=0 here). LED sinks 10-14 mA @ 3V 25 | import spidev 26 | 27 | 28 | 29 | # Don't forget the other 2 SPI pins SCK and MOSI (SDA) 30 | 31 | # OK, GPIO (of one variety) is all ready. Now do the LCD demo: 32 | 33 | 34 | TFT = TFT144(GPIO, spidev.SpiDev(), CE, DC, RST, LED, TFT144.ORIENTATION90) 35 | # TFT = TFT144(GPIO, spidev.SpiDev(), CE, DC) # the minimalist version 36 | 37 | 38 | TFT.clear_display(TFT.BLUE) 39 | sleep(1) 40 | TFT.clear_display(TFT.RED) 41 | sleep(1) 42 | TFT.clear_display(TFT.GREEN) 43 | sleep(1) 44 | TFT.clear_display(TFT.PINK) 45 | sleep(1) 46 | TFT.clear_display(TFT.LIGHTBLUE) 47 | sleep(1) 48 | TFT.clear_display(TFT.LIGHTGREEN) 49 | sleep(1) 50 | TFT.clear_display(TFT.YELLOW) 51 | sleep(1) 52 | TFT.clear_display(TFT.MAGENTA) 53 | sleep(1) 54 | TFT.clear_display(TFT.CYAN) 55 | sleep(1) 56 | 57 | TFT.clear_display(0) 58 | 59 | print ("Display character sets:") 60 | for f in range(1, 9): 61 | posx=0 62 | posy=0 63 | print ("Font %d" % f) , 64 | print ("Base Font" if (f%2) else "Doubled Font"), 65 | print ("(default)" if f==3 else "") 66 | for i in range (33,126): 67 | # Note manual handling of cursor here (character output) 68 | TFT.put_char(chr(i),posx,posy,TFT.WHITE,TFT.BLACK,f) 69 | posx+=TFT.fontW 70 | if (posx+TFT.fontW)>=127: 71 | posx=0 72 | posy+=TFT.fontH 73 | if (posy+TFT.fontH)>=128: 74 | break 75 | 76 | sleep(1) 77 | TFT.clear_display(0) 78 | 79 | print ("Extended char set for fonts 3,4") 80 | posx=0 81 | posy=0 82 | for i in range (1,256): 83 | # Note manual handling of cursor here (character output) 84 | TFT.put_char(chr(i),posx,posy,TFT.WHITE,TFT.BLACK) 85 | posx+=TFT.fontW 86 | if (posx+TFT.fontW)>=127: 87 | posx=0 88 | posy+=TFT.fontH 89 | if (posy+TFT.fontH)>=128: 90 | break 91 | 92 | sleep(4) 93 | TFT.clear_display(0) 94 | 95 | 96 | print ("String output: 4 base fonts") 97 | # Note here the character positioning, wrap etc is auto 98 | TFT.put_string("Quick Brown fox jumped over", 0,0,TFT.WHITE, TFT.BLACK,1) 99 | TFT.put_string("Quick Brown fox jumped over", 0,20,TFT.LIGHTBLUE, TFT.BLACK,3) 100 | TFT.put_string("Quick Brown fox jumped over", 0,55,TFT.LIGHTGREEN, TFT.BLACK,5) 101 | TFT.put_string("Quick Brown fox jumped over", 0,90,TFT.PINK, TFT.BLACK,7) 102 | 103 | sleep(6) 104 | TFT.clear_display(TFT.BLUE) 105 | TFT.put_string("Fin.", 30, 40, TFT.WHITE, TFT.BLUE, 8) 106 | -------------------------------------------------------------------------------- /example-tft144-grfx.py: -------------------------------------------------------------------------------- 1 | # example-tft144-grfx.py V1.6 2 | # Brian Lavery (C) Oct 2014 brian (at) blavery (dot) com 3 | # Free software. 4 | 5 | # Full demonstration of the "BLACK" or "RED" 128x128 SPI TFT board connected to either: 6 | # 1. Raspberry Pi 7 | # 2. Virtual GPIO device running at 3.3V (eg Pro-mini 328) (vGPIO 0.9.5 min) 8 | 9 | # See the alternate pin assignments a few lines down. 10 | 11 | # THE DEMO: 12 | # Filling screen with small font text. Shows font character set. 13 | # Show screen blanking control. 14 | # Show "inversion" of screen (ie like a photographic colour negative). 15 | # Text with choice of colours. String-based printing. 16 | # Two sizes of font. 17 | # Draw a BMP image to screen. Must be correctly scaled, and upside down! 18 | # Graphics: rectangles, lines, circles 19 | # "Bat and ball" animation 20 | 21 | from smartGPIO import GPIO 22 | from lib_tft144 import TFT144 23 | from time import sleep 24 | 25 | 26 | 27 | if GPIO.RPI_REVISION == 0: # VIRTUAL-GPIO 28 | RST = 8 29 | CE = 10 # VirtGPIO: the chosen Chip Select pin#. (different from rpi) 30 | DC = 9 31 | LED = 7 32 | spi = GPIO.SpiDev() 33 | # the virtual GPIO module directly supports spidev function 34 | 35 | else: # RPI 36 | GPIO.setwarnings(False) 37 | GPIO.setmode(GPIO.BCM) 38 | RST = 18 # RST may use direct +3V strapping, and then be listed as 0 here. (Soft Reset used instead) 39 | CE = 0 # RPI GPIO: 0 or 1 for CE0 / CE1 number (NOT the pin#) 40 | DC = 22 # Labeled on board as "A0" Command/Data select 41 | LED = 23 # LED may also be strapped direct to +3V, (and then LED=0 here). LED sinks 10-14 mA @ 3V 42 | import spidev 43 | spi = spidev.SpiDev() 44 | 45 | 46 | 47 | # Don't forget the other 2 SPI pins SCK and MOSI (SDA) 48 | 49 | # OK, GPIO (of one variety) is all ready. Now do the LCD demo: 50 | 51 | 52 | TFT = TFT144(GPIO, spi, CE, DC, RST, LED, TFT144.ORIENTATION90, isRedBoard=False) 53 | # TFT = TFT144(GPIO, spi, CE, DC) # the minimalist version 54 | 55 | posx=0 56 | posy=0 57 | print ("Display character set:") 58 | for i in range (32,256): 59 | TFT.put_char(chr(i),posx,posy,TFT.WHITE,TFT.BLACK) 60 | posx+=6 61 | if posx>=121: 62 | posx=0 63 | posy+=8 64 | for i in range (48,123): 65 | TFT.put_char(chr(i),posx,posy,TFT.BLUE,TFT.WHITE) 66 | posx+=6 67 | if posx>=121: 68 | posx=0 69 | posy+=8 70 | sleep(2) 71 | 72 | print ("Screen blank") 73 | TFT.led_on(False) 74 | sleep(2) 75 | TFT.led_on(True) 76 | sleep(7) 77 | 78 | 79 | TFT.put_string("<<< INVERSION >>>",TFT.textX(2),TFT.textY(15),TFT.YELLOW,TFT.RED) 80 | # Note can use "character-based" cursor location instead of pixel-based (textX()) 81 | sleep(2) 82 | 83 | print ("INVERSION test") 84 | for i in range (0,2): 85 | TFT.invert_screen() 86 | sleep (0.5) 87 | TFT.normal_screen() 88 | sleep (0.5) 89 | sleep(3) 90 | 91 | TFT.clear_display(TFT.BLUE) 92 | 93 | 94 | print ("Message:") 95 | TFT.put_string("Hello,World!",21,22,TFT.WHITE,TFT.BLUE,7) 96 | TFT.put_string("g'DAY", 25,80,TFT.RED, TFT.BLUE, 4) 97 | sleep(3) 98 | 99 | print ("BMP image:") 100 | # Prepare your little BMP image first. Correct size. 3 colour (ie 3bytes/pixel format). And rotate it! 101 | # You may need to tinker to get it right. 102 | if GPIO.RPI_REVISION>0: 103 | if TFT.draw_bmp("rpi2.bmp", 26,45): 104 | sleep(6) 105 | else: 106 | # on non-RPI, let's not offend the Foundation 107 | if TFT.draw_bmp("gpio.bmp", 26,45): 108 | sleep(6) 109 | 110 | TFT.draw_bmp("bl.bmp") 111 | sleep(6) 112 | 113 | print ("Rectangle") 114 | TFT.draw_filled_rectangle(0,0,128,64 ,TFT.RED) 115 | TFT.draw_filled_rectangle(0,64,128,128,TFT.BLACK) 116 | for i in range (4,32,4): 117 | TFT.draw_rectangle(i,i,128-i,64-i,TFT.colour565(i-1,i-1,i-1)) 118 | 119 | print ("Line:") 120 | TFT.draw_line(0,0,128,128,TFT.GREEN) 121 | TFT.draw_line(0,128,128,0,TFT.GREEN) 122 | 123 | print ("Circles:") 124 | TFT.draw_circle(64,64,63,TFT.BLUE) 125 | TFT.draw_circle(64,64,53,TFT.BLUE) 126 | TFT.draw_circle(64,64,43,TFT.BLUE) 127 | TFT.draw_circle(64,64,33,TFT.BLUE) 128 | 129 | print ("Rectangles") 130 | TFT.draw_filled_rectangle(0,64,128,128,TFT.BLACK) 131 | TFT.draw_rectangle(0,64,127,127,TFT.BLUE) 132 | 133 | print ("Ball & Bat") 134 | # bat and ball animation 135 | ballX=64 136 | ballY=96 137 | ballSpeed=1 138 | xDir=ballSpeed 139 | yDir=ballSpeed 140 | print ("(CTRL-C to finish ...)") 141 | 142 | while(1): 143 | TFT.draw_filled_rectangle(ballX,ballY,ballX+2,ballY+2,TFT.BLACK) 144 | TFT.draw_filled_rectangle(ballX-2,122,ballX+4,124,TFT.BLACK) 145 | ballX +=xDir 146 | ballY +=yDir 147 | if (ballX>121): 148 | xDir=-ballSpeed 149 | if (ballX<4): 150 | xDir=ballSpeed 151 | if (ballY>120): 152 | yDir=-ballSpeed 153 | if (ballY<66): 154 | yDir=ballSpeed 155 | TFT.draw_filled_rectangle(ballX,ballY,ballX+2,ballY+2,TFT.WHITE) 156 | TFT.draw_filled_rectangle(ballX-2,122,ballX+4,124,TFT.WHITE) 157 | -------------------------------------------------------------------------------- /example-tft144-rpi-only.py: -------------------------------------------------------------------------------- 1 | # example-tft144.py V1.6 2 | # Brian Lavery (C) Oct 2014 brian (at) blavery (dot) com 3 | # Free software. 4 | 5 | # Demonstrates the "BLACK" or "RED" 128x128 SPI TFT board 6 | 7 | # There are 3 variants of this file: 8 | # example-tft144.py 9 | # example-tft144-rpi-only.py <<<<<< THIS ONE 10 | # example-tft144-vgpio-only.py 11 | 12 | 13 | 14 | import RPi.GPIO as GPIO 15 | from lib_tft144 import TFT144 16 | from time import sleep 17 | import spidev 18 | 19 | GPIO.setwarnings(False) 20 | GPIO.setmode(GPIO.BCM) 21 | 22 | RST = 18 23 | CE = 0 # 0 or 1 for CE0 / CE1 number (NOT the pin#) 24 | DC = 22 # Labeled on board as "A0" 25 | LED = 23 # LED backlight sinks 10-14 mA @ 3V 26 | 27 | 28 | 29 | 30 | # Don't forget the other 2 SPI pins SCK and MOSI (SDA) 31 | 32 | TFT = TFT144(GPIO, spidev.SpiDev(), CE, DC, RST, LED, isRedBoard=False) 33 | 34 | 35 | print ("Display character set:") 36 | posx=0 37 | posy=0 38 | # Manual cursor moving 39 | for i in range (32,256): 40 | TFT.put_char(chr(i),posx,posy,TFT.WHITE,TFT.BLACK) 41 | posx+=TFT.fontW 42 | if (posx+TFT.fontW)>128: 43 | posx=0 44 | posy+=TFT.fontH 45 | sleep(2) 46 | 47 | 48 | TFT.clear_display(TFT.BLUE) 49 | 50 | 51 | print ("Message:") 52 | # Automatic cursor moving 53 | TFT.put_string("Hello,World!",28,28,TFT.WHITE,TFT.BLUE) # std font 3 (default) 54 | TFT.put_string("TFT144", 24,80,TFT.RED, TFT.BLUE, 4) # doubled font 4 55 | sleep(3) 56 | 57 | 58 | 59 | print ("Rectangle") 60 | TFT.draw_filled_rectangle(0,0,128,64 ,TFT.RED) 61 | TFT.draw_filled_rectangle(0,64,128,128,TFT.BLACK) 62 | for i in range (4,32,4): 63 | TFT.draw_rectangle(i,i,128-i,64-i,TFT.colour565(i-1,i-1,i-1)) 64 | 65 | print ("Line:") 66 | TFT.draw_line(0,0,128,128,TFT.GREEN) 67 | TFT.draw_line(0,128,128,0,TFT.GREEN) 68 | -------------------------------------------------------------------------------- /example-tft144-vgpio-only.py: -------------------------------------------------------------------------------- 1 | # example-tft144.py V1.6 2 | # Brian Lavery (C) Oct 2014 brian (at) blavery (dot) com 3 | # Free software. 4 | 5 | # Demonstrates the "BLACK" or "RED" 128x128 SPI TFT board 6 | 7 | # There are 3 variants of this file: 8 | # example-tft144.py 9 | # example-tft144-rpi-only.py 10 | # example-tft144-vgpio-only.py <<<<<< THIS ONE 11 | 12 | 13 | 14 | import virtGPIO as GPIO 15 | from lib_tft144 import TFT144 16 | from time import sleep 17 | spidev = GPIO 18 | 19 | RST = 8 20 | CE = 10 # VirtGPIO: the chosen Chip Select pin#. (different meaning from rpi) 21 | DC = 9 22 | LED = 7 23 | spidev = GPIO 24 | 25 | 26 | 27 | # Don't forget the other 2 SPI pins SCK and MOSI (SDA) 28 | 29 | TFT = TFT144(GPIO, spidev.SpiDev(), CE, DC, RST, LED, isRedBoard=False) 30 | 31 | 32 | print ("Display character set:") 33 | posx=0 34 | posy=0 35 | # Manual cursor moving 36 | for i in range (32,256): 37 | TFT.put_char(chr(i),posx,posy,TFT.WHITE,TFT.BLACK) 38 | posx+=TFT.fontW 39 | if (posx+TFT.fontW)>128: 40 | posx=0 41 | posy+=TFT.fontH 42 | sleep(2) 43 | 44 | 45 | TFT.clear_display(TFT.BLUE) 46 | 47 | 48 | print ("Message:") 49 | # Automatic cursor moving 50 | TFT.put_string("Hello,World!",28,28,TFT.WHITE,TFT.BLUE) # std font 3 (default) 51 | TFT.put_string("TFT144", 24,80,TFT.RED, TFT.BLUE, 4) # doubled font 4 52 | sleep(3) 53 | 54 | 55 | 56 | print ("Rectangle") 57 | TFT.draw_filled_rectangle(0,0,128,64 ,TFT.RED) 58 | TFT.draw_filled_rectangle(0,64,128,128,TFT.BLACK) 59 | for i in range (4,32,4): 60 | TFT.draw_rectangle(i,i,128-i,64-i,TFT.colour565(i-1,i-1,i-1)) 61 | 62 | print ("Line:") 63 | TFT.draw_line(0,0,128,128,TFT.GREEN) 64 | TFT.draw_line(0,128,128,0,TFT.GREEN) 65 | -------------------------------------------------------------------------------- /example-tft144.py: -------------------------------------------------------------------------------- 1 | # example-tft144.py V1.6 2 | # Brian Lavery (C) Oct 2014 brian (at) blavery (dot) com 3 | # Free software. 4 | 5 | # Demonstrates the "BLACK" & "RED" 128x128 SPI TFT board 6 | 7 | # There are 3 variants of this file: 8 | # example-tft144.py <<<< THIS ONE - picks virtual or raspberry automatically 9 | # example-tft144-rpi-only.py 10 | # example-tft144-vgpio-only.py 11 | 12 | 13 | 14 | from smartGPIO import GPIO 15 | from lib_tft144 import TFT144 16 | from time import sleep 17 | 18 | 19 | # My tests. Two configurations. 20 | 21 | if GPIO.RPI_REVISION == 0: # VIRTUAL-GPIO 22 | RST = 8 23 | CE = 10 # VirtGPIO: the chosen Chip Select pin#. (different from rpi) 24 | DC = 9 25 | LED = 7 26 | spidev = GPIO 27 | # the virtual GPIO module directly supports spidev function 28 | 29 | else: # RPI 30 | GPIO.setwarnings(False) 31 | GPIO.setmode(GPIO.BCM) 32 | RST = 18 # RST may use direct +3V strapping, and then be listed as 0 here. (Soft Reset used instead) 33 | CE = 0 # RPI GPIO: 0 or 1 for CE0 / CE1 number (NOT the pin#) 34 | DC = 22 # Labeled on board as "A0" Command/Data select 35 | LED = 23 # LED may also be strapped direct to +3V, (and then LED=0 here). LED sinks 10-14 mA @ 3V 36 | import spidev 37 | 38 | 39 | 40 | # Don't forget the other 2 SPI pins SCK and MOSI (SDA) 41 | 42 | TFT = TFT144(GPIO, spidev.SpiDev(), CE, DC, RST, LED, isRedBoard=False) 43 | 44 | 45 | print ("Display character set:") 46 | posx=0 47 | posy=0 48 | # Manual cursor moving 49 | for i in range (32,256): 50 | TFT.put_char(chr(i),posx,posy,TFT.WHITE,TFT.BLACK) 51 | posx+=TFT.fontW 52 | if (posx+TFT.fontW)>128: 53 | posx=0 54 | posy+=TFT.fontH 55 | sleep(2) 56 | 57 | 58 | TFT.clear_display(TFT.BLUE) 59 | 60 | 61 | print ("Message:") 62 | # Automatic cursor moving 63 | TFT.put_string("Hello,World!",28,28,TFT.WHITE,TFT.BLUE) # std font 3 (default) 64 | TFT.put_string("TFT144", 24,80,TFT.RED, TFT.BLUE, 4) # doubled font 4 65 | sleep(3) 66 | 67 | 68 | 69 | print ("Rectangle") 70 | TFT.draw_filled_rectangle(0,0,128,64 ,TFT.RED) 71 | TFT.draw_filled_rectangle(0,64,128,128,TFT.BLACK) 72 | for i in range (4,32,4): 73 | TFT.draw_rectangle(i,i,128-i,64-i,TFT.colour565(i-1,i-1,i-1)) 74 | 75 | print ("Line:") 76 | TFT.draw_line(0,0,128,128,TFT.GREEN) 77 | TFT.draw_line(0,128,128,0,TFT.GREEN) 78 | -------------------------------------------------------------------------------- /gpio.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BLavery/LIBtft144/HEAD/gpio.bmp -------------------------------------------------------------------------------- /lcdfonts.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # array 6x8, Unicode set 5 | font6x8=( # Array format 6x8 different from other 3. 6 | [0x00,0x00,0x00,0x00,0x00,0x00], # 0x00 0 7 | [0x00,0x64,0x18,0x04,0x64,0x18], #  0x01 1 8 | [0x00,0x3c,0x40,0x40,0x20,0x7c], #  0x02 2 9 | [0x00,0x0c,0x30,0x40,0x30,0x0c], #  0x03 3 10 | [0x00,0x3c,0x40,0x30,0x40,0x3c], #  0x04 4 11 | [0x00,0x00,0x3e,0x1c,0x08,0x00], #  0x05 5 12 | [0x00,0x04,0x1e,0x1f,0x1e,0x04], #  0x06 6 13 | [0x00,0x10,0x3c,0x7c,0x3c,0x10], #  0x07 7 14 | [0x00,0x20,0x40,0x3e,0x01,0x02], #  0x08 8 15 | [0x00,0x22,0x14,0x08,0x14,0x22], # 0x09 9 16 | [0x00,0x00,0x38,0x28,0x38,0x00], # 0x0a 10 17 | [0x00,0x00,0x10,0x38,0x10,0x00], # 0x0b 11 18 | [0x00,0x00,0x00,0x10,0x00,0x00], # 0x0c 12 19 | [0x00,0x08,0x78,0x08,0x00,0x00], # 0x0d 13 20 | [0x00,0x00,0x15,0x15,0x0a,0x00], #  0x0e 14 21 | [0x00,0x7f,0x7f,0x09,0x09,0x01], #  0x0f 15 22 | [0x00,0x10,0x20,0x7f,0x01,0x01], #  0x10 16 23 | [0x00,0x04,0x04,0x00,0x01,0x1f], #  0x11 17 24 | [0x00,0x00,0x19,0x15,0x12,0x00], #  0x12 18 25 | [0x00,0x40,0x60,0x50,0x48,0x44], #  0x13 19 26 | [0x00,0x06,0x09,0x09,0x06,0x00], #  0x14 20 27 | [0x00,0x0f,0x02,0x01,0x01,0x00], #  0x15 21 28 | [0x00,0x00,0x01,0x1f,0x01,0x00], #  0x16 22 29 | [0x00,0x44,0x44,0x4a,0x4a,0x51], #  0x17 23 30 | [0x00,0x14,0x74,0x1c,0x17,0x14], #  0x18 24 31 | [0x00,0x51,0x4a,0x4a,0x44,0x44], #  0x19 25 32 | [0x00,0x00,0x00,0x04,0x04,0x04], # 0x1a 26 33 | [0x00,0x00,0x7c,0x54,0x54,0x44], #  0x1b 27 34 | [0x00,0x08,0x08,0x2a,0x1c,0x08], #  0x1c 28 35 | [0x00,0x7c,0x00,0x7c,0x44,0x7c], #  0x1d 29 36 | [0x00,0x04,0x02,0x7f,0x02,0x04], #  0x1e 30 37 | [0x00,0x10,0x20,0x7f,0x20,0x10], #  0x1f 31 38 | [0x00,0x00,0x00,0x00,0x00,0x00], # 0x20 32 39 | [0x00,0x00,0x00,0x6f,0x00,0x00], # ! 0x21 33 40 | [0x00,0x00,0x07,0x00,0x07,0x00], # " 0x22 34 41 | [0x00,0x14,0x7f,0x14,0x7f,0x14], # # 0x23 35 42 | [0x00,0x00,0x07,0x04,0x1e,0x00], # $ 0x24 36 43 | [0x00,0x23,0x13,0x08,0x64,0x62], # % 0x25 37 44 | [0x00,0x36,0x49,0x56,0x20,0x50], # & 0x26 38 45 | [0x00,0x00,0x00,0x07,0x00,0x00], # ' 0x27 39 46 | [0x00,0x00,0x1c,0x22,0x41,0x00], # ( 0x28 40 47 | [0x00,0x00,0x41,0x22,0x1c,0x00], # ) 0x29 41 48 | [0x00,0x14,0x08,0x3e,0x08,0x14], # * 0x2a 42 49 | [0x00,0x08,0x08,0x3e,0x08,0x08], # + 0x2b 43 50 | [0x00,0x00,0x50,0x30,0x00,0x00], # , 0x2c 44 51 | [0x00,0x08,0x08,0x08,0x08,0x08], # - 0x2d 45 52 | [0x00,0x00,0x60,0x60,0x00,0x00], # . 0x2e 46 53 | [0x00,0x20,0x10,0x08,0x04,0x02], # / 0x2f 47 54 | [0x00,0x3e,0x51,0x49,0x45,0x3e], # 0 0x30 48 55 | [0x00,0x00,0x42,0x7f,0x40,0x00], # 1 0x31 49 56 | [0x00,0x42,0x61,0x51,0x49,0x46], # 2 0x32 50 57 | [0x00,0x21,0x41,0x45,0x4b,0x31], # 3 0x33 51 58 | [0x00,0x18,0x14,0x12,0x7f,0x10], # 4 0x34 52 59 | [0x00,0x27,0x45,0x45,0x45,0x39], # 5 0x35 53 60 | [0x00,0x3c,0x4a,0x49,0x49,0x30], # 6 0x36 54 61 | [0x00,0x01,0x71,0x09,0x05,0x03], # 7 0x37 55 62 | [0x00,0x36,0x49,0x49,0x49,0x36], # 8 0x38 56 63 | [0x00,0x06,0x49,0x49,0x29,0x1e], # 9 0x39 57 64 | [0x00,0x00,0x36,0x36,0x00,0x00], # : 0x3a 58 65 | [0x00,0x00,0x56,0x36,0x00,0x00], # ; 0x3b 59 66 | [0x00,0x08,0x14,0x22,0x41,0x00], # < 0x3c 60 67 | [0x00,0x14,0x14,0x14,0x14,0x14], # = 0x3d 61 68 | [0x00,0x00,0x41,0x22,0x14,0x08], # > 0x3e 62 69 | [0x00,0x02,0x01,0x51,0x09,0x06], # ? 0x3f 63 70 | [0x00,0x3e,0x41,0x5d,0x49,0x4e], # @ 0x40 64 71 | [0x00,0x7e,0x09,0x09,0x09,0x7e], # A 0x41 65 72 | [0x00,0x7f,0x49,0x49,0x49,0x36], # B 0x42 66 73 | [0x00,0x3e,0x41,0x41,0x41,0x22], # C 0x43 67 74 | [0x00,0x7f,0x41,0x41,0x41,0x3e], # D 0x44 68 75 | [0x00,0x7f,0x49,0x49,0x49,0x41], # E 0x45 69 76 | [0x00,0x7f,0x09,0x09,0x09,0x01], # F 0x46 70 77 | [0x00,0x3e,0x41,0x49,0x49,0x7a], # G 0x47 71 78 | [0x00,0x7f,0x08,0x08,0x08,0x7f], # H 0x48 72 79 | [0x00,0x00,0x41,0x7f,0x41,0x00], # I 0x49 73 80 | [0x00,0x20,0x40,0x41,0x3f,0x01], # J 0x4a 74 81 | [0x00,0x7f,0x08,0x14,0x22,0x41], # K 0x4b 75 82 | [0x00,0x7f,0x40,0x40,0x40,0x40], # L 0x4c 76 83 | [0x00,0x7f,0x02,0x0c,0x02,0x7f], # M 0x4d 77 84 | [0x00,0x7f,0x04,0x08,0x10,0x7f], # N 0x4e 78 85 | [0x00,0x3e,0x41,0x41,0x41,0x3e], # O 0x4f 79 86 | [0x00,0x7f,0x09,0x09,0x09,0x06], # P 0x50 80 87 | [0x00,0x3e,0x41,0x51,0x21,0x5e], # Q 0x51 81 88 | [0x00,0x7f,0x09,0x19,0x29,0x46], # R 0x52 82 89 | [0x00,0x46,0x49,0x49,0x49,0x31], # S 0x53 83 90 | [0x00,0x01,0x01,0x7f,0x01,0x01], # T 0x54 84 91 | [0x00,0x3f,0x40,0x40,0x40,0x3f], # U 0x55 85 92 | [0x00,0x0f,0x30,0x40,0x30,0x0f], # V 0x56 86 93 | [0x00,0x3f,0x40,0x30,0x40,0x3f], # W 0x57 87 94 | [0x00,0x63,0x14,0x08,0x14,0x63], # X 0x58 88 95 | [0x00,0x07,0x08,0x70,0x08,0x07], # Y 0x59 89 96 | [0x00,0x61,0x51,0x49,0x45,0x43], # Z 0x5a 90 97 | [0x00,0x3c,0x4a,0x49,0x29,0x1e], # [ 0x5b 91 98 | [0x00,0x02,0x04,0x08,0x10,0x20], # \ 0x5c 92 99 | [0x00,0x00,0x41,0x7f,0x00,0x00], # ] 0x5d 93 100 | [0x00,0x04,0x02,0x01,0x02,0x04], # ^ 0x5e 94 101 | [0x00,0x40,0x40,0x40,0x40,0x40], # _ 0x5f 95 102 | [0x00,0x00,0x00,0x03,0x04,0x00], # ` 0x60 96 103 | [0x00,0x20,0x54,0x54,0x54,0x78], # a 0x61 97 104 | [0x00,0x7f,0x48,0x44,0x44,0x38], # b 0x62 98 105 | [0x00,0x38,0x44,0x44,0x44,0x20], # c 0x63 99 106 | [0x00,0x38,0x44,0x44,0x48,0x7f], # d 0x64 100 107 | [0x00,0x38,0x54,0x54,0x54,0x18], # e 0x65 101 108 | [0x00,0x08,0x7e,0x09,0x01,0x02], # f 0x66 102 109 | [0x00,0x0c,0x52,0x52,0x52,0x3e], # g 0x67 103 110 | [0x00,0x7f,0x08,0x04,0x04,0x78], # h 0x68 104 111 | [0x00,0x00,0x44,0x7d,0x40,0x00], # i 0x69 105 112 | [0x00,0x20,0x40,0x44,0x3d,0x00], # j 0x6a 106 113 | [0x00,0x00,0x7f,0x10,0x28,0x44], # k 0x6b 107 114 | [0x00,0x00,0x41,0x7f,0x40,0x00], # l 0x6c 108 115 | [0x00,0x7c,0x04,0x18,0x04,0x78], # m 0x6d 109 116 | [0x00,0x7c,0x08,0x04,0x04,0x78], # n 0x6e 110 117 | [0x00,0x38,0x44,0x44,0x44,0x38], # o 0x6f 111 118 | [0x00,0x7c,0x14,0x14,0x14,0x08], # p 0x70 112 119 | [0x00,0x08,0x14,0x14,0x18,0x7c], # q 0x71 113 120 | [0x00,0x7c,0x08,0x04,0x04,0x08], # r 0x72 114 121 | [0x00,0x48,0x54,0x54,0x54,0x20], # s 0x73 115 122 | [0x00,0x04,0x3f,0x44,0x40,0x20], # t 0x74 116 123 | [0x00,0x3c,0x40,0x40,0x20,0x7c], # u 0x75 117 124 | [0x00,0x1c,0x20,0x40,0x20,0x1c], # v 0x76 118 125 | [0x00,0x3c,0x40,0x30,0x40,0x3c], # w 0x77 119 126 | [0x00,0x44,0x28,0x10,0x28,0x44], # x 0x78 120 127 | [0x00,0x0c,0x50,0x50,0x50,0x3c], # y 0x79 121 128 | [0x00,0x44,0x64,0x54,0x4c,0x44], # z 0x7a 122 129 | [0x00,0x00,0x08,0x36,0x41,0x41], # [ 0x7b 123 130 | [0x00,0x00,0x00,0x7f,0x00,0x00], # | 0x7c 124 131 | [0x00,0x41,0x41,0x36,0x08,0x00], # ] 0x7d 125 132 | [0x00,0x04,0x02,0x04,0x08,0x04], # ~ 0x7e 126 133 | [0x00,0x7f,0x6b,0x6b,0x6b,0x7f], # 0x7f 127 134 | [0x00,0x00,0x7c,0x44,0x7c,0x00], # ¬ 0x80 128 135 | [0x00,0x00,0x08,0x7c,0x00,0x00], # ? 0x81 129 136 | [0x00,0x00,0x64,0x54,0x48,0x00], # ‚ 0x82 130 137 | [0x00,0x00,0x44,0x54,0x28,0x00], # ƒ 0x83 131 138 | [0x00,0x00,0x1c,0x10,0x78,0x00], # „ 0x84 132 139 | [0x00,0x00,0x5c,0x54,0x24,0x00], # … 0x85 133 140 | [0x00,0x00,0x78,0x54,0x74,0x00], # † 0x86 134 141 | [0x00,0x00,0x64,0x14,0x0c,0x00], # ‡ 0x87 135 142 | [0x00,0x00,0x7c,0x54,0x7c,0x00], # ˆ 0x88 136 143 | [0x00,0x00,0x5c,0x54,0x3c,0x00], # ‰ 0x89 137 144 | [0x00,0x78,0x24,0x26,0x25,0x78], # Š 0x8a 138 145 | [0x00,0x78,0x25,0x26,0x24,0x78], # ‹ 0x8b 139 146 | [0x00,0x70,0x2a,0x29,0x2a,0x70], # Œ 0x8c 140 147 | [0x00,0x78,0x25,0x24,0x25,0x78], # ? 0x8d 141 148 | [0x00,0x20,0x54,0x56,0x55,0x78], # ] 0x8e 142 149 | [0x00,0x20,0x55,0x56,0x54,0x78], # ? 0x8f 143 150 | [0x00,0x20,0x56,0x55,0x56,0x78], # ? 0x90 144 151 | [0x00,0x20,0x55,0x54,0x55,0x78], # ‘ 0x91 145 152 | [0x00,0x7c,0x54,0x56,0x55,0x44], # ’ 0x92 146 153 | [0x00,0x7c,0x55,0x56,0x54,0x44], # “ 0x93 147 154 | [0x00,0x7c,0x56,0x55,0x56,0x44], # ” 0x94 148 155 | [0x00,0x7c,0x55,0x54,0x55,0x44], # • 0x95 149 156 | [0x00,0x38,0x54,0x56,0x55,0x18], # – 0x96 150 157 | [0x00,0x38,0x55,0x56,0x54,0x18], # — 0x97 151 158 | [0x00,0x38,0x56,0x55,0x56,0x18], # ˜ 0x98 152 159 | [0x00,0x38,0x55,0x54,0x55,0x18], # ™ 0x99 153 160 | [0x00,0x00,0x44,0x7e,0x45,0x00], # š 0x9a 154 161 | [0x00,0x00,0x45,0x7e,0x44,0x00], # › 0x9b 155 162 | [0x00,0x00,0x46,0x7d,0x46,0x00], # œ 0x9c 156 163 | [0x00,0x00,0x45,0x7c,0x45,0x00], # ? 0x9d 157 164 | [0x00,0x00,0x48,0x7a,0x41,0x00], # ~ 0x9e 158 165 | [0x00,0x00,0x49,0x7a,0x40,0x00], # Ÿ 0x9f 159 166 | [0x00,0x00,0x4a,0x79,0x42,0x00], # 0xa0 160 167 | [0x00,0x00,0x49,0x78,0x41,0x00], # ¡ 0xa1 161 168 | [0x00,0x38,0x44,0x46,0x45,0x38], # ¢ 0xa2 162 169 | [0x00,0x38,0x45,0x46,0x44,0x38], # £ 0xa3 163 170 | [0x00,0x38,0x46,0x45,0x46,0x38], # ¤ 0xa4 164 171 | [0x00,0x38,0x45,0x44,0x45,0x38], # ¥ 0xa5 165 172 | [0x00,0x30,0x48,0x4a,0x49,0x30], # ¦ 0xa6 166 173 | [0x00,0x30,0x49,0x4a,0x48,0x30], # § 0xa7 167 174 | [0x00,0x30,0x4a,0x49,0x4a,0x30], # ¨ 0xa8 168 175 | [0x00,0x30,0x49,0x48,0x49,0x30], # © 0xa9 169 176 | [0x00,0x3c,0x40,0x42,0x41,0x3c], # ª 0xaa 170 177 | [0x00,0x3c,0x41,0x42,0x40,0x3c], # « 0xab 171 178 | [0x00,0x3c,0x42,0x41,0x42,0x3c], # ¬ 0xac 172 179 | [0x00,0x3c,0x41,0x40,0x41,0x3c], # ­ 0xad 173 180 | [0x00,0x3c,0x40,0x42,0x21,0x7c], # ® 0xae 174 181 | [0x00,0x3c,0x41,0x42,0x20,0x7c], # ¯ 0xaf 175 182 | [0x00,0x38,0x42,0x41,0x22,0x78], # ° 0xb0 176 183 | [0x00,0x3c,0x41,0x40,0x21,0x7c], # ± 0xb1 177 184 | [0x00,0x4e,0x51,0x71,0x11,0x0a], # ² 0xb2 178 185 | [0x00,0x58,0x64,0x64,0x24,0x10], # ³ 0xb3 179 186 | [0x00,0x7c,0x0a,0x11,0x22,0x7d], # ´ 0xb4 180 187 | [0x00,0x78,0x12,0x09,0x0a,0x71], # µ 0xb5 181 188 | [0x00,0x00,0x00,0x04,0x02,0x01], # ¶ 0xb6 182 189 | [0x00,0x01,0x02,0x04,0x00,0x00], # · 0xb7 183 190 | [0x00,0x00,0x02,0x00,0x02,0x00], # ¸ 0xb8 184 191 | [0x00,0x30,0x48,0x45,0x40,0x20], # ¹ 0xb9 185 192 | [0x00,0x00,0x00,0x7b,0x00,0x00], # º 0xba 186 193 | [0x00,0x38,0x44,0x44,0x38,0x44], # » 0xbb 187 194 | [0x00,0x40,0x3e,0x49,0x49,0x36], # ¼ 0xbc 188 195 | [0x00,0x08,0x04,0x08,0x70,0x0c], # ½ 0xbd 189 196 | [0x00,0x60,0x50,0x48,0x50,0x60], # ¾ 0xbe 190 197 | [0x00,0x20,0x52,0x55,0x59,0x30], # ¿ 0xbf 191 198 | [0x00,0x38,0x54,0x54,0x54,0x00], # À 0xc0 192 199 | [0x00,0x00,0x00,0x7f,0x41,0x00], # Á 0xc1 193 200 | [0x00,0x40,0x22,0x14,0x18,0x60], #  0xc2 194 201 | [0x00,0x7c,0x20,0x20,0x1c,0x20], # à 0xc3 195 202 | [0x00,0x44,0x3c,0x04,0x7c,0x44], # Ä 0xc4 196 203 | [0x00,0x40,0x3c,0x12,0x12,0x0c], # Å 0xc5 197 204 | [0x00,0x41,0x63,0x55,0x49,0x41], # Æ 0xc6 198 205 | [0x00,0x38,0x44,0x44,0x3c,0x04], # Ç 0xc7 199 206 | [0x00,0x08,0x04,0x3c,0x44,0x24], # È 0xc8 200 207 | [0x00,0x08,0x14,0x7f,0x14,0x08], # É 0xc9 201 208 | [0x00,0x4e,0x71,0x01,0x71,0x4e], # Ê 0xca 202 209 | [0x00,0x45,0x29,0x11,0x29,0x45], # Ë 0xcb 203 210 | [0x00,0x0d,0x51,0x51,0x51,0x3d], # Ì 0xcc 204 211 | [0x00,0x00,0x00,0x05,0x02,0x05], # Í 0xcd 205 212 | [0x00,0x40,0x00,0x40,0x00,0x40], # Î 0xce 206 213 | [0x00,0x00,0x08,0x1c,0x3e,0x00], # Ï 0xcf 207 214 | [0x00,0x1c,0x1c,0x1c,0x00,0x00], # Ð 0xd0 208 215 | [0x00,0x00,0x70,0x08,0x07,0x00], # Ñ 0xd1 209 216 | [0x00,0x00,0x08,0x08,0x08,0x00], # Ò 0xd2 210 217 | [0x00,0x00,0x1d,0x15,0x17,0x00], # Ó 0xd3 211 218 | [0x00,0x00,0x07,0x05,0x07,0x00], # Ô 0xd4 212 219 | [0x00,0x00,0x11,0x15,0x0a,0x00], # Õ 0xd5 213 220 | [0x00,0x00,0x00,0x00,0x00,0x00], # Ö 0xd6 214 221 | [0x00,0x04,0x3c,0x41,0x20,0x00], # × 0xd7 215 222 | [0x00,0x7c,0x16,0x15,0x16,0x08], # Ø 0xd8 216 223 | [0x00,0x21,0x16,0x08,0x34,0x42], # Ù 0xd9 217 224 | [0x00,0x7f,0x09,0x1d,0x01,0x03], # Ú 0xda 218 225 | [0x00,0x38,0x54,0x54,0x14,0x08], # Û 0xdb 219 226 | [0x00,0x00,0x00,0x7c,0x40,0x40], # Ü 0xdc 220 227 | [0x00,0x7f,0x0e,0x1c,0x38,0x7f], # Ý 0xdd 221 228 | [0x00,0x41,0x22,0x5d,0x22,0x1c], # Þ 0xde 222 229 | [0x00,0x1c,0x3e,0x1c,0x08,0x00], # ß 0xdf 223 230 | [0x00,0x7f,0x7f,0x7f,0x7f,0x7f], # à 0xe0 224 231 | [0x00,0x77,0x7b,0x01,0x7b,0x77], # á 0xe1 225 232 | [0x00,0x7f,0x43,0x75,0x43,0x7f], # â 0xe2 226 233 | [0x00,0x7f,0x6f,0x55,0x43,0x7f], # ã 0xe3 227 234 | [0x00,0x40,0x40,0x40,0x40,0x40], # ä 0xe4 228 235 | [0x00,0x44,0x42,0x5f,0x42,0x44], # å 0xe5 229 236 | [0x00,0x40,0x5e,0x45,0x5e,0x40], # æ 0xe6 230 237 | [0x00,0x40,0x48,0x55,0x5e,0x40], # ç 0xe7 231 238 | [0x00,0x00,0x04,0x08,0x10,0x20], # è 0xe8 232 239 | [0x00,0x03,0x07,0x0e,0x1c,0x38], # é 0xe9 233 240 | [0x00,0x01,0x03,0x07,0x0f,0x1f], # ê 0xea 234 241 | [0x00,0x7c,0x78,0x70,0x60,0x40], # ë 0xeb 235 242 | [0x00,0x08,0x08,0x1c,0x22,0x1c], # ì 0xec 236 243 | [0x00,0x00,0x1c,0x22,0x1c,0x00], # í 0xed 237 244 | [0x00,0x02,0x00,0x08,0x00,0x20], # î 0xee 238 245 | [0x00,0x04,0x3e,0x3f,0x3e,0x04], # ï 0xef 239 246 | [0x00,0x10,0x3e,0x7e,0x3e,0x10], # ð 0xf0 240 247 | [0x00,0x55,0x2a,0x55,0x2a,0x55], # ñ 0xf1 241 248 | [0x00,0x24,0x2a,0x7f,0x2a,0x12], # ò 0xf2 242 249 | [0x00,0x04,0x1e,0x1f,0x1e,0x04], # ó 0xf3 243 250 | [0x00,0x00,0x00,0x00,0x00,0x00], # ô 0xf4 244 251 | [0x00,0x00,0x00,0x00,0x00,0x00], # õ 0xf5 245 252 | [0x00,0x00,0x00,0x00,0x00,0x00], # ö 0xf6 246 253 | [0x00,0x00,0x00,0x00,0x00,0x00], # ÷ 0xf7 247 254 | [0xf0,0xf0,0xf0,0x00,0x00,0x00], # 0xf8 248 255 | [0x00,0x00,0x00,0xf0,0xf0,0xf0], # 0xf9 249 256 | [0x0f,0x0f,0x0f,0x00,0x00,0x00], # 0xfa 250 257 | [0x00,0x00,0x00,0x0f,0x0f,0x0f], # 0xfb 251 258 | [0x24,0xff,0x24,0x24,0xff,0x24], # 0xfc 252 259 | [0x10,0x10,0x10,0xff,0x10,0x10], # 0xfd 253 260 | [0x55,0xaa,0x55,0xaa,0x55,0xaa], # 0xfe 254 261 | [0xff,0xff,0xff,0xff,0xff,0xff]) # 0xff 255 262 | # Added a few old-fashioned block graphic characters at the end of this! BL 263 | 264 | 265 | font8x16=( 266 | [0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00], # 0x20 32 267 | [0x00,0x00,0x00,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x00,0x00,0x18,0x18,0x00,0x00], 268 | [0x00,0x48,0x6C,0x24,0x12,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00], 269 | [0x00,0x00,0x00,0x24,0x24,0x24,0x7F,0x12,0x12,0x12,0x7F,0x12,0x12,0x12,0x00,0x00], 270 | [0x00,0x00,0x08,0x1C,0x2A,0x2A,0x0A,0x0C,0x18,0x28,0x28,0x2A,0x2A,0x1C,0x08,0x08], 271 | [0x00,0x00,0x00,0x22,0x25,0x15,0x15,0x15,0x2A,0x58,0x54,0x54,0x54,0x22,0x00,0x00], 272 | [0x00,0x00,0x00,0x0C,0x12,0x12,0x12,0x0A,0x76,0x25,0x29,0x11,0x91,0x6E,0x00,0x00], 273 | [0x00,0x06,0x06,0x04,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00], 274 | [0x00,0x40,0x20,0x10,0x10,0x08,0x08,0x08,0x08,0x08,0x08,0x10,0x10,0x20,0x40,0x00], 275 | [0x00,0x02,0x04,0x08,0x08,0x10,0x10,0x10,0x10,0x10,0x10,0x08,0x08,0x04,0x02,0x00], 276 | [0x00,0x00,0x00,0x00,0x08,0x08,0x6B,0x1C,0x1C,0x6B,0x08,0x08,0x00,0x00,0x00,0x00], 277 | [0x00,0x00,0x00,0x00,0x08,0x08,0x08,0x08,0x7F,0x08,0x08,0x08,0x08,0x00,0x00,0x00], 278 | [0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x06,0x04,0x03], 279 | [0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00], 280 | [0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x06,0x00,0x00], 281 | [0x00,0x00,0x80,0x40,0x40,0x20,0x20,0x10,0x10,0x08,0x08,0x04,0x04,0x02,0x02,0x00], 282 | [0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x24,0x18,0x00,0x00], 283 | [0x00,0x00,0x00,0x08,0x0E,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x3E,0x00,0x00], 284 | [0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x20,0x20,0x10,0x08,0x04,0x42,0x7E,0x00,0x00], 285 | [0x00,0x00,0x00,0x3C,0x42,0x42,0x20,0x18,0x20,0x40,0x40,0x42,0x22,0x1C,0x00,0x00], 286 | [0x00,0x00,0x00,0x20,0x30,0x28,0x24,0x24,0x22,0x22,0x7E,0x20,0x20,0x78,0x00,0x00], 287 | [0x00,0x00,0x00,0x7E,0x02,0x02,0x02,0x1A,0x26,0x40,0x40,0x42,0x22,0x1C,0x00,0x00], 288 | [0x00,0x00,0x00,0x38,0x24,0x02,0x02,0x1A,0x26,0x42,0x42,0x42,0x24,0x18,0x00,0x00], 289 | [0x00,0x00,0x00,0x7E,0x22,0x22,0x10,0x10,0x08,0x08,0x08,0x08,0x08,0x08,0x00,0x00], 290 | [0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x24,0x18,0x24,0x42,0x42,0x42,0x3C,0x00,0x00], 291 | [0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x42,0x64,0x58,0x40,0x40,0x24,0x1C,0x00,0x00], 292 | [0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00], 293 | [0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x08,0x08,0x04], 294 | [0x00,0x00,0x00,0x40,0x20,0x10,0x08,0x04,0x02,0x04,0x08,0x10,0x20,0x40,0x00,0x00], 295 | [0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x00,0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00], 296 | [0x00,0x00,0x00,0x02,0x04,0x08,0x10,0x20,0x40,0x20,0x10,0x08,0x04,0x02,0x00,0x00], 297 | [0x00,0x00,0x00,0x3C,0x42,0x42,0x46,0x40,0x20,0x10,0x10,0x00,0x18,0x18,0x00,0x00], 298 | [0x00,0x00,0x00,0x1C,0x22,0x5A,0x55,0x55,0x55,0x55,0x2D,0x42,0x22,0x1C,0x00,0x00], 299 | [0x00,0x00,0x00,0x08,0x08,0x18,0x14,0x14,0x24,0x3C,0x22,0x42,0x42,0xE7,0x00,0x00], 300 | [0x00,0x00,0x00,0x1F,0x22,0x22,0x22,0x1E,0x22,0x42,0x42,0x42,0x22,0x1F,0x00,0x00], 301 | [0x00,0x00,0x00,0x7C,0x42,0x42,0x01,0x01,0x01,0x01,0x01,0x42,0x22,0x1C,0x00,0x00], 302 | [0x00,0x00,0x00,0x1F,0x22,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x22,0x1F,0x00,0x00], 303 | [0x00,0x00,0x00,0x3F,0x42,0x12,0x12,0x1E,0x12,0x12,0x02,0x42,0x42,0x3F,0x00,0x00], 304 | [0x00,0x00,0x00,0x3F,0x42,0x12,0x12,0x1E,0x12,0x12,0x02,0x02,0x02,0x07,0x00,0x00], 305 | [0x00,0x00,0x00,0x3C,0x22,0x22,0x01,0x01,0x01,0x71,0x21,0x22,0x22,0x1C,0x00,0x00], 306 | [0x00,0x00,0x00,0xE7,0x42,0x42,0x42,0x42,0x7E,0x42,0x42,0x42,0x42,0xE7,0x00,0x00], 307 | [0x00,0x00,0x00,0x3E,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x3E,0x00,0x00], 308 | [0x00,0x00,0x00,0x7C,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x11,0x0F], 309 | [0x00,0x00,0x00,0x77,0x22,0x12,0x0A,0x0E,0x0A,0x12,0x12,0x22,0x22,0x77,0x00,0x00], 310 | [0x00,0x00,0x00,0x07,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x42,0x7F,0x00,0x00], 311 | [0x00,0x00,0x00,0x77,0x36,0x36,0x36,0x36,0x2A,0x2A,0x2A,0x2A,0x2A,0x6B,0x00,0x00], 312 | [0x00,0x00,0x00,0xE3,0x46,0x46,0x4A,0x4A,0x52,0x52,0x52,0x62,0x62,0x47,0x00,0x00], 313 | [0x00,0x00,0x00,0x1C,0x22,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x22,0x1C,0x00,0x00], 314 | [0x00,0x00,0x00,0x3F,0x42,0x42,0x42,0x42,0x3E,0x02,0x02,0x02,0x02,0x07,0x00,0x00], 315 | [0x00,0x00,0x00,0x1C,0x22,0x41,0x41,0x41,0x41,0x41,0x4D,0x53,0x32,0x1C,0x60,0x00], 316 | [0x00,0x00,0x00,0x3F,0x42,0x42,0x42,0x3E,0x12,0x12,0x22,0x22,0x42,0xC7,0x00,0x00], 317 | [0x00,0x00,0x00,0x7C,0x42,0x42,0x02,0x04,0x18,0x20,0x40,0x42,0x42,0x3E,0x00,0x00], 318 | [0x00,0x00,0x00,0x7F,0x49,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x1C,0x00,0x00], 319 | [0x00,0x00,0x00,0xE7,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x3C,0x00,0x00], 320 | [0x00,0x00,0x00,0xE7,0x42,0x42,0x22,0x24,0x24,0x14,0x14,0x18,0x08,0x08,0x00,0x00], 321 | [0x00,0x00,0x00,0x6B,0x49,0x49,0x49,0x49,0x55,0x55,0x36,0x22,0x22,0x22,0x00,0x00], 322 | [0x00,0x00,0x00,0xE7,0x42,0x24,0x24,0x18,0x18,0x18,0x24,0x24,0x42,0xE7,0x00,0x00], 323 | [0x00,0x00,0x00,0x77,0x22,0x22,0x14,0x14,0x08,0x08,0x08,0x08,0x08,0x1C,0x00,0x00], 324 | [0x00,0x00,0x00,0x7E,0x21,0x20,0x10,0x10,0x08,0x04,0x04,0x42,0x42,0x3F,0x00,0x00], 325 | [0x00,0x78,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x78,0x00], 326 | [0x00,0x00,0x02,0x02,0x04,0x04,0x08,0x08,0x08,0x10,0x10,0x20,0x20,0x20,0x40,0x40], 327 | [0x00,0x1E,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x1E,0x00], 328 | [0x00,0x38,0x44,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00], 329 | [0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF], 330 | [0x00,0x06,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00], 331 | [0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x42,0x78,0x44,0x42,0x42,0xFC,0x00,0x00], 332 | [0x00,0x00,0x00,0x03,0x02,0x02,0x02,0x1A,0x26,0x42,0x42,0x42,0x26,0x1A,0x00,0x00], 333 | [0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x44,0x02,0x02,0x02,0x44,0x38,0x00,0x00], 334 | [0x00,0x00,0x00,0x60,0x40,0x40,0x40,0x78,0x44,0x42,0x42,0x42,0x64,0xD8,0x00,0x00], 335 | [0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x42,0x7E,0x02,0x02,0x42,0x3C,0x00,0x00], 336 | [0x00,0x00,0x00,0xF0,0x88,0x08,0x08,0x7E,0x08,0x08,0x08,0x08,0x08,0x3E,0x00,0x00], 337 | [0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7C,0x22,0x22,0x1C,0x02,0x3C,0x42,0x42,0x3C], 338 | [0x00,0x00,0x00,0x03,0x02,0x02,0x02,0x3A,0x46,0x42,0x42,0x42,0x42,0xE7,0x00,0x00], 339 | [0x00,0x00,0x00,0x0C,0x0C,0x00,0x00,0x0E,0x08,0x08,0x08,0x08,0x08,0x3E,0x00,0x00], 340 | [0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x38,0x20,0x20,0x20,0x20,0x20,0x20,0x22,0x1E], 341 | [0x00,0x00,0x00,0x03,0x02,0x02,0x02,0x72,0x12,0x0A,0x16,0x12,0x22,0x77,0x00,0x00], 342 | [0x00,0x00,0x00,0x0E,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x3E,0x00,0x00], 343 | [0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x92,0x92,0x92,0x92,0x92,0xB7,0x00,0x00], 344 | [0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3B,0x46,0x42,0x42,0x42,0x42,0xE7,0x00,0x00], 345 | [0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x42,0x42,0x3C,0x00,0x00], 346 | [0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1B,0x26,0x42,0x42,0x42,0x22,0x1E,0x02,0x07], 347 | [0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x78,0x44,0x42,0x42,0x42,0x44,0x78,0x40,0xE0], 348 | [0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x77,0x4C,0x04,0x04,0x04,0x04,0x1F,0x00,0x00], 349 | [0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7C,0x42,0x02,0x3C,0x40,0x42,0x3E,0x00,0x00], 350 | [0x00,0x00,0x00,0x00,0x00,0x08,0x08,0x3E,0x08,0x08,0x08,0x08,0x08,0x30,0x00,0x00], 351 | [0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x63,0x42,0x42,0x42,0x42,0x62,0xDC,0x00,0x00], 352 | [0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE7,0x42,0x24,0x24,0x14,0x08,0x08,0x00,0x00], 353 | [0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xEB,0x49,0x49,0x55,0x55,0x22,0x22,0x00,0x00], 354 | [0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x76,0x24,0x18,0x18,0x18,0x24,0x6E,0x00,0x00], 355 | [0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE7,0x42,0x24,0x24,0x14,0x18,0x08,0x08,0x07], 356 | [0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0x22,0x10,0x08,0x08,0x44,0x7E,0x00,0x00], 357 | [0x00,0xC0,0x20,0x20,0x20,0x20,0x20,0x10,0x20,0x20,0x20,0x20,0x20,0x20,0xC0,0x00], 358 | [0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10], 359 | [0x00,0x06,0x08,0x08,0x08,0x08,0x08,0x10,0x08,0x08,0x08,0x08,0x08,0x08,0x06,0x00], 360 | [0x0C,0x32,0xC2,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00]) # ~ 0x7e 126 361 | 362 | 363 | font8x12=( 364 | 365 | [0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00], # 32 366 | [0x00,0x10,0x10,0x10,0x10,0x10,0x00,0x00,0x10,0x00,0x00,0x00,0x00], 367 | [0x00,0x6C,0x6C,0x24,0x24,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00], 368 | [0x48,0x48,0x24,0x7E,0x24,0x24,0x7E,0x24,0x12,0x12,0x00,0x00,0x00], 369 | [0x10,0x38,0x24,0x04,0x18,0x20,0x24,0x1C,0x10,0x10,0x00,0x00,0x00], 370 | [0x00,0x04,0x0A,0x04,0x30,0x0E,0x10,0x28,0x10,0x00,0x00,0x00,0x00], 371 | [0x00,0x00,0x70,0x08,0x08,0x18,0x54,0x24,0x78,0x00,0x00,0x00,0x00], 372 | [0x00,0x08,0x08,0x08,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00], 373 | [0x00,0x20,0x20,0x10,0x10,0x10,0x10,0x10,0x10,0x20,0x20,0x00,0x00], 374 | [0x00,0x04,0x04,0x08,0x08,0x08,0x08,0x08,0x08,0x04,0x04,0x00,0x00], 375 | [0x00,0x10,0x7C,0x10,0x28,0x28,0x00,0x00,0x00,0x00,0x00,0x00,0x00], 376 | [0x00,0x00,0x10,0x10,0x10,0xFE,0x10,0x10,0x10,0x00,0x00,0x00,0x00], 377 | [0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x08,0x0C,0x04,0x00,0x00], 378 | [0x00,0x00,0x00,0x00,0x00,0x7E,0x00,0x00,0x00,0x00,0x00,0x00,0x00], 379 | [0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x00], 380 | [0x20,0x20,0x10,0x10,0x08,0x08,0x04,0x04,0x02,0x02,0x00,0x00,0x00], 381 | [0x00,0x3C,0x42,0x42,0x42,0x42,0x42,0x42,0x3C,0x00,0x00,0x00,0x00], 382 | [0x00,0x10,0x1C,0x10,0x10,0x10,0x10,0x10,0x7C,0x00,0x00,0x00,0x00], 383 | [0x00,0x1C,0x22,0x20,0x10,0x08,0x04,0x22,0x3E,0x00,0x00,0x00,0x00], 384 | [0x00,0x1C,0x22,0x20,0x18,0x20,0x20,0x22,0x1C,0x00,0x00,0x00,0x00], 385 | [0x00,0x30,0x28,0x24,0x24,0x7E,0x20,0x20,0x70,0x00,0x00,0x00,0x00], 386 | [0x00,0x7C,0x04,0x04,0x3C,0x40,0x40,0x42,0x3C,0x00,0x00,0x00,0x00], 387 | [0x00,0x70,0x08,0x04,0x3C,0x44,0x44,0x44,0x38,0x00,0x00,0x00,0x00], 388 | [0x00,0x7E,0x42,0x40,0x20,0x20,0x10,0x10,0x10,0x00,0x00,0x00,0x00], 389 | [0x00,0x3C,0x42,0x42,0x3C,0x42,0x42,0x42,0x3C,0x00,0x00,0x00,0x00], 390 | [0x00,0x3C,0x42,0x42,0x42,0x7C,0x40,0x20,0x1E,0x00,0x00,0x00,0x00], 391 | [0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x00], 392 | [0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x18,0x0C,0x04,0x00,0x00,0x00], 393 | [0x00,0x00,0x40,0x30,0x08,0x06,0x08,0x30,0x40,0x00,0x00,0x00,0x00], 394 | [0x00,0x00,0x00,0x7E,0x00,0x7E,0x00,0x00,0x00,0x00,0x00,0x00,0x00], 395 | [0x00,0x00,0x02,0x0C,0x10,0x60,0x10,0x0C,0x02,0x00,0x00,0x00,0x00], 396 | [0x00,0x38,0x44,0x40,0x40,0x20,0x10,0x00,0x18,0x00,0x00,0x00,0x00], 397 | [0x1C,0x22,0x22,0x32,0x2A,0x2A,0x32,0x02,0x22,0x1C,0x00,0x00,0x00], 398 | [0x00,0x18,0x10,0x28,0x28,0x28,0x38,0x44,0xEE,0x00,0x00,0x00,0x00], 399 | [0x00,0x3E,0x44,0x44,0x3C,0x44,0x44,0x44,0x3E,0x00,0x00,0x00,0x00], 400 | [0x00,0x78,0x44,0x02,0x02,0x02,0x02,0x44,0x38,0x00,0x00,0x00,0x00], 401 | [0x00,0x1E,0x24,0x44,0x44,0x44,0x44,0x24,0x1E,0x00,0x00,0x00,0x00], 402 | [0x00,0x7E,0x44,0x14,0x1C,0x14,0x04,0x44,0x7E,0x00,0x00,0x00,0x00], 403 | [0x00,0x7E,0x44,0x14,0x1C,0x14,0x04,0x04,0x0E,0x00,0x00,0x00,0x00], 404 | [0x00,0x78,0x44,0x02,0x02,0xE2,0x42,0x44,0x38,0x00,0x00,0x00,0x00], 405 | [0x00,0xEE,0x44,0x44,0x7C,0x44,0x44,0x44,0xEE,0x00,0x00,0x00,0x00], 406 | [0x00,0x7C,0x10,0x10,0x10,0x10,0x10,0x10,0x7C,0x00,0x00,0x00,0x00], 407 | [0x00,0x78,0x20,0x20,0x20,0x22,0x22,0x22,0x1C,0x00,0x00,0x00,0x00], 408 | [0x00,0xEE,0x44,0x24,0x14,0x1C,0x24,0x44,0xCE,0x00,0x00,0x00,0x00], 409 | [0x00,0x0E,0x04,0x04,0x04,0x04,0x44,0x44,0x7E,0x00,0x00,0x00,0x00], 410 | [0x00,0xEE,0x6C,0x6C,0x54,0x54,0x44,0x44,0xEE,0x00,0x00,0x00,0x00], 411 | [0x00,0xE7,0x46,0x4A,0x4A,0x52,0x52,0x62,0x67,0x00,0x00,0x00,0x00], 412 | [0x00,0x38,0x44,0x82,0x82,0x82,0x82,0x44,0x38,0x00,0x00,0x00,0x00], 413 | [0x00,0x3E,0x44,0x44,0x44,0x3C,0x04,0x04,0x0E,0x00,0x00,0x00,0x00], 414 | [0x00,0x38,0x44,0x82,0x82,0x82,0x82,0x44,0x38,0xF8,0x00,0x00,0x00], 415 | [0x00,0x3E,0x44,0x44,0x44,0x3C,0x24,0x44,0x8E,0x00,0x00,0x00,0x00], 416 | [0x00,0x5C,0x62,0x02,0x3C,0x40,0x40,0x46,0x3A,0x00,0x00,0x00,0x00], 417 | [0x00,0xFE,0x92,0x10,0x10,0x10,0x10,0x10,0x38,0x00,0x00,0x00,0x00], 418 | [0x00,0xEE,0x44,0x44,0x44,0x44,0x44,0x44,0x38,0x00,0x00,0x00,0x00], 419 | [0x00,0xE7,0x42,0x42,0x24,0x24,0x24,0x18,0x18,0x00,0x00,0x00,0x00], 420 | [0x00,0xEE,0x44,0x44,0x54,0x54,0x54,0x54,0x28,0x00,0x00,0x00,0x00], 421 | [0x00,0xEE,0x44,0x28,0x10,0x10,0x28,0x44,0xEE,0x00,0x00,0x00,0x00], 422 | [0x00,0xEE,0x44,0x28,0x28,0x10,0x10,0x10,0x38,0x00,0x00,0x00,0x00], 423 | [0x00,0x7C,0x44,0x20,0x10,0x10,0x08,0x44,0x7C,0x00,0x00,0x00,0x00], 424 | [0x00,0x38,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x38,0x00,0x00], 425 | [0x02,0x02,0x04,0x04,0x08,0x08,0x08,0x10,0x10,0x10,0x00,0x00,0x00], 426 | [0x00,0x0E,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x0E,0x00,0x00], 427 | [0x08,0x08,0x14,0x22,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00], 428 | [0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF], 429 | [0x00,0x08,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00], 430 | [0x00,0x00,0x00,0x3C,0x42,0x7C,0x42,0x62,0xDC,0x00,0x00,0x00,0x00], 431 | [0x00,0x03,0x02,0x3A,0x46,0x42,0x42,0x46,0x3B,0x00,0x00,0x00,0x00], 432 | [0x00,0x00,0x00,0x5C,0x62,0x02,0x02,0x42,0x3C,0x00,0x00,0x00,0x00], 433 | [0x00,0x60,0x40,0x5C,0x62,0x42,0x42,0x62,0xDC,0x00,0x00,0x00,0x00], 434 | [0x00,0x00,0x00,0x3C,0x42,0x7E,0x02,0x02,0x7C,0x00,0x00,0x00,0x00], 435 | [0x00,0x70,0x08,0x7E,0x08,0x08,0x08,0x08,0x7E,0x00,0x00,0x00,0x00], 436 | [0x00,0x00,0x00,0xDC,0x62,0x42,0x42,0x62,0x5C,0x40,0x3C,0x00,0x00], 437 | [0x00,0x06,0x04,0x34,0x4C,0x44,0x44,0x44,0xEE,0x00,0x00,0x00,0x00], 438 | [0x00,0x10,0x00,0x1C,0x10,0x10,0x10,0x10,0x7C,0x00,0x00,0x00,0x00], 439 | [0x00,0x10,0x00,0x3C,0x20,0x20,0x20,0x20,0x20,0x20,0x1E,0x00,0x00], 440 | [0x00,0x06,0x04,0xF4,0x24,0x1C,0x14,0x24,0xE6,0x00,0x00,0x00,0x00], 441 | [0x00,0x18,0x10,0x10,0x10,0x10,0x10,0x10,0x7C,0x00,0x00,0x00,0x00], 442 | [0x00,0x00,0x00,0x4B,0xB6,0x92,0x92,0x92,0xB7,0x00,0x00,0x00,0x00], 443 | [0x00,0x00,0x00,0x36,0x4C,0x44,0x44,0x44,0xEE,0x00,0x00,0x00,0x00], 444 | [0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x42,0x3C,0x00,0x00,0x00,0x00], 445 | [0x00,0x00,0x00,0x36,0x4C,0x44,0x44,0x44,0x3C,0x04,0x0E,0x00,0x00], 446 | [0x00,0x00,0x00,0xDC,0x62,0x42,0x42,0x62,0x5C,0x40,0xE0,0x00,0x00], 447 | [0x00,0x00,0x00,0x76,0x0C,0x04,0x04,0x04,0x3E,0x00,0x00,0x00,0x00], 448 | [0x00,0x00,0x00,0x7C,0x42,0x3C,0x40,0x42,0x3E,0x00,0x00,0x00,0x00], 449 | [0x00,0x00,0x04,0x3E,0x04,0x04,0x04,0x44,0x38,0x00,0x00,0x00,0x00], 450 | [0x00,0x00,0x00,0x66,0x44,0x44,0x44,0x64,0xD8,0x00,0x00,0x00,0x00], 451 | [0x00,0x00,0x00,0xE7,0x42,0x24,0x24,0x18,0x18,0x00,0x00,0x00,0x00], 452 | [0x00,0x00,0x00,0xEE,0x44,0x54,0x54,0x54,0x28,0x00,0x00,0x00,0x00], 453 | [0x00,0x00,0x00,0x66,0x24,0x18,0x18,0x24,0x66,0x00,0x00,0x00,0x00], 454 | [0x00,0x00,0x00,0xEE,0x44,0x44,0x28,0x28,0x10,0x10,0x1C,0x00,0x00], 455 | [0x00,0x00,0x00,0x7C,0x24,0x10,0x08,0x44,0x7C,0x00,0x00,0x00,0x00], 456 | [0x00,0x10,0x08,0x08,0x08,0x04,0x08,0x08,0x08,0x10,0x00,0x00,0x00], 457 | [0x00,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x00,0x00], 458 | [0x00,0x04,0x08,0x08,0x08,0x10,0x08,0x08,0x08,0x04,0x00,0x00,0x00], 459 | [0x00,0x00,0x00,0x00,0x4C,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00]) # 126 460 | 461 | 462 | font4x6=( 463 | [0x00,0x00,0x00,0x00,0x00,0x00], # char num 32 464 | [0x04,0x04,0x04,0x00,0x04,0x00], 465 | [0x0A,0x0A,0x00,0x00,0x00,0x00], 466 | [0x0A,0x0E,0x0A,0x0E,0x0A,0x00], 467 | [0x04,0x0C,0x06,0x0C,0x06,0x04], 468 | [0x02,0x08,0x04,0x02,0x08,0x00], 469 | [0x04,0x0A,0x0C,0x0A,0x0E,0x00], 470 | [0x06,0x02,0x00,0x00,0x00,0x00], 471 | [0x04,0x02,0x02,0x02,0x04,0x00], 472 | [0x02,0x04,0x04,0x04,0x02,0x00], 473 | [0x0A,0x04,0x0E,0x04,0x0A,0x00], 474 | [0x00,0x04,0x0E,0x04,0x00,0x00], 475 | [0x00,0x00,0x00,0x00,0x06,0x02], 476 | [0x00,0x00,0x0E,0x00,0x00,0x00], 477 | [0x00,0x00,0x00,0x00,0x04,0x00], 478 | [0x08,0x08,0x04,0x02,0x02,0x00], 479 | [0x0C,0x0A,0x0A,0x0A,0x06,0x00], 480 | [0x04,0x06,0x04,0x04,0x0E,0x00], 481 | [0x06,0x08,0x04,0x02,0x0E,0x00], 482 | [0x06,0x08,0x04,0x08,0x06,0x00], 483 | [0x08,0x0A,0x0E,0x08,0x08,0x00], 484 | [0x0E,0x02,0x06,0x08,0x06,0x00], 485 | [0x04,0x02,0x06,0x0A,0x04,0x00], 486 | [0x0E,0x08,0x0C,0x04,0x04,0x00], 487 | [0x04,0x0A,0x04,0x0A,0x04,0x00], 488 | [0x04,0x0A,0x0C,0x08,0x04,0x00], 489 | [0x00,0x00,0x04,0x00,0x04,0x00], 490 | [0x00,0x00,0x04,0x00,0x06,0x02], 491 | [0x08,0x04,0x02,0x04,0x08,0x00], 492 | [0x00,0x00,0x0E,0x00,0x0E,0x00], 493 | [0x02,0x04,0x08,0x04,0x02,0x00], 494 | [0x06,0x08,0x04,0x00,0x04,0x00], 495 | [0x0E,0x0A,0x0A,0x02,0x0E,0x00], 496 | [0x04,0x0A,0x0E,0x0A,0x0A,0x00], 497 | [0x06,0x0A,0x06,0x0A,0x06,0x00], 498 | [0x0C,0x02,0x02,0x02,0x0C,0x00], 499 | [0x06,0x0A,0x0A,0x0A,0x06,0x00], 500 | [0x0E,0x02,0x06,0x02,0x0E,0x00], 501 | [0x0E,0x02,0x06,0x02,0x02,0x00], 502 | [0x0C,0x02,0x0A,0x0A,0x0C,0x00], 503 | [0x0A,0x0A,0x0E,0x0A,0x0A,0x00], 504 | [0x0E,0x04,0x04,0x04,0x0E,0x00], 505 | [0x08,0x08,0x08,0x0A,0x04,0x00], 506 | [0x0A,0x0A,0x06,0x0A,0x0A,0x00], 507 | [0x02,0x02,0x02,0x02,0x0E,0x00], 508 | [0x0A,0x0E,0x0E,0x0A,0x0A,0x00], 509 | [0x0A,0x0E,0x0A,0x0A,0x0A,0x00], 510 | [0x04,0x0A,0x0A,0x0A,0x04,0x00], 511 | [0x06,0x0A,0x06,0x02,0x02,0x00], 512 | [0x04,0x0A,0x0A,0x0E,0x0C,0x00], 513 | [0x06,0x0A,0x06,0x0A,0x0A,0x00], 514 | [0x0C,0x02,0x0E,0x08,0x06,0x00], 515 | [0x0E,0x04,0x04,0x04,0x04,0x00], 516 | [0x0A,0x0A,0x0A,0x0A,0x0E,0x00], 517 | [0x0A,0x0A,0x0A,0x0A,0x04,0x00], 518 | [0x0A,0x0A,0x0E,0x0E,0x0A,0x00], 519 | [0x0A,0x0A,0x04,0x0A,0x0A,0x00], 520 | [0x0A,0x0A,0x04,0x04,0x04,0x00], 521 | [0x0E,0x08,0x04,0x02,0x0E,0x00], 522 | [0x06,0x02,0x02,0x02,0x06,0x00], 523 | [0x02,0x02,0x04,0x08,0x08,0x00], 524 | [0x06,0x04,0x04,0x04,0x06,0x00], 525 | [0x04,0x0A,0x00,0x00,0x00,0x00], 526 | [0x00,0x00,0x00,0x00,0x00,0x0F], 527 | [0x06,0x04,0x00,0x00,0x00,0x00], 528 | [0x00,0x00,0x0C,0x0A,0x0E,0x00], 529 | [0x02,0x02,0x06,0x0A,0x06,0x00], 530 | [0x00,0x00,0x0C,0x02,0x0C,0x00], 531 | [0x08,0x08,0x0C,0x0A,0x0C,0x00], 532 | [0x00,0x00,0x0E,0x06,0x0C,0x00], 533 | [0x08,0x04,0x0E,0x04,0x04,0x00], 534 | [0x00,0x00,0x0E,0x0A,0x08,0x0E], 535 | [0x02,0x02,0x06,0x0A,0x0A,0x00], 536 | [0x04,0x00,0x04,0x04,0x04,0x00], 537 | [0x04,0x00,0x04,0x04,0x04,0x06], 538 | [0x02,0x02,0x0A,0x06,0x0A,0x00], 539 | [0x04,0x04,0x04,0x04,0x04,0x00], 540 | [0x00,0x00,0x0E,0x0E,0x0A,0x00], 541 | [0x00,0x00,0x06,0x0A,0x0A,0x00], 542 | [0x00,0x00,0x04,0x0A,0x04,0x00], 543 | [0x00,0x00,0x06,0x0A,0x06,0x02], 544 | [0x00,0x00,0x0C,0x0A,0x0C,0x08], 545 | [0x00,0x00,0x06,0x02,0x02,0x00], 546 | [0x00,0x00,0x0C,0x04,0x06,0x00], 547 | [0x00,0x04,0x0E,0x04,0x0C,0x00], 548 | [0x00,0x00,0x0A,0x0A,0x0E,0x00], 549 | [0x00,0x00,0x0A,0x0A,0x04,0x00], 550 | [0x00,0x00,0x0A,0x0E,0x0E,0x00], 551 | [0x00,0x00,0x0A,0x04,0x0A,0x00], 552 | [0x00,0x00,0x0A,0x0A,0x04,0x02], 553 | [0x00,0x00,0x06,0x04,0x0C,0x00], 554 | [0x0C,0x04,0x06,0x04,0x0C,0x00], 555 | [0x04,0x04,0x04,0x04,0x04,0x00], 556 | [0x06,0x04,0x0C,0x04,0x06,0x00], 557 | [0x0A,0x05,0x00,0x00,0x00,0x00], 558 | [0x00,0x04,0x0A,0x0E,0x00,0x00]) # char num 127 559 | -------------------------------------------------------------------------------- /lib_tft144.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # lib_tft144.py v1.6 5 | 6 | # Raspberry Pi Serial-SPI version 7 | # eg http://www.ebay.com.au/itm/141239781210 - under $4! 8 | # Both "red" and "black" boards supported as from V1.6 April 2015 9 | # Board has inbuilt 5V-3V (2.9?) regulator (which does NOT break out the 3V!!) 10 | # As far as I can discern, logic level is still 3.3V limit, despite supply is 5V. 11 | # Currently the code here is designed simply for case of 128x128 pixels. 12 | # Brian Lavery (C) Oct 2014 brian (at) blavery (dot) com 13 | # Added: SPI access, BMP file load, double size fonts, python class 14 | # Works on: Rasp Pi GPIO, or "virtual GPIO" 3.3V (identical library for both) 15 | 16 | # THIS BOARD WORKS A TREAT !!!! BL 17 | 18 | #************************************************************************ 19 | # 20 | # (1) Based on ILI9163 128x128 LCD library - parallel I/O AVR C code 21 | # Copyright (C) 2012 Simon Inns Email: simon.inns@gmail.com 22 | # http://www.waitingforfriday.com/index.php/Reverse_Engineering_a_1.5_inch_Photoframe 23 | # (2) ... then based on Antares python/parallel Raspberry Pi code: 24 | # http://www.raspberrypi.org/forums/viewtopic.php?t=58291&p=450201 25 | # (3) ... making this version lib_tft144 python SPI interface for RPI or Virtual GPIO 26 | # (It's looking a bit different now from Inns' original!) 27 | # 28 | # This program is free software: you can redistribute it and/or modify 29 | # it under the terms of the GNU General Public License as published by 30 | # the Free Software Foundation, either version 3 of the License, or 31 | # (at your option) any later version. 32 | # 33 | # This program is distributed in the hope that it will be useful, 34 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 35 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 36 | # GNU General Public License for more details. 37 | # 38 | # You should have received a copy of the GNU General Public License 39 | # along with this program. If not, see . 40 | # 41 | #************************************************************************/ 42 | 43 | # 128x128 pixels, 44 | # Note the board is write-only. There is no feedback if board is absent or misbehaving. 45 | 46 | import sys 47 | 48 | if __name__ == '__main__': 49 | print (sys.argv[0], 'is an importable module:') 50 | print ("... from", sys.argv[0], "import TFT144") 51 | exit() 52 | 53 | 54 | from time import sleep 55 | import os 56 | GPIO = None 57 | 58 | TFTWIDTH = 128 59 | TFTHEIGHT = 128 60 | 61 | #ILI9163 commands 62 | NOP=0x00 63 | SOFT_RESET=0x01 64 | ENTER_SLEEP_MODE=0x10 65 | EXIT_SLEEP_MODE=0x11 66 | ENTER_PARTIAL_MODE=0x12 67 | ENTER_NORMAL_MODE=0x13 68 | EXIT_INVERT_MODE=0x20 69 | ENTER_INVERT_MODE=0x21 70 | SET_GAMMA_CURVE=0x26 71 | SET_DISPLAY_OFF=0x28 72 | SET_DISPLAY_ON=0x29 73 | SET_COLUMN_ADDRESS=0x2A 74 | SET_PAGE_ADDRESS=0x2B 75 | WRITE_MEMORY_START=0x2C 76 | SET_PARTIAL_AREA=0x30 77 | SET_SCROLL_AREA=0x33 78 | SET_ADDRESS_MODE=0x36 79 | SET_SCROLL_START=0X37 80 | EXIT_IDLE_MODE=0x38 81 | ENTER_IDLE_MODE=0x39 82 | SET_PIXEL_FORMAT=0x3A 83 | WRITE_MEMORY_CONTINUE=0x3C 84 | READ_MEMORY_CONTINUE=0x3E 85 | FRAME_RATE_CONTROL1=0xB1 86 | FRAME_RATE_CONTROL2=0xB2 87 | FRAME_RATE_CONTROL3=0xB3 88 | DISPLAY_INVERSION=0xB4 89 | POWER_CONTROL1=0xC0 90 | POWER_CONTROL2=0xC1 91 | POWER_CONTROL3=0xC2 92 | POWER_CONTROL4=0xC3 93 | POWER_CONTROL5=0xC4 94 | VCOM_CONTROL1=0xC5 95 | VCOM_CONTROL2=0xC6 96 | VCOM_OFFSET_CONTROL=0xC7 97 | POSITIVE_GAMMA_CORRECT=0xE0 98 | NEGATIVE_GAMMA_CORRECT=0xE1 99 | GAM_R_SEL=0xF2 100 | 101 | VIRTUALGPIO = 0 102 | 103 | from lcdfonts import * 104 | 105 | class TFT144: 106 | # red board is built 180 rotated relative to black board !! 107 | ORIENTATION0=0 108 | ORIENTATION90=96 109 | ORIENTATION270=160 110 | ORIENTATION180=192 111 | # Do you rotate the image, or the device? :-) 112 | 113 | def __init__(self, gpio, spidev, CE, dc_pin, rst_pin=0, led_pin=0, orientation=ORIENTATION0, isRedBoard=False, spi_speed=16000000): 114 | # CE is 0 or 1 for RPI, but is actual CE pin for virtGPIO 115 | # RST pin. 0 means soft reset (but reset pin still needs holding high (3V) 116 | # LED pin, may be tied to 3V (abt 14mA) or used on a 3V logic pin (abt 7mA) 117 | # and this object needs to be told the GPIO and SPIDEV objects to talk to 118 | global GPIO 119 | GPIO = gpio 120 | self.SPI = spidev 121 | self.orientation = orientation 122 | self.is_redboard = isRedBoard 123 | self.BLUE = self.colour565(0,0,255) 124 | self.GREEN = self.colour565(0,255, 0) 125 | self.RED = self.colour565(255,0,0) 126 | self.PINK = self.colour565(255,120,120) 127 | self.LIGHTBLUE = self.colour565(120,120,255) 128 | self.LIGHTGREEN = self.colour565(120,255,120) 129 | self.BLACK = self.colour565(0,0,0) 130 | self.WHITE = self.colour565(255,255,255) 131 | self.GREY = self.colour565(120,120,120) 132 | self.YELLOW = self.colour565(255,255,0) 133 | self.MAGENTA = self.colour565(255,0,255) 134 | self.CYAN = self.colour565(0,255,255) 135 | 136 | self.RST = rst_pin 137 | self.DC = dc_pin 138 | self.LED = led_pin 139 | GPIO.setup(dc_pin, GPIO.OUT) 140 | GPIO.output(dc_pin, GPIO.HIGH) 141 | if rst_pin: 142 | GPIO.setup(rst_pin, GPIO.OUT) 143 | GPIO.output(rst_pin, GPIO.HIGH) 144 | if led_pin: 145 | GPIO.setup(led_pin, GPIO.OUT) 146 | self.led_on(True) 147 | self.SPI.open(0, CE) # CE is 0 or 1 (means pin CE0 or CE1) or actual CE pin for virtGPIO 148 | self.SPI.max_speed_hz=spi_speed 149 | # Black board may cope with 32000000 Hz. Red board up to 16000000. YMMV. 150 | sleep(0.5) 151 | self.init_LCD(orientation) 152 | 153 | def led_on(self, onoff): 154 | if self.LED: 155 | GPIO.output(self.LED, GPIO.HIGH if onoff else GPIO.LOW) 156 | 157 | #function to pack 3 bytes of rgb value in 2 byte integer, R,G and B 0-255 158 | def colour565(self, r,g,b): 159 | return ((b & 0xF8) << 8) | ((g & 0xFC) << 3) | (r >> 3) 160 | 161 | #functions to translate x,y pixel coords. to text column,row 162 | def textX(self, x, font=3): 163 | return x*(self.fontDim[font][0]) 164 | 165 | def textY(self, y, font=3): 166 | return y*(self.fontDim[font][1]) 167 | 168 | #initial LCD reset 169 | def reset_LCD(self): 170 | if self.RST == 0: 171 | self.write_command(SOFT_RESET) 172 | else: 173 | GPIO.output(self.RST,False) 174 | sleep (0.2) 175 | GPIO.output(self.RST,True) 176 | sleep (0.2) 177 | return 178 | 179 | #write command to controller 180 | def write_command(self, address): 181 | GPIO.output(self.DC,False) 182 | self.SPI.writebytes([address]) 183 | 184 | 185 | #write data 186 | def write_data(self, data): 187 | GPIO.output(self.DC,True) 188 | if not type(data) == type([]): # is it already a list? 189 | data = [data] 190 | self.SPI.writebytes(data) 191 | 192 | #------------------------------------------- 193 | 194 | def init_LCD(self, orientation): 195 | self.reset_LCD() 196 | self.write_command(EXIT_SLEEP_MODE) 197 | sleep(0.05) 198 | self.write_command(SET_PIXEL_FORMAT) 199 | self.write_data(0x05) 200 | self.write_command(SET_GAMMA_CURVE) 201 | self.write_data(0x04) 202 | self.write_command(GAM_R_SEL) 203 | self.write_data(0x01) 204 | 205 | self.write_command(POSITIVE_GAMMA_CORRECT) 206 | self.write_data([0x3f, 0x25, 0x1c, 0x1e, 0x20, 0x12, 0x2a, 0x90, 0x24, 0x11, 0, 0, 0, 0, 0]) 207 | 208 | self.write_command(NEGATIVE_GAMMA_CORRECT) 209 | self.write_data([0x20, 0x20, 0x20, 0x20, 0x05, 0, 0x15, 0xa7, 0x3d, 0x18, 0x25, 0x2a, 0x2b, 0x2b, 0x3a]) 210 | self.write_command(FRAME_RATE_CONTROL1) 211 | self.write_data([0x08, 0x08]) 212 | 213 | self.write_command(DISPLAY_INVERSION) 214 | self.write_data(0x01) 215 | 216 | self.write_command(POWER_CONTROL1) 217 | self.write_data([0x0a, 0x02]) 218 | 219 | self.write_command(POWER_CONTROL2) 220 | self.write_data(0x02) 221 | 222 | self.write_command(VCOM_CONTROL1) 223 | self.write_data([0x50, 0x5b]) 224 | 225 | self.write_command(VCOM_OFFSET_CONTROL) 226 | self.write_data(0x40) 227 | self.set_frame() 228 | 229 | self.write_command(SET_ADDRESS_MODE) 230 | self.write_data(orientation) 231 | 232 | self.clear_display(self.BLACK) 233 | self.write_command(SET_DISPLAY_ON) 234 | # self.write_command(WRITE_MEMORY_START) 235 | 236 | # clear display,writes same color pixel in all screen 237 | def clear_display(self, color): 238 | color_hi=color>>8 239 | color_lo= color&(~(65280)) 240 | self.set_frame() 241 | self.write_command(WRITE_MEMORY_START) 242 | if GPIO.RPI_REVISION == VIRTUALGPIO: 243 | GPIO.output(self.DC,True) 244 | self.SPI.fill(16384, color) 245 | # For virtGPIO "fill" is MUCH faster, but is a special VirtGPIO function 246 | else: 247 | # Otherwise (RPI) repetitively push out all those identical pixels 248 | for row in range(TFTHEIGHT): 249 | self.write_data([color_hi, color_lo] * TFTWIDTH) 250 | 251 | def set_frame(self, x1=0, x2=TFTWIDTH-1, y1=0, y2=TFTHEIGHT-1 ): 252 | if self.is_redboard: 253 | if self.orientation==self.ORIENTATION0: 254 | y1 += 32 255 | y2 += 32 256 | if self.orientation==self.ORIENTATION90: 257 | x1 += 32 258 | x2 += 32 259 | self.write_command(SET_COLUMN_ADDRESS) 260 | self.write_data([0, x1, 0, x2]) 261 | self.write_command(SET_PAGE_ADDRESS) 262 | self.write_data([0,y1,0,y2]) 263 | 264 | 265 | # draw a dot in x,y with 'color' colour 266 | def draw_dot(self, x,y,color): 267 | color_hi=color>>8 268 | color_lo= color&(~(65280)) 269 | self.set_frame(x, x+1, y, y+1) 270 | self.write_command(WRITE_MEMORY_START) 271 | self.write_data([color_hi,color_lo]) 272 | 273 | # Bresenham's algorithm to draw a line with integers 274 | # x0<=x1, y0<=y1 275 | def draw_line(self, x0,y0,x1,y1,color): 276 | dy=y1-y0 277 | dx=x1-x0 278 | if (dy<0): 279 | dy=-dy 280 | stepy=-1 281 | else: 282 | stepy=1 283 | if (dx<0): 284 | dx=-dx 285 | stepx=-1 286 | else: 287 | stepx=1 288 | dx <<=1 289 | dy <<=1 290 | self.draw_dot(x0,y0,color) 291 | if (dx>dy): 292 | fraction=dy-(dx>>1) 293 | while (x0!=x1): 294 | if (fraction>=0): 295 | y0 +=stepy 296 | fraction -=dx 297 | x0 +=stepx 298 | fraction +=dy 299 | self.draw_dot(x0,y0,color) 300 | else: 301 | fraction=dx-(dy>>1) 302 | while (y0!=y1): 303 | if (fraction>=0): 304 | x0 +=stepx 305 | fraction -=dy 306 | y0 +=stepy 307 | fraction +=dx 308 | self.draw_dot(x0,y0,color) 309 | 310 | # draws hollow rectangle 311 | # x0<=x1, y0<= y1 312 | def draw_rectangle(self, x0,y0,x1,y1,color): 313 | self.draw_line(x0,y0,x0,y1,color) 314 | self.draw_line(x0,y1,x1,y1,color) 315 | self.draw_line(x1,y0,x1,y1,color) 316 | self.draw_line(x0,y0,x1,y0,color) 317 | 318 | # draws filled rectangle, fills frame memory section with same pixel 319 | # x0<=x1, y0<=y1 320 | def draw_filled_rectangle(self, x0,y0,x1,y1,color): 321 | color_hi=color>>8 322 | color_lo= color&(~(65280)) 323 | self.set_frame(x0, x1, y0, y1) 324 | 325 | self.write_command(WRITE_MEMORY_START) 326 | for pixels in range (0,(1+x1-x0)): 327 | dbuf = [color_hi, color_lo] * (y1-y0) 328 | self.write_data(dbuf) 329 | 330 | #Bresenham's circle algorithm, circle can't pass screen boundaries 331 | def draw_circle(self, x0,y0,radio,color): 332 | error=1-radio 333 | errorx=1 334 | errory=-2*radio 335 | y=radio 336 | x=0 337 | self.draw_dot(x0,y0+radio,color) 338 | self.draw_dot(x0,y0-radio,color) 339 | self.draw_dot(x0+radio,y0,color) 340 | self.draw_dot(x0-radio,y0,color) 341 | while (x=0): 343 | y -=1 344 | errory +=2 345 | error +=errory 346 | x +=1 347 | errorx +=2 348 | error +=errorx 349 | self.draw_dot(x0+x,y0+y,color) 350 | self.draw_dot(x0-x,y0+y,color) 351 | self.draw_dot(x0+x,y0-y,color) 352 | self.draw_dot(x0-x,y0-y,color) 353 | self.draw_dot(x0+y,y0+x,color) 354 | self.draw_dot(x0-y,y0+x,color) 355 | self.draw_dot(x0+y,y0-x,color) 356 | self.draw_dot(x0-y,y0-x,color) 357 | 358 | 359 | fontDim = ([0], [4, 6, 1], [8, 12, 2], [6, 8, 1], [12, 16, 2], [8, 12, 1], [16, 24, 2], [8, 16, 1], [16, 32, 2] ) 360 | # Font dimensions for fonts 1-8. [W, H, Scale] 361 | fontW = 0 # These are valid only AFTER a char was displayed 362 | fontH = 0 363 | 364 | # writes a character in graphic coordinates x,y, with 365 | # foreground and background colours 366 | def put_char(self, character,x,y,fgcolor,bgcolor, font = 3): 367 | fgcolor_hi=fgcolor>>8 368 | fgcolor_lo= fgcolor&(~(65280)) 369 | bgcolor_hi=bgcolor>>8 370 | bgcolor_lo= bgcolor&(~(65280)) 371 | self.fontW = self.fontDim[font][0] 372 | self.fontH = self.fontDim[font][1] 373 | fontScale = self.fontDim[font][2] 374 | character = ord(character) 375 | if not (font == 3 or font == 4): # restricted char set 32-126 for most 376 | if character < 32 or character > 126: # only strictly ascii chars 377 | character = 0 378 | else: 379 | character -= 32 380 | self.set_frame(x, (x+self.fontW-1), y, (y + self.fontH-1)) 381 | xx = [0] 382 | if fontScale == 2: 383 | xx = [0, 2, 2 * self.fontW, 2 + (2 * self.fontW) ] # DOUBLE: every pixel becomes a 2x2 pixel 384 | 385 | self.write_command(WRITE_MEMORY_START) 386 | cbuf = [0] * (self.fontW * self.fontH * 2) 387 | for row in range (0, int(self.fontH // fontScale)): 388 | for column in range (0,int(self.fontW // fontScale)): 389 | topleft = ((column*2*fontScale) + (row*2*self.fontW*fontScale)) 390 | if font <=2: 391 | pixOn = (font4x6[character][row]) & (1<= 7: 393 | pixOn = (font8x16[character][row]) & (1<= 5: 395 | pixOn = (font8x12[character][row]) & (1<TFTWIDTH): 418 | x=originx 419 | y +=(fontH) 420 | if ((y+fontH)>TFTHEIGHT): 421 | break 422 | self.put_char(str[char_number],x,y,fgcolor,bgcolor, font) 423 | x +=(fontW) 424 | 425 | 426 | 427 | def draw_bmp(self, filename, x0=0, y0=0): 428 | if not os.path.exists(filename): 429 | return False 430 | with open(filename, 'rb') as bitmap_file: 431 | bitmap_file.seek(18) 432 | w = ord(bitmap_file.read(1)) 433 | bitmap_file.seek(22) 434 | h = ord(bitmap_file.read(1)) 435 | bitmap_file.seek(10) 436 | start = ord(bitmap_file.read(1)) 437 | bitmap_file.seek(start) 438 | self.set_frame(x0, x0+w-1, y0, y0+h-1) 439 | self.write_command(WRITE_MEMORY_START) 440 | for y in range(h): # 3 bytes of colour / pixel 441 | dbuf = [0] * (w*2) 442 | for x in range(w): 443 | b = ord(bitmap_file.read(1)) 444 | g = ord(bitmap_file.read(1)) 445 | r = ord(bitmap_file.read(1)) 446 | RGB = self.colour565(r, g, b) 447 | #RGB = self.YELLOW 448 | dbuf[2*x] = RGB>>8 449 | dbuf[1 + (2*x)] = RGB&(~65280) 450 | self.write_data(dbuf) 451 | # Now, BMP has a 4byte alignment issue at end of each line V1.0.1 452 | x = 3*w # bytes in line @ 3bytes/pixel 453 | while (x % 4): 454 | x += 1 455 | bitmap_file.read(1) # waste a byte until aligned 456 | return True 457 | 458 | def invert_screen(self): 459 | self.write_command(ENTER_INVERT_MODE) 460 | 461 | def normal_screen(self): 462 | self.write_command(EXIT_INVERT_MODE) 463 | 464 | 465 | ######################################################################## 466 | -------------------------------------------------------------------------------- /rpi2.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BLavery/LIBtft144/HEAD/rpi2.bmp -------------------------------------------------------------------------------- /smartGPIO.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | # AUTO: Find if operating on Raspberry Pi GPIO system or on virtual GPIO on PC 5 | 6 | if __name__ == '__main__': 7 | import sys 8 | print ('%s is an importable module:' % sys.argv[0]) 9 | print ("... from smartGPIO import GPIO") 10 | print ("") 11 | exit() 12 | 13 | 14 | try: 15 | # This para is the vGPIO attempt: 16 | import virtGPIO as GPIO 17 | # That succeeded 18 | 19 | except: 20 | try: 21 | # This para is the RPI-GPIO attempt: 22 | import RPi.GPIO as GPIO 23 | # That succeeded 24 | 25 | 26 | except: 27 | print ("No GPIO?") 28 | exit() 29 | --------------------------------------------------------------------------------