GPS-PIE Slice Example Software

The example software described below is provided as the starting point for development only. Although these programs are fully functional as described, fitness of this software for any specific purpose is specifically disclaimed. The source code is commented throughout to provide documentation for all functions. The example software is available either as a download or on a pre-configured SD card.
Please note that we can only answer questions that relate specifically to our boards and the example software as is. There is no application specific software or support available for these boards. We regret that we are not able to do projects for customers or provide any consultancy on any projects. We cannot explain Euler angles, quaternions or Kalman filters any better than the many online tutorials that already exist. All of our example code is written in C as the manufacturer's driver code for the BNO055 and MS5637 is provided in C. We provide no code or support for Python, Java or any other language.
Dependencies
The Raspberry Pi serial port must be configured for the GPS receiver. See Raspberry Pi serial configuration for GPS receivers for details.
The BNO055 motion sensor is not compatible with the standard Raspberry Pi hardware I2C interface so needs to be set up differently. See Raspberry Pi I2C configuration for the BNO055 for details.
As these configuration changes may be incompatable with other boards and software you may currently use with your Raspberry Pi we offer our example code on an SD card pre-configured with Raspbian Buster as a development environment. This will allow you to keep your current configuration on your current SD card ready to swap back in at any time.
WiringPI
Our example software programs described below are dependent on the WiringPi library for GPIO interfacing, i2c and other functionality. Run the following command to check you have the latest version or to install WiringPi:
sudo apt-get install wiringpi
 
OpenGL
The cube example program uses the IMU output of the BNO055 to animate an OpenGL cube. This example requires that OpenGL be installed on the Raspberry Pi. To do this, follow the setup OpenGL instructions.
 
GPS Receiver Example Software
The gps example software is contained in the GPS_EXAMPLE directory. The file nmea.c contains the NMEA parser code. This is partially based on the libgps library by Walter Dal Mut. It allows the conversion from raw NMEA data sentences to variables for latitude, longitude, speed, altitude and heading. The file gps_functions.c contains the GPS receiver interface code. This contains functions which open the Raspberry Pi serial port with the correct baud rate for the GPS receiver, set up the GPS receiver to the desired baud rate and set the NMEA data sentence output frequency. It provides an example of how to use the PMTK codes to control the GPS receiver setup.

The file gps_example.c contains the GPS example program which creates a simple datalogger. It uses the gps functions to open the serial port, set up the GPS receiver, read in the NMEA data and write the data to a file, named automatically with the current time and date. The raw NMEA data is also written to the terminal window as shown below. If a button is installed on GPIO pin 29 the program will shutdown the Raspberry Pi when it is pressed. This allows the safe operation of the logger without a screen, keyboard or mouse for mobile testing.

The example program is set up for the L80 GPS receiver. If you are using the Gmm slice you will need to edit lines 93 and 94 which are shown below before compiling. Comment out line 93 and uncomment line 94.

 
BNO055 IMU Motion Sensor Example Software
The BNO055 example software is comprised of two separate example programs in the directories BNO055 and Cube. The example in the cube directory depends on the contents of the BNO055 directory so these must be compiled first.
BNO055 Interface Example
The BNO055 directory contains the files shown below. The Bosch Sensortec driver code for the BNO055 is contained in bno055.c. This code provides the interface functions for all of the BNO055 sensors and the register settings that can be applied to them. The driver function declarations are in bno055.h. Both of these files are unchanged from the Bosch Sensortec Github and should not need to be altered. The file bno055_funcs.c contains functions that provide the Raspberry Pi interface code to the Bosch Sensortec driver. These use the WiringPi library to create the i2c interface routines required to access the BNO055 as well as routines to setup, access and format the sensor data. These functions are declared in bno055_funcs.h.

The example program contained in main.c demonstrates the simple set up and usage of the BNO055 in NDOF mode which allows a demonstration of the device as a 9 degree of freedom IMU. When the program is run it will first read the sensor configuration file bno055_data.cfg from the disk and attempt to configure the sensor fusion algorithm. Please see our description of the BNO055 configuration procedure for full details. When the BNO055 is configured the program will output the sensor data to the terminal window as shown below. It shows the Euler angles giving heading, roll and pitch. Please see page 30 of the data sheet for the angle conventions. The accelerometer output is divided into linear acceleration, without the influence of gravity, and acceleration due to gravity, without the influence of motion. The temperature is also shown. This is not ambient temperature, but the temperature of the sensor on the module board.

The program also demonstrates how to set up an interrupt on the BNO055, in this example on any motion on any accelerometer axis. A corresponding interrupt service routine is set up on GPIO pin 13 which will simply trigger the printing of a message to the terminal window. For this to work the BNO055 interrupt pin must be connected to GPIO pin 13 either by a jumper or wire link as shown below. Jumper shown is not supplied.

 
Cube BNO055 Example
The Cube example program uses the output of the BNO055 IMU to animate a cube displayed on screen by the Raspberry Pi using Open GL. The cube program is provided as an example to allow the visualisation of the BNO055 sensor data. The cube directory contains the files shown below. The faces of the cube displayed are defined by the set of *.raw image files. The file cube.c contains the code for the example program which uses OpenGL to create the full screen cube display. The program includes bno055_funcs.h from the BNO055 directory to allow access to the BNO055 interface functions. The makefile links bno055.o and bno055_funcs.o from the BNO055 directory when cube.c is compiled to provide the program with access to the BNO055 interface. The program can therefore call functions to set the BNO055 up in NDOF mode and then return either Euler angles or quaternions from the BNO055 IMU. On start-up the program uses bno055_data.cfg as described above at the start of the BNO055 configuration process. When the sensors are configured the cube will be displayed as shown below.

The BNO055 is able to generate Euler angles representing pitch, roll and magnetic heading. The front face of the cube always points to magnetic north. However these Euler angle outputs are only consistent when pitch and roll stay below 45 degrees. For an alternative solution the quaternion output of the BNO055 can be used and then converted to Euler angles. The cube program can display the output of both data types. It will always start using quaternions denoted by the Q before the heading at the bottom of the screen, but if a button is installed on GPIO pin 29 it can be used to toggle between quaternions and Euler angles. When Euler angles are selected an E will be shown at the bottom of the screen. The Quaternion to Euler conversion is based on the Wikipedia example code and is not guaranteed to produce accurate results in all orientations. No account is made for gimbal lock.

 
MS5637 Example Software
The MS5637 directory contains the files shown below. The MS5673 interface code ms56376_funcs.c consists of the TEConnectivity source code containing the algorithm described in the datasheet for reading the pressure from the sensor. In addition functions for converting pressure to altitude in metres and feet are also included. Other functions also provide for setting up the i2c interface for communicating to the sensor. The file ms56376_funcs.h contains function definitions so the interface code can be included in other projects. Once compiled using the makefile ms56376_funcs.o can be compiled into other projects.

The example program main.c demonstrates a simple set-up and use of the MS5637 sensor to read barometric pressure, convert it to altitude in metres and feet, printing the results to the terminal window as shown below. Initially the altitude is calculated from a sea level reference pressure defined in the program. The program also demonstrates how to use a button connected to Raspberry Pi GPIO pin 29 as an control input. Pressing this button resets the base pressure reading so that subsequent pressure readings are taken from this level. This effectively zeros the pressure reading so the altitude is taken from this point rather than the sea level reference. Please note that the example software does round values in the calculations.
Please note that there are timing issues involved with including the MS5637 code. The MS5637 does not have a data ready interrupt and does not allow polling. A sensor read requires a fixed time interval between the initial request to the sensor for data and the reading of data. At the highest resolution this will take just over 40ms.
 
Combined Example Software
The COMBINED_EXAMPLE directory contains an example of how the interface code for the sensors described above can be combined into a program. The file main.c contains the calls to the various functions that setup and get data from the three sensors. The program depends on gps_functions.o and gps_functions.h from the GPS_EXAMPLE directory, bno055.o , bno055_funcs.o and bno055_funcs.h from the BNO055 directory with ms56376_funcs.o and ms56376_funcs.h from the MS5637 directory.

When the program is run GPS data, BNO055 data and MS5637 data are then displayed in the terminal window and written to a log file on disk for a set period before the program terminates.

The combined example program demonstrates how a log file can be written as plain text or as kml points. The kml points file can be read into Google maps.
 
References
If you are new to the Raspberry Pi or just want a good reference book we recommend Exploring Raspberry Pi: Interfacing to the Real World with Embedded Linux by Derek Molloy. This book covers a very good range of topics including interfacing GPS receivers, accelerometers and other sensors to the Raspberry Pi. In addition there is a supporting website with a range of code for the examples in the book.

Home

Back

© The BlackBoxCameraTM Company Limited 2019