Skip to content

Commit 4057d8f

Browse files
authored
Merge pull request #1485 from arduino/benjamindannegard/giga-display-shield-square-tutorial
[GIGA Display Shield] SquareLine tutorial
2 parents a66efdb + af7f55e commit 4057d8f

File tree

9 files changed

+409
-0
lines changed

9 files changed

+409
-0
lines changed

content/hardware/10.mega/shields/giga-display-shield/tutorials/10.square-line-tutorial/assets/button_label_gui.svg

Lines changed: 15 additions & 0 deletions
Loading

content/hardware/10.mega/shields/giga-display-shield/tutorials/10.square-line-tutorial/assets/export_options.svg

Lines changed: 27 additions & 0 deletions
Loading

content/hardware/10.mega/shields/giga-display-shield/tutorials/10.square-line-tutorial/assets/folder_structure.svg

Lines changed: 31 additions & 0 deletions
Loading

content/hardware/10.mega/shields/giga-display-shield/tutorials/10.square-line-tutorial/assets/lv_config.svg

Lines changed: 27 additions & 0 deletions
Loading

content/hardware/10.mega/shields/giga-display-shield/tutorials/10.square-line-tutorial/assets/names_highlight.svg

Lines changed: 17 additions & 0 deletions
Loading

content/hardware/10.mega/shields/giga-display-shield/tutorials/10.square-line-tutorial/assets/project_settings.svg

Lines changed: 44 additions & 0 deletions
Loading

content/hardware/10.mega/shields/giga-display-shield/tutorials/10.square-line-tutorial/assets/squareline_studio_project.svg

Lines changed: 15 additions & 0 deletions
Loading

content/hardware/10.mega/shields/giga-display-shield/tutorials/10.square-line-tutorial/assets/text_font_size.svg

Lines changed: 16 additions & 0 deletions
Loading
Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
---
2+
title: SquareLine Studio With the GIGA Display Shield
3+
description: "Learn how to use SquareLine Studio to create LVGL GUIs for the GIGA Display Shield"
4+
author: Benjamin Dannegård
5+
tags: [Display, squareline, LVGL]
6+
---
7+
8+
The GIGA Display Shield with the GIGA R1 WiFi board can run LVGL which allows for the creation of advanced GUIs. To make the design of the GUI easier we can use the software SquareLine Studio. This will allow us to drag and drop different elements and then export it for usage on the display shield.
9+
10+
## Hardware & Software Needed
11+
12+
- [Arduino GIGA R1 WiFi](https://store.arduino.cc/products/giga-r1-wifi)
13+
- [Arduino GIGA Display Shield](https://store.arduino.cc/products/giga-display-shield)
14+
- [Arduino IDE](https://www.arduino.cc/en/software)
15+
- [SquareLine Studio](https://squareline.io/)
16+
17+
## Downloading the Library and Core
18+
19+
Make sure the latest GIGA Core is installed in the Arduino IDE. **Tools > Board > Board Manager...**. Here you need to look for the **Arduino Mbed OS Giga Boards** and install it, the [Arduino_H7_Video library](https://github.com/arduino/ArduinoCore-mbed/tree/main/libraries/Arduino_H7_Video) is included in the core. Now you have to install the library needed. Go to **Tools > Manage libraries..**, search for [**lvgl**](https://github.com/lvgl/lvgl) and [**Arduino_GigaDisplayTouch**](https://github.com/arduino-libraries/Arduino_GigaDisplayTouch), install both of these libraries.
20+
21+
## Using SquareLine Studio
22+
23+
First download SquareLine Studio from the link above. Now in SquareLine Studio go to the "create" section and select the Arduino tab. On the right you can set the "project settings". These needs to be set like so:
24+
25+
- **Project name**: Set the name of your project
26+
- **Resolution**: 800x480 (to fully use the 800x480 screen in landscape mode, select 480x800 for portrait)
27+
- **Color depth**: 16 bit
28+
- **LVGL version**: 8.3.x
29+
30+
As show on this image:
31+
32+
![Project settings in SquareLine Studio](assets/project_settings.svg)
33+
34+
Finally click on the "create" button.
35+
36+
### Creating the GUI
37+
38+
Now it is time to create the GUI that will be on the display shield. Feel free to customize your GUI however you want. On the left there are plenty of handy widgets that can be drag and dropped. On the right you can set more specific options for the widgets.
39+
40+
![Project in SquareLine Studio](assets/squareline_studio_project.svg)
41+
42+
### Exporting a Project From SquareLine Studio
43+
44+
Now that the project is ready it is time to export it. First click on the "Export" tab at the top, then select "Create Template Project" and select the destination for your exported files. When that is done click on the "Export UI Files" and wait for the process to finish.
45+
46+
![Export options in SquareLine Studio](assets/export_options.svg)
47+
48+
Now all the files should be in the folder that you specified.
49+
50+
### Running the SquareLine Studio Project on Arduino IDE
51+
52+
In the folder that you exported the files to, go into the "libraries" folder and then copy the "ui" folder.
53+
54+
![Folder structure of the exported files](assets/folder_structure.svg)
55+
56+
Place this folder in your **Libraries** folder found inside your **Arduino** folder. This is the same **Arduino** folder that contains your Arduino IDE sketches.
57+
58+
Now to run the SquareLine Studio project, use this sketch:
59+
60+
```arduino
61+
#include "Arduino_H7_Video.h"
62+
#include "Arduino_GigaDisplayTouch.h"
63+
64+
#include "lvgl.h"
65+
#include "ui.h"
66+
67+
/* Insert resolution WxH according to your SquareLine studio project settings */
68+
Arduino_H7_Video Display(800, 480, GigaDisplayShield);
69+
Arduino_GigaDisplayTouch Touch;
70+
71+
void setup() {
72+
Display.begin();
73+
Touch.begin();
74+
75+
ui_init();
76+
}
77+
78+
void loop() {
79+
80+
/* Feed LVGL engine */
81+
lv_timer_handler();
82+
}
83+
```
84+
85+
## Using SquareLine Studio Widgets in Arduino IDE
86+
87+
The project from SquareLine Studio is exported as a library, let's take a look at how we can reference a specific element in the GUI. To demonstrate this we will first create a simple GUI with a increase button, a decrease button and a label. The label will show the number that will decrease or increase depending on what button is pressed. Our GUI will look like this:
88+
89+
![The GUI we will be using in this section](assets/button_label_gui.svg)
90+
91+
Pay attention to the names of the button and the label, which can be seen on the right side and the upper left side here:
92+
93+
![Name sections highlighted in SquareLine Studio](assets/names_highlight.svg)
94+
95+
Name the widgets accordingly:
96+
97+
- **Increase Button**: ui_ButtonInc
98+
- **Decrease Button**: ui_ButtonDec
99+
- **Number Label**: ui_LabelNum
100+
101+
Also pay attention to the size of the font set for the counter label. We set the size to 26, this then needs to be enabled in the lv_conf.h file. This file can be found in /mbed/libraries/Arduino_H7_Video/src.
102+
103+
![Font size option in SquareLine Studio](assets/text_font_size.svg)
104+
105+
And to enable the font size find the **FONT USAGE** section. If you want to enable any other size simply change the `0` next to any of the font sizes into a `1`:
106+
107+
![lv_conf.h font usage section](assets/lv_config.svg)
108+
109+
Now export the project and put the library in the Arduino libraries folder, as shown in the previous section.
110+
111+
First declare the libraries and set up the screen, this will be the same as the sketch above.
112+
113+
```arduino
114+
#include "Arduino_H7_Video.h"
115+
#include "Arduino_GigaDisplayTouch.h"
116+
117+
#include "lvgl.h"
118+
#include "ui.h"
119+
120+
/* Insert resolution WxH according to your SquareLine studio project settings */
121+
Arduino_H7_Video Display(800, 480, GigaDisplayShield);
122+
Arduino_GigaDisplayTouch Touch;
123+
```
124+
125+
Then it is as simple as using the names of the widgets in a LVGL function. For example, when a function like `lv_label_set_text_fmt(NAME_OF_LABEL, "Label");` needs a reference to a label object, we can enter the name of the label that we created in SquareLine Studio. Same goes for the button widgets, like this in the `setup()` function:
126+
127+
```arduino
128+
void setup() {
129+
Display.begin();
130+
Touch.begin();
131+
132+
/* Initialize the user interface designed with SquareLine Studio */
133+
ui_init();
134+
135+
/* Add buttons event handlers */
136+
lv_obj_add_event_cb(ui_ButtonInc, ButtonInc_evt_handler, LV_EVENT_ALL, NULL);
137+
lv_obj_add_event_cb(ui_ButtonDec, ButtonDec_evt_handler, LV_EVENT_ALL, NULL);
138+
139+
/* Set initial value of the label to zero */
140+
label_val = 0;
141+
lv_label_set_text_fmt(ui_LabelNum, "%d", label_val);
142+
}
143+
```
144+
145+
The last important part of the sketch are the callback functions that will run when a button is pressed. In the segment above you can see how the callback functions are tied to the buttons. The function will check when the button is pressed and increase the count on the label:
146+
147+
```arduino
148+
static void ButtonInc_evt_handler(lv_event_t * e) {
149+
lv_event_code_t code = lv_event_get_code(e);
150+
151+
if(code == LV_EVENT_CLICKED) {
152+
label_val++;
153+
lv_label_set_text_fmt(ui_LabelNum, "%d", label_val);
154+
}
155+
}
156+
```
157+
158+
### Full Sketch
159+
160+
```arduino
161+
#include "Arduino_H7_Video.h"
162+
#include "Arduino_GigaDisplayTouch.h"
163+
164+
#include "lvgl.h"
165+
#include "ui.h"
166+
167+
/* Initialize the GIGA Display Shield with a resolution of 800x480 pixels */
168+
Arduino_H7_Video Display(800, 480, GigaDisplayShield);
169+
Arduino_GigaDisplayTouch Touch;
170+
171+
int label_val;
172+
173+
static void ButtonInc_evt_handler(lv_event_t * e) {
174+
lv_event_code_t code = lv_event_get_code(e);
175+
176+
if(code == LV_EVENT_CLICKED) {
177+
label_val++;
178+
lv_label_set_text_fmt(ui_LabelNum, "%d", label_val);
179+
}
180+
}
181+
182+
static void ButtonDec_evt_handler(lv_event_t * e) {
183+
lv_event_code_t code = lv_event_get_code(e);
184+
185+
if(code == LV_EVENT_CLICKED) {
186+
label_val--;
187+
lv_label_set_text_fmt(ui_LabelNum, "%d", label_val);
188+
}
189+
}
190+
191+
void setup() {
192+
Display.begin();
193+
Touch.begin();
194+
195+
/* Initialize the user interface designed with SquareLine Studio */
196+
ui_init();
197+
198+
/* Add buttons event handlers */
199+
lv_obj_add_event_cb(ui_ButtonInc, ButtonInc_evt_handler, LV_EVENT_ALL, NULL);
200+
lv_obj_add_event_cb(ui_ButtonDec, ButtonDec_evt_handler, LV_EVENT_ALL, NULL);
201+
202+
/* Set initial value of the label to zero */
203+
label_val = 0;
204+
lv_label_set_text_fmt(ui_LabelNum, "%d", label_val);
205+
}
206+
207+
void loop() {
208+
/* Feed LVGL engine */
209+
lv_timer_handler();
210+
}
211+
```
212+
213+
## Next Step
214+
215+
If you are curious about how LVGL works with the GIGA Display Shield, take a look at our [LVGL Guide](/tutorials/giga-display-shield/lvgl-guide).
216+
217+
LVGL can also be used in combination with the sensors on the display shield. Have a look at our [Image Orientation tutorial](/tutorials/giga-display-shield/image-orientation).

0 commit comments

Comments
 (0)