In [1]:
from pynq import Overlay
Overlay("base.bit").download()
In [2]:
from pynq.iop import Arduino_LCD18
from pynq.iop import ARDUINO
lcd = Arduino_LCD18(ARDUINO)
In [3]:
lcd.clear()
The screen is 160 pixels by 128 pixels. So the largest picture that can fit in the screen is 160 by 128. To resize a picture to a desired size, users can do:
from PIL import Image
img = Image.open('data/large.jpg')
w_new = 160
h_new = 128
new_img = img.resize((w_new,h_new),Image.ANTIALIAS)
new_img.save('data/small.jpg','JPEG')
img.close()
The format of the picture can be PNG, JPEG, BMP, or any other format that can be opened using the Image library. In the API, the picture will be compressed into a binary format having (per pixel) 5 bits for blue, 6 bits for green, and 5 bits for red. All the pixels (of 16 bits each) will be stored in DDR memory and then transferred to the IO processor for display.
The orientation of the picture is as shown below, while currently, only orientation 1 and 3 are supported. Orientation 3 will display picture normally, while orientation 1 will display picture upside-down.
To display the picture at the desired location, the position has to be calculated. For example, to display in the center a 76-by-25 picture with orientation 3, x_pos has to be (160-76/2)=42, and y_pos has to be (128/2)+(25/2)=76.
The parameter background is a list of 3 components: [R,G,B], where each component consists of 8 bits. If it is not defined, it will be defaulted to [0,0,0] (black).
In [4]:
lcd.display('data/board_small.jpg',x_pos=0,y_pos=127,
orientation=3,background=[255,255,255])
In [5]:
lcd.display('data/logo_small.png',x_pos=0,y_pos=127,
orientation=1,background=[255,255,255],frames=100)
Draw a white line from upper left corner towards lower right corner.
The parameter background is a list of 3 components: [R,G,B], where each component consists of 8 bits. If it is not defined, it will be defaulted to [0,0,0] (black).
Similarly, the parameter color defines the color of the line, with a default value of [255,255,255] (white).
All the 3 draw_line() use the default orientation 3.
Note that if the background is changed, the screen will also be cleared. Otherwise the old lines will still stay on the screen.
In [6]:
lcd.clear()
lcd.draw_line(x_start_pos=151,y_start_pos=98,x_end_pos=19,y_end_pos=13)
Draw a 100-pixel wide red horizontal line, on a yellow background. Since the background is changed, the screen will be cleared automatically.
In [7]:
lcd.draw_line(50,50,150,50,color=[255,0,0],background=[255,255,0])
Draw a 80-pixel tall blue vertical line, on the same yellow background.
In [8]:
lcd.draw_line(50,20,50,120,[0,0,255],[255,255,0])
Users can print a scaled string at a desired position with a desired text color and background color.
The first print_string() prints "Hello, PYNQ!" at 1st row, 1st column, with white text color and blue background.
The second print_string() prints today's date at 5th row, 10th column, with yellow text color and blue background.
Note that if the background is changed, the screen will also be cleared. Otherwise the old strings will still stay on the screen.
In [9]:
text = 'Hello, PYNQ!'
lcd.print_string(1,1,text,[255,255,255],[0,0,255])
In [10]:
import time
text = time.strftime("%d/%m/%Y")
lcd.print_string(5,10,text,[255,255,0],[0,0,255])
In [11]:
lcd.draw_filled_rectangle(x_start_pos=10,y_start_pos=10,
width=60,height=80,color=[64,255,0])
In [12]:
lcd.draw_filled_rectangle(x_start_pos=20,y_start_pos=30,
width=80,height=30,color=[255,128,0])
In [13]:
lcd.draw_filled_rectangle(x_start_pos=90,y_start_pos=40,
width=70,height=120,color=[64,0,255])
In [14]:
button=lcd.read_joystick()
if button == 1:
print('Left')
elif button == 2:
print('Down')
elif button==3:
print('Center')
elif button==4:
print('Right')
elif button==5:
print('Up')
else:
print('Not pressed')
In [ ]: