Skip to content

Commit 5d61803

Browse files
Merge pull request #531 from arduino/karlsoderby/review-giga-display-shield
[GIGA Display Shield] LVGL + Microphone guide review
2 parents f697ecb + e97a223 commit 5d61803

19 files changed

+113
-189
lines changed

content/hardware/10.mega/shields/giga-display-shield/tutorials/lvgl-guide/assets/button-clicked.svg

Lines changed: 0 additions & 15 deletions
This file was deleted.
Loading

content/hardware/10.mega/shields/giga-display-shield/tutorials/lvgl-guide/assets/button.svg

Lines changed: 0 additions & 27 deletions
This file was deleted.

content/hardware/10.mega/shields/giga-display-shield/tutorials/lvgl-guide/assets/checkboxes.svg

Lines changed: 0 additions & 27 deletions
This file was deleted.

content/hardware/10.mega/shields/giga-display-shield/tutorials/lvgl-guide/assets/example-in-ide.svg

Lines changed: 0 additions & 27 deletions
This file was deleted.
Loading
Loading

content/hardware/10.mega/shields/giga-display-shield/tutorials/lvgl-guide/assets/image.svg

Lines changed: 0 additions & 15 deletions
This file was deleted.

content/hardware/10.mega/shields/giga-display-shield/tutorials/lvgl-guide/assets/radio-buttons.svg

Lines changed: 0 additions & 15 deletions
This file was deleted.
Loading

content/hardware/10.mega/shields/giga-display-shield/tutorials/lvgl-guide/assets/slider.svg

Lines changed: 0 additions & 15 deletions
This file was deleted.

content/hardware/10.mega/shields/giga-display-shield/tutorials/lvgl-guide/content.md

Lines changed: 107 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
---
2-
title: Guide for Using LVGL With the GIGA Display Shield
2+
title: GIGA Display Shield LVGL Guide
33
description: 'Learn how to use LVGL with the GIGA Display Shield.'
44
author: Benjamin Dannegård
55
tags: [Display, LVGL]
66
---
77

88
## Introduction
99

10-
LVGL is a very powerful graphical framework that is compatible with the GIGA Display Shield. It will allow you to put components on the screen like buttons, images, loading bars, sliders, checkboxes, etc. It also allows you to fully customize the screenspace on the display. This guide will go through the different components in detail so you can learn how to best implement it to your project.
10+
[LVGL](https://lvgl.io/) is a graphical framework for building powerful UIs, and is fully compatible with the GIGA Display Shield. It allows you to build UIs, using pre-made widgets like buttons, images, loading bars, sliders, checkboxes, etc. It also allows you to fully customize the screenspace on the display. In this guide, we will go through some of the different components, so you can learn how to best implement it in your projects.
11+
12+
***LVGL is a large framework, and the aim of this guide is to get you familiar with it. For much more information, visit the [LVGL documentation](https://docs.lvgl.io/master/)***
1113

1214
## Hardware & Software Needed
1315

@@ -19,50 +21,61 @@ LVGL is a very powerful graphical framework that is compatible with the GIGA Dis
1921

2022
## Downloading the Library and Core
2123

22-
The GIGA core includes a library that will help us handle the display, so make sure you have the latest version of the core.
24+
The GIGA R1 core includes the [Arduino_H7_Video](https://github.com/arduino/ArduinoCore-mbed/tree/main/libraries/Arduino_H7_Video) library that handles the display.
2325

2426
In this guide, we will be using three different libraries:
25-
- **[Arduino_H7_Video](https://github.com/arduino/ArduinoCore-mbed/tree/main/libraries/Arduino_H7_Video)**, this one is bundled with the core, so make sure you have the latest version of the [Mbed core](https://github.com/arduino/ArduinoCore-mbed)
26-
- **Arduino_GigaDisplayTouch**
27-
- **LVGL**
27+
- [Arduino_H7_Video](https://github.com/arduino/ArduinoCore-mbed/tree/main/libraries/Arduino_H7_Video), this one is bundled with the core, so make sure you have the latest version of the [Mbed core](https://github.com/arduino/ArduinoCore-mbed) installed.
28+
- [Arduino_GigaDisplayTouch](https://www.arduino.cc/reference/en/libraries/arduino_gigadisplaytouch/)
29+
- [lvgl](https://github.com/lvgl/lvgl)
2830

29-
Open the library manager and install the latest version of **Arduino_GigaDisplayTouch** and **lvgl**.
31+
To install them, open the library manager and install the latest version by searching for **"Arduino_GigaDisplayTouch"** and **"lvgl"**.
3032

3133
In the sketch include the libraries like this:
3234

3335
```arduino
3436
#include "Arduino_H7_Video.h"
3537
#include "lvgl.h"
36-
3738
#include "Arduino_GigaDisplayTouch.h"
3839
```
3940

4041
## General Set Up
4142

43+
In this section, we will go through the fundamental elements of an LVGL sketch:
44+
- How to define & configure the display,
45+
- how to create a grid layout,
46+
- how to add an object to the grid,
47+
- how to update the display.
48+
49+
***At the end of this section, you will find a complete example which implements a grid layout. You can [skip directly to the example](#minimal-example), but if you have no prior experience with lvgl, we recommend you follow the information below.***
50+
4251
### Display Shield Configuration
4352

44-
We then will also need to define the screen we are using, do this by adding this line of code after the library inclusions. This function will use the **Arduino_H7_Video** library:
53+
The first thing we need to do is to define the display we are using, by creating a object using the `Arduino_H7_Video` class, specifying the height, width and type of display.
4554

4655
```arduino
4756
Arduino_H7_Video Display(800, 480, GigaDisplayShield);
4857
````
4958
50-
And if you want to use touch with your application call the following to use the **Arduino_GigaDisplayTouch** library:
59+
And if you want to use touch with your application, we need to create an object using the `Arduino_GigaDisplayTouch` class.
5160
5261
```arduino
5362
Arduino_GigaDisplayTouch TouchDetector;
5463
```
5564

56-
Then we have to start these functions by putting these lines in the `setup()` function:
65+
In the `setup()`, we begin by initializing the display and the touch detector.
5766

5867
```arduino
59-
Display.begin();
60-
TouchDetector.begin();
68+
void setup(){
69+
Display.begin();
70+
TouchDetector.begin();
71+
}
6172
```
6273

74+
With these things set up, we can go on to configure the LVGL elements.
75+
6376
### LVGL Screen Configuration
6477

65-
When creating elements, information about the screen and placement needs to be provided. Let's create a pointer variable that can be used whenever the screenspace needs to be used. The pointer variable will be named `screen` and to use the current screen for the pointer use `lv_scr_act()`.
78+
When creating elements, information about the screen and placement needs to be provided. Let's create a pointer variable that can be used whenever the screenspace needs to be used. The pointer variable will be named `screen` and to use the current screen for the pointer use `lv_scr_act()`. This code should also be added inside `setup()`.
6679

6780
```arduino
6881
lv_obj_t * screen = lv_obj_create(lv_scr_act());
@@ -101,12 +114,24 @@ Now that the columns and rows have been defined the overall screen needs to be t
101114
lv_obj_set_size(grid, Display.width(), Display.height());
102115
```
103116

104-
Then if we want to center the grid on the screen, simply use:
117+
Then, just to test it out, let's add an object to the grid.
118+
- first declare the `obj` pointer add it to the `grid`,
119+
- then we set the grid cell via `lv_obj_set_grid_cell()` method.
105120

106121
```arduino
107-
lv_obj_center(grid);
122+
lv_obj_t* obj;
123+
obj = lv_obj_create(grid);
124+
lv_obj_set_grid_cell(obj, LV_GRID_ALIGN_STRETCH, 0, 1, //column
125+
LV_GRID_ALIGN_STRETCH, 0, 1); //row
108126
```
109127

128+
129+
The `lv_obj_set_grid_cell())` have a set of parameters related to how the object is positioned and aligned. In this case, we have created a 2x2 grid, where the `0` (column) and `0` (row) indicates where on the grid it should go.
130+
131+
Take a look at this graphic to understand it better:
132+
133+
![How grids work in LVGL.](assets/gridlvgl.png)
134+
110135
### Update Loop
111136

112137
Include this in the loop of your sketch to make sure the LVGL engine is running and updating the screen.
@@ -117,6 +142,59 @@ void loop() {
117142
}
118143
```
119144

145+
### Minimal Example
146+
147+
The summary of all code snippets in this section can be found in the example below. It implements a 2x2 grid, as well as adds an object in each slot.
148+
149+
```arduino
150+
#include "Arduino_H7_Video.h"
151+
#include "lvgl.h"
152+
#include "Arduino_GigaDisplayTouch.h"
153+
154+
Arduino_H7_Video Display(800, 480, GigaDisplayShield);
155+
Arduino_GigaDisplayTouch TouchDetector;
156+
157+
void setup() {
158+
Display.begin();
159+
TouchDetector.begin();
160+
161+
//Display & Grid Setup
162+
lv_obj_t* screen = lv_obj_create(lv_scr_act());
163+
lv_obj_set_size(screen, Display.width(), Display.height());
164+
165+
static lv_coord_t col_dsc[] = { 370, 370, LV_GRID_TEMPLATE_LAST };
166+
static lv_coord_t row_dsc[] = { 215, 215, 215, 215, LV_GRID_TEMPLATE_LAST };
167+
168+
lv_obj_t* grid = lv_obj_create(lv_scr_act());
169+
lv_obj_set_grid_dsc_array(grid, col_dsc, row_dsc);
170+
lv_obj_set_size(grid, Display.width(), Display.height());
171+
172+
//top left
173+
lv_obj_t* obj;
174+
obj = lv_obj_create(grid);
175+
lv_obj_set_grid_cell(obj, LV_GRID_ALIGN_STRETCH, 0, 1, //column
176+
LV_GRID_ALIGN_STRETCH, 0, 1); //row
177+
178+
//bottom left
179+
obj = lv_obj_create(grid);
180+
lv_obj_set_grid_cell(obj, LV_GRID_ALIGN_STRETCH, 0, 1, //column
181+
LV_GRID_ALIGN_STRETCH, 1, 1); //row
182+
//top right
183+
obj = lv_obj_create(grid);
184+
lv_obj_set_grid_cell(obj, LV_GRID_ALIGN_STRETCH, 1, 1, //column
185+
LV_GRID_ALIGN_STRETCH, 0, 1); //row
186+
187+
//bottom right
188+
obj = lv_obj_create(grid);
189+
lv_obj_set_grid_cell(obj, LV_GRID_ALIGN_STRETCH, 1, 1, //column
190+
LV_GRID_ALIGN_STRETCH, 1, 1); //row
191+
}
192+
193+
void loop() {
194+
lv_timer_handler();
195+
}
196+
```
197+
120198
## Visual Elements
121199

122200
### Image
@@ -148,9 +226,9 @@ To make sure we see the image use the align function to make it centered. Then a
148226
lv_obj_set_size(img1, 200, 150);
149227
```
150228

151-
![An image rendered on the Display Shield with LVGL](assets/image.svg)
229+
![An image rendered on the Display Shield with LVGL](assets/image.png)
152230

153-
### Full Example
231+
**Full Example:**
154232

155233
```arduino
156234
#include "Arduino_H7_Video.h"
@@ -221,9 +299,9 @@ The startup state of the checkbox can be set with `lv_obj_add_state()`. Where th
221299
lv_obj_add_state(checkbox, LV_STATE_CHECKED);
222300
```
223301

224-
![Checkboxes rendered on the Display Shield with LVGL](assets/checkboxes.svg)
302+
![Checkboxes rendered on the Display Shield with LVGL](assets/checkboxes.png)
225303

226-
### Full Example
304+
**Full Example:**
227305

228306
```arduino
229307
#include "Arduino_H7_Video.h"
@@ -296,9 +374,9 @@ The size of the radio button is set with `lv_style_set_radius`. To make the radi
296374
lv_style_set_bg_img_src(&style_radio_chk, NULL);
297375
```
298376

299-
![Radio buttons rendered on the Display Shield with LVGL](assets/radio-buttons.svg)
377+
![Radio buttons rendered on the Display Shield with LVGL](assets/radiobuttons.png)
300378

301-
### Full Example
379+
**Full Example:**
302380

303381
```arduino
304382
#include "Arduino_H7_Video.h"
@@ -391,9 +469,9 @@ If you want a label by your slider it can be created like you would create any o
391469
lv_obj_align_to(label, slider, LV_ALIGN_OUT_BOTTOM_MID, 0, 10);
392470
```
393471

394-
![Slider rendered on the Display Shield with LVGL](assets/slider.svg)
472+
![Slider rendered on the Display Shield with LVGL](assets/slider.png)
395473

396-
### Full Example
474+
**Full Example:**
397475

398476
```arduino
399477
#include "Arduino_H7_Video.h"
@@ -517,7 +595,7 @@ static void set_bar_val(void * bar, int32_t val) {
517595

518596
![A bar rendered on the Display Shield with LVGL](assets/bar.gif)
519597

520-
### Full Example
598+
**Full Example:**
521599

522600
```arduino
523601
#include "Arduino_H7_Video.h"
@@ -630,10 +708,10 @@ static void button_event_callback(lv_event_t * e) {
630708
}
631709
```
632710

633-
![A button rendered on the Display Shield with LVGL](assets/button.svg)
634-
![Button when it has been pressed](assets/button-clicked.svg)
711+
![A button rendered on the Display Shield with LVGL](assets/button.png)
712+
![Button when it has been pressed](assets/button-clicked.png)
635713

636-
### Full Example
714+
**Full Example:**
637715

638716
```arduino
639717
#include "Arduino_H7_Video.h"
@@ -695,7 +773,7 @@ void loop() {
695773

696774
This guide went through the building blocks of the different components that can be implemented with LVGL. To see these examples in a full running example sketch go to **File > Examples > Arduino_H7_Video > LVGLDemo**.
697775

698-
![Example in the IDE](assets/example-in-ide.svg)
776+
![Example in the IDE](assets/example-in-ide.png)
699777

700778
This example sketch will show the different components in a 2x2 grid.
701779

content/hardware/10.mega/shields/giga-display-shield/tutorials/microphone-tutorial/assets/pdm-test-sketch.svg

Lines changed: 0 additions & 15 deletions
This file was deleted.

content/hardware/10.mega/shields/giga-display-shield/tutorials/microphone-tutorial/content.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
2-
title: Microphone With LVGL Tutorial
3-
description: "Learn how to use the GIGA Display Shield's microphone together with LVGL."
2+
title: GIGA Display Shield Microphone & LVGL Tutorial
3+
description: "Learn how to use the GIGA Display Shield's microphone with LVGL."
44
author: Benjamin Dannegård
55
tags: [Display, microphone, LVGL]
66
---
@@ -20,11 +20,11 @@ Make sure the latest GIGA core is installed in the Arduino IDE. **Tools > Board
2020

2121
## Microphone Readings With The Shield
2222

23-
### Microphone Test Sketch
23+
### Test Microphone
2424

2525
To test the microphone we can use the **PDMSerialPlotter** example sketch. This sketch can be found in **File > Examples > PDM** in the Arduino IDE. This sketch will print readings in the serial monitor. Upload the sketch and check so that readings are appearing in the serial monitor.
2626

27-
![Example sketch printing values in the serial monitor](assets/pdm-test-sketch.svg)
27+
![Example sketch printing values in the serial monitor](assets/pdm-test-sketch.png)
2828

2929
### Using the Microphone Readings
3030

@@ -103,6 +103,8 @@ In the section below you can find the full sketch. If you upload it to your GIGA
103103

104104
### Full Sketch
105105

106+
You will find the full sketch in the example below:
107+
106108
```arduino
107109
#include <PDM.h>
108110
#include "Arduino_H7_Video.h"

0 commit comments

Comments
 (0)