You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/hardware/09.mega/shields/giga-display-shield/tutorials/image-orientation/orientation-content.md
+17-30Lines changed: 17 additions & 30 deletions
Original file line number
Diff line number
Diff line change
@@ -1,46 +1,29 @@
1
1
---
2
-
title: Using IMU to determine the orientation of the Giga Display Shield
2
+
title: Screen Orientation With IMU Readings
3
3
description: 'Learn how to use the shields IMU to determine the orientation of the Giga Display Shield'
4
4
author: Benjamin Dannegård
5
-
tags: [Display, IMU, orientation]
5
+
tags: [Display, IMU, orientation, lvgl]
6
6
---
7
7
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.
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.
40
22
41
23
## Using the IMU Readings With the Image
42
24
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.
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();`.
56
39
57
40
```arduino
58
41
LV_IMG_DECLARE(img_arduinologo);
@@ -71,7 +54,7 @@ void setup() {
71
54
}
72
55
```
73
56
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);`.
int16_t rot_angle = 900 - atan(x / y) * 180.0 / M_PI * 10; //Calculation for the rotation angle
94
77
lv_img_set_angle(img, rot_angle);
95
78
}
96
79
}
@@ -100,7 +83,7 @@ void loop() {
100
83
101
84
### IMU Test Sketch
102
85
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.
104
87
105
88
```arduino
106
89
#include "Arduino_BMI270_BMM150.h"
@@ -177,6 +160,10 @@ void loop() {
177
160
}
178
161
```
179
162
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
+
180
167
## Testing it Out
181
168
182
169
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