One of the ways to access the Raspberry Pi's Sense HAT add-on board from Qt is by using the Qt Labs QtSenseHAT module.   Unfortunately the standard compilation procedure may not work as described in this forum where a solution is recommended to directly link the RTIMULib source code files instead of using its precompiled library.   This guide will explain one of the ways to perform such compilation with direct RTIMULib source code linkage under the assumption that the official https://wiki.qt.io/RaspberryPi2EGLFS guide is followed for the cross-compilation of other Qt modules.
1)  The cross-compilation of QtSenseHat module has to be performed after compiling the QtBase module it depends on as described in https://wiki.qt.io/RaspberryPi2EGLFS.  After the QtBase and all other desired Qt modules have been compiled using the https://wiki.qt.io/RaspberryPi2EGLFS guide,cd ~/raspi/qt5
to the qt5 directory on the host computer and clone the QtSenseHAT module into the qt5 directory using the following command: git clone https://github.com/qt-labs/qtsensehat.git
2)  From the terminal cd ~/raspi/qt5/qtsensehat/src/sensehat
and clone the RTIMULib2 library there by running the following command: git clone https://github.com/RTIMULib/RTIMULib2.git
3)  Using the Qt Creator open the "sensehat.pro" file under the "~/raspi/qt5/qtsensehat/src/sensehat" directory.   In the Qt Creator open the "qsensehatsensors.cpp" file and make the following changes:
– add #include <QtCore/QtMath>
– add #include <QLoggingCategory>
– change the #include <RTIMULib.h>
to become #include <RTIMULib2/RTIMULib/RTIMULib.h>
.
4)  Add all files from the the "~/raspi/qt5/qtsensehat/src/sensehat/RTIMULib2/RTIMULib/" directory to the "sensehat.pro" project file.   The easiest way to do so is to right click on the folder contating the .h or .cpp files listed in the project file tree within the Qt Creator and choose "Add existing files...".   Make sure to also include all files located in the "IMUDrivers" directory to the project.   After adding the files this way they will be added to the "sensehat.pro" file and will appear in the project file structure.
5)  Remove the "LIBS += -lRTIMULib" line from the "sensehat.pro" file located in the "~/raspi/qt5/qtsensehat/src/sensehat" folder.
6)  Remove the "LIBS += -lRTIMULib" line from the "rtimulib.pro" file located in the "~/raspi/qt5/qtsensehat/config.tests/rtimulib/" folder.
7)  Open the "main.cpp" file located in the "~/raspi/qt5/qtsensehat/config.tests/rtimulib/" folder and change the include statement from #include <RTIMULib.h>
to #include <../../src/sensehat/RTIMULib2/RTIMULib/RTIMULib.h>
8)  After the above changes compile the QtSenseHat just like any other module according to the directions in the https://wiki.qt.io/RaspberryPi2EGLFS guide.
9) If you don't want to do through the above steps yourself the final result of such adjustement may be downloaded as the qtsensehat.tar.xz archive.   This archive needs to be extracted into the qt5 folder and compiled like any other Qt module as described in step 16 of the https://wiki.qt.io/RaspberryPi2EGLFS guide.
As an alternative it is also possible to use a different Qt plugin to access Sense HAT using Qt which used to be considered for potential inclusion into Qt (see QTBUG-60309 and QTBUG-63612).   Although it may be trickier to compile.
As an laternative to the Sense HAT board one can connect the Texas Instruments SensorTag over bluetooth for sensor input by trying the QtSensorTag plugin (see QTBUG-63610) which has been merged with the Qt dev branch and may be cloned as part of QtSensors using the following git command: git clone git://code.qt.io/qt/qtsensors.git
.   It is important to install all necessary bluetooth libraries onto your Linux system before compiling (or cross-compiling) Qt or else it will not be able to access the SensorTag bluetooth hardware.
www.bytran.org -|- Page created in 2018, last edited June 3, 2022
✉  Email:  bytran@bytran.org
© 2018 - 2022 Dzianis Pliutau