Skip to content

Commit 922ca9a

Browse files
Updated tutorial
1 parent dd0a759 commit 922ca9a

File tree

1 file changed

+17
-30
lines changed

1 file changed

+17
-30
lines changed

content/hardware/09.mega/shields/giga-display-shield/tutorials/image-orientation/orientation-content.md

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,29 @@
11
---
2-
title: Using IMU to determine the orientation of the Giga Display Shield
2+
title: Screen Orientation With IMU Readings
33
description: 'Learn how to use the shields IMU to determine the orientation of the Giga Display Shield'
44
author: Benjamin Dannegård
5-
tags: [Display, IMU, orientation]
5+
tags: [Display, IMU, orientation, lvgl]
66
---
77

8-
Any modern device uses sensors to determine the correct orientation in which an image should be displayed. Using the Arduino GIGA R1 WiFi with the GIGA Display Shield we can read values given by the onboard IMU to determine what orientation an image should be given. This tutorial will show you how to manipulate an image on the GIGA Display Shield using readings from the IMU sensor.
8+
Any modern device with a screen uses sensors to determine the correct orientation in which an image should be displayed. Using the Arduino GIGA R1 WiFi with the GIGA Display Shield we can read values given by the onboard IMU to determine what orientation an image should be given. This tutorial will show you how to manipulate an image on the GIGA Display Shield using lvgl and readings from the IMU sensor.
99

1010
## Hardware & Software Needed
1111

12-
- [GIGA R1 WiFi](/hardware/giga-r1).
12+
- [GIGA R1 WiFi](/hardware/giga-r1)
1313
- [GIGA Display Shield]()
1414
- [Arduino IDE](https://www.arduino.cc/en/software)
1515
- [Arduino_BMI270_BMM150 library](https://reference.arduino.cc/reference/en/libraries/arduino_bmi270_bmm150/)
16-
- [Arduino_H7_Video](https://github.com/arduino/ArduinoCore-mbed/tree/main/libraries/Arduino_H7_Video) library.
17-
- [Lvgl](https://reference.arduino.cc/reference/en/libraries/lvgl/) library.
16+
- [Arduino_H7_Video library](https://github.com/arduino/ArduinoCore-mbed/tree/main/libraries/Arduino_H7_Video)
17+
- [Lvgl library](https://reference.arduino.cc/reference/en/libraries/lvgl/)
1818

1919
## Downloading the Library and Core
2020

21-
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. Now you have to install the library needed for the IMU. Go to **Tools > Manage libraries..**, search for **Arduino_BMI270_BMM150**, and install it. This library will help us with reading values from the IMU.
22-
23-
## Getting IMU Readings
24-
25-
The three-axis that we will measure will be:
26-
27-
- x-axis: Measures horizontally
28-
- y-axis: Measures vertically
29-
- z-axis: Measures the rotational axis
30-
31-
This tutorial will assume that the screen is oriented as in the image below.
32-
33-
![Orientation of screen normally]()
34-
35-
## Creating an Image
36-
37-
Any image could be used here. This tutorial will use the following image of the Arduino logo. Alternatively, any raw RGB565 image can be used. If you have an image you want to use, you can use this [online image converter](https://lvgl.io/tools/imageconverter), or any other software that lets you convert an image to a raw RGB565 image. This website will output in the Binary RGB565 format.
38-
39-
[In sketch image]()
21+
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. Now you have to install the library needed for the IMU and the library for handling the image. Go to **Tools > Manage libraries..**, search for **Arduino_BMI270_BMM150**, and install it. This library will help us with reading values from the IMU. Now search for **LVGL**, and install it. This library will be used for the image and rotating it.
4022

4123
## Using the IMU Readings With the Image
4224

43-
Now to first get the readings from the IMU we will use the `"Arduino_BMI270_BMM150.h"` library. Then we need to set the image name variables with `extern const lv_img_dsc_t arduino_logo_1;`. To use the IMU set it up with `BoschSensorClass imu(Wire1);`.
25+
Now to first get the readings from the IMU we will use the `"Arduino_BMI270_BMM150.h"` library. The `"Arduino_H7_Video.h"` and
26+
`"lvgl.h"` libraries will help us handle the image. Set up the display dimensions with `Arduino_H7_Video Display(800, 480, GigaDisplayShield);`. To use the IMU set it up with `BoschSensorClass imu(Wire1);`. Next, we can give the image its attributes.
4427

4528
```arduino
4629
#include "Arduino_BMI270_BMM150.h"
@@ -52,7 +35,7 @@ Arduino_H7_Video Display(800, 480, GigaDisplayShield); /* Arduino_H7_Vi
5235
BoschSensorClass imu(Wire1);
5336
```
5437

55-
initialize the display with `Display.begin();` and start recieving IMU readings with `imu.begin();`. Next, we can give the image its attributes.
38+
Start receiving IMU readings with `imu.begin();` and start the display with `Display.begin();`.
5639

5740
```arduino
5841
LV_IMG_DECLARE(img_arduinologo);
@@ -71,7 +54,7 @@ void setup() {
7154
}
7255
```
7356

74-
Now all that is left is to change the image depending on the IMU readings. First, declare the variables that will hold the values. Then to assign them the IMU reading values use `imu.readAcceleration(x, y, z);`. Next, we use `if ()` statements to change the rotation variable depending on the readings we are getting. And at the end, we render the image with the correct rotation.
57+
Now all that is left is to change the image depending on the IMU readings. First, declare the variables that will hold the values. Then to assign them the IMU reading values use `imu.readAcceleration(x, y, z);`. Next, we use `if ()` statements to change the rotation variable depending on the readings we are getting. And at the end, we render the image with the correct rotation. When the correct rotation has been calculated, we can apply it to the image using `lv_img_set_angle(img, rot_angle);`.
7558

7659
```arduino
7760
uint8_t rotation = 0;
@@ -90,7 +73,7 @@ void loop() {
9073
} else if (y > 0.8) {
9174
rotation = 3;
9275
}
93-
int16_t rot_angle = 900 - atan(x / y) * 180.0 / M_PI * 10;
76+
int16_t rot_angle = 900 - atan(x / y) * 180.0 / M_PI * 10; //Calculation for the rotation angle
9477
lv_img_set_angle(img, rot_angle);
9578
}
9679
}
@@ -100,7 +83,7 @@ void loop() {
10083

10184
### IMU Test Sketch
10285

103-
The easiest way to tell what values you are getting depending on the orientation of the device is to use a simple sketch, like the one below that will simply print the IMU values in the serial monitor. Take note of the values you are getting when you rotate the shield and you can use them in the previous sketch.
86+
The easiest way to tell what values you are getting depending on the orientation of the device is to use a simple sketch, like the one below that will print the IMU values in the serial monitor. Take note of the values you are getting when you rotate the shield and you can use them in the full sketch.
10487

10588
```arduino
10689
#include "Arduino_BMI270_BMM150.h"
@@ -177,6 +160,10 @@ void loop() {
177160
}
178161
```
179162

163+
### Using Another Image
164+
165+
Any image could be the sketch. This tutorial and the example uses an image of the Arduino logo. Alternatively, any raw RGB565 image can be used. If you have an image you want to use, you can use this [online image converter](https://lvgl.io/tools/imageconverter), or any other software that lets you convert an image to a raw RGB565 image. This website will output in the Binary RGB565 format. For further instructions on how to display your own image, have a look at our [Text and Image tutorial](/tutorials/text-and-image).
166+
180167
## Testing it Out
181168

182169
Now try rotating your device to see if the image behaves correctly. If the image does not rotate correctly have another look at the values you entered into the previous sketch. It might help to try and run the simple IMU readings printer sketch to take a quick look at the IMU values in the serial monitor. This will help you figure out what values should be considered when the device is being moved.

0 commit comments

Comments
 (0)