Skip to content

Commit 6a64888

Browse files
committed
Add SPI Example Guide for AmebaD
- Add SPI Example Guide for AmebaD
1 parent c3f0468 commit 6a64888

File tree

51 files changed

+506
-7
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+506
-7
lines changed
Lines changed: 291 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,291 @@
1+
SPI - Print Image and Text On LCD Screen
2+
=========================================
3+
4+
.. contents::
5+
:local:
6+
:depth: 2
7+
8+
If you are not familiar with SPI, please read `Introduction to
9+
SPI <https://www.amebaiot.com/spi-intro/>`_ first.
10+
11+
Materials
12+
---------
13+
14+
- AmebaD [AMB21 / AMB22 / AMB23 / AMB25 / AMB26 / BW16 / AW-CU488 Thing Plus] x 1
15+
16+
- ILI9341 TFT LCD with SPI interface x 1
17+
18+
Example
19+
-------
20+
21+
We have tested the following two models of ILI9341 TFT LCD with SPI interface:
22+
23+
**Adafruit 2.8″ TFT LCD (with touch screen)**
24+
25+
- https://www.adafruit.com/products/1651
26+
27+
- https://learn.adafruit.com/adafruit-2-8-tft-touch-shield-v2?view=all
28+
29+
**QVGA 2.2″ TFT LCD**
30+
31+
- http://www.lcdwiki.com/2.2inch_SPI_Module_ILI9341_SKU:MSP2202
32+
33+
Common pins in ILI9341 TFT LCD with SPI interface:
34+
35+
- MOSI: Standard SPI Pin
36+
37+
- MISO: Standard SPI Pin
38+
39+
- SLK: Standard SPI Pin
40+
41+
- CS: Standard SPI Pin
42+
43+
- RESET: Used to reboot LCD.
44+
45+
- D/C: Data/Command. When it is at LOW, the signal transmitted are commands, otherwise the data transmitted are data.
46+
47+
- LED (or BL): Adapt the screen backlight. Can be controlled by PWM or connected to VCC for 100% backlight.
48+
49+
- VCC: Connected to 3V or 5V, depends on its spec.
50+
51+
- GND: Connected to GND.
52+
53+
**QVGA 2.2″ TFT LCD Wiring Diagrams**
54+
55+
.. only:: amb21
56+
57+
|image01|
58+
59+
.. only:: end amb21
60+
61+
.. only:: amb23
62+
63+
|image02|
64+
65+
.. only:: end amb23
66+
67+
.. only:: amb25
68+
69+
|image06|
70+
71+
.. only:: end amb25
72+
73+
.. only:: amb26
74+
75+
|image07|
76+
77+
.. only:: end amb26
78+
79+
.. only:: bw16-typeb
80+
81+
|image03|
82+
83+
.. only:: end bw16-typeb
84+
85+
.. only:: bw16-typec
86+
87+
|image04|
88+
89+
.. only:: end bw16-typec
90+
91+
.. only:: aw-cu488
92+
93+
|image05|
94+
95+
.. only:: end aw-cu488
96+
97+
**Adafruit 2.8″ TFT LCD touch shield Wiring Diagrams**
98+
99+
.. only:: amb21
100+
101+
|image08|
102+
103+
.. only:: end amb21
104+
105+
.. only:: amb23
106+
107+
|image09|
108+
109+
.. only:: end amb23
110+
111+
.. only:: amb25
112+
113+
|image13|
114+
115+
.. only:: end amb25
116+
117+
.. only:: amb26
118+
119+
|image14|
120+
121+
.. only:: end amb26
122+
123+
.. only:: bw16-typeb
124+
125+
|image10|
126+
127+
.. only:: end bw16-typeb
128+
129+
.. only:: bw16-typec
130+
131+
|image11|
132+
133+
.. only:: end bw16-typec
134+
135+
.. only:: aw-cu488
136+
137+
|image12|
138+
139+
.. only:: end aw-cu488
140+
141+
Open the example, “File”→ “Examples”→ “AmebaSPI” → “ILI9341_TFT_LCD_basic”
142+
143+
|image15|
144+
145+
Compile and upload to Ameba, then press the reset button.
146+
Then you can see some display tests appear on the LCD screen, such as displaying different colors, drawing vertical and horizontal lines, drawing circles, etc.…
147+
148+
|image16|
149+
150+
Besides, it can also display any user images based on the screen size. Using the online Image converting tool here that supports input images in png, .jpg and .gif ad output as .c file. Upon converting is done, place the .c file in our template Amebalogo.h file and upload the code again.
151+
152+
|image18|
153+
154+
|image19|
155+
156+
Code Reference
157+
--------------
158+
159+
- | **RGB 16-bit**
160+
| ILI9341 uses RGB 16-bit to display colors. Different from RGB
161+
24-bit, it uses 5 bits for red, 6 bits for green, 5 bits for blue.
162+
For example, the RGB 24-bit representation of sky blue is 0x87CEFF,
163+
that is in binary:
164+
165+
- Red: 0x87 = B10000111
166+
167+
- Green: 0xCE = B11001110
168+
169+
- Blue: 0xFF = B11111111
170+
171+
..
172+
173+
and converted to RGB 16-bit:
174+
175+
- Red: B10000
176+
177+
- Green: B110011
178+
179+
- Blue: B11111
180+
181+
..
182+
183+
Then concatenate them, which forms B1000011001111111 = 0x867F
184+
185+
- **Drawing of ILI9341**
186+
187+
- First you must specify the range of the rectangle to draw, then
188+
pass the 2-byte RGB 16-bit color to ILI9341 corresponding to each
189+
pixel one by one, in this way ILI9341 fills each color to each
190+
pixel.
191+
192+
- You still must specify the drawing range even though the range
193+
covers only one pixel.
194+
195+
- From the rules we mentioned above, we can conclude that drawing
196+
vertical or horizontal lines are faster than diagonal lines.
197+
198+
- **Printing text on ILI9341**
199+
200+
- In our API, each character is 5x7 but each character is printed to
201+
size 6x8 (its right side and below are left blank), so as to
202+
separate from next character. For example, the character “A”:
203+
204+
|image17|
205+
206+
- The font size represents the dot size. For example, if the font
207+
size is 2, each dot in the character is a 2x2 rectangle
208+
209+
- **Screen rotation**
210+
211+
- ILI9341 provides 0, 90, 180, 270 degrees screen rotation.
212+
213+
- If the original width is 240 and original height is 320, when the
214+
screen rotates 90 degrees, the width becomes 320 and the height
215+
becomes 240.
216+
217+
.. |image01| image:: ../../../_static/amebad/Example_Guides/SPI/SPI_Print_Image_And_Text_On_LCD_Screen/image01.png
218+
:width: 602 px
219+
:height: 379 px
220+
221+
.. |image02| image:: ../../../_static/amebad/Example_Guides/SPI/SPI_Print_Image_And_Text_On_LCD_Screen/image02.png
222+
:width: 569 px
223+
:height: 382 px
224+
225+
.. |image03| image:: ../../../_static/amebad/Example_Guides/SPI/SPI_Print_Image_And_Text_On_LCD_Screen/image03.png
226+
:width: 875 px
227+
:height: 560 px
228+
229+
.. |image04| image:: ../../../_static/amebad/Example_Guides/SPI/SPI_Print_Image_And_Text_On_LCD_Screen/image04.png
230+
:width: 518 px
231+
:height: 339 px
232+
233+
.. |image05| image:: ../../../_static/amebad/Example_Guides/SPI/SPI_Print_Image_And_Text_On_LCD_Screen/image05.png
234+
:width: 785 px
235+
:height: 565 px
236+
237+
.. |image06| image:: ../../../_static/amebad/Example_Guides/SPI/SPI_Print_Image_And_Text_On_LCD_Screen/image06.png
238+
:width: 772 px
239+
:height: 482 px
240+
241+
.. |image07| image:: ../../../_static/amebad/Example_Guides/SPI/SPI_Print_Image_And_Text_On_LCD_Screen/image07.png
242+
:width: 817 px
243+
:height: 382 px
244+
245+
.. |image08| image:: ../../../_static/amebad/Example_Guides/SPI/SPI_Print_Image_And_Text_On_LCD_Screen/image08.png
246+
:width: 602 px
247+
:height: 384 px
248+
249+
.. |image09| image:: ../../../_static/amebad/Example_Guides/SPI/SPI_Print_Image_And_Text_On_LCD_Screen/image09.png
250+
:width: 589 px
251+
:height: 385 px
252+
253+
.. |image10| image:: ../../../_static/amebad/Example_Guides/SPI/SPI_Print_Image_And_Text_On_LCD_Screen/image10.png
254+
:width: 776 px
255+
:height: 510 px
256+
257+
.. |image11| image:: ../../../_static/amebad/Example_Guides/SPI/SPI_Print_Image_And_Text_On_LCD_Screen/image11.png
258+
:width: 533 px
259+
:height: 343 px
260+
261+
.. |image12| image:: ../../../_static/amebad/Example_Guides/SPI/SPI_Print_Image_And_Text_On_LCD_Screen/image12.png
262+
:width: 865 px
263+
:height: 714 px
264+
265+
.. |image13| image:: ../../../_static/amebad/Example_Guides/SPI/SPI_Print_Image_And_Text_On_LCD_Screen/image13.png
266+
:width: 789 px
267+
:height: 517 px
268+
269+
.. |image14| image:: ../../../_static/amebad/Example_Guides/SPI/SPI_Print_Image_And_Text_On_LCD_Screen/image14.png
270+
:width: 835px
271+
:height: 564 px
272+
273+
.. |image15| image:: ../../../_static/amebad/Example_Guides/SPI/SPI_Print_Image_And_Text_On_LCD_Screen/image15.png
274+
:width: 761 px
275+
:height: 859 px
276+
277+
.. |image16| image:: ../../../_static/amebad/Example_Guides/SPI/SPI_Print_Image_And_Text_On_LCD_Screen/image16.png
278+
:width: 750 px
279+
:height: 240 px
280+
281+
.. |image17| image:: ../../../_static/amebad/Example_Guides/SPI/SPI_Print_Image_And_Text_On_LCD_Screen/image17.png
282+
:width: 193 px
283+
:height: 258 px
284+
285+
.. |image18| image:: ../../../_static/amebad/Example_Guides/SPI/SPI_Print_Image_And_Text_On_LCD_Screen/image18.png
286+
:width: 768 px
287+
:height: 400 px
288+
289+
.. |image19| image:: ../../../_static/amebad/Example_Guides/SPI/SPI_Print_Image_And_Text_On_LCD_Screen/image19.png
290+
:width: 634 px
291+
:height: 906 px

0 commit comments

Comments
 (0)