Using the Accelerometer of the WSTK Expansion Board

Description

Introduction

EFR32BGXX devices are capable of running many different types of external sensors. This example shows how to use an accelerometer found in the WSTK expansion board. Communicating between the sensor and the radio board is done via SPI. Accelerometer data is sent over UART and Bluetooth notifications. Because not all the EFR32BGXX devices are pin-to-pin compatible, this example may need some modifications to work with your radio board. The example has been created for the BGM121 but it can be ported to other devices easily.

Implementation

The software has the following tasks:

Setting up

This code example requires the following hardware:

To try the attached example, following the steps below:

  1. Create a new SoC - Empty project for your device.

  2. Import the attached gatt.xml file into the GATT configurator. The imported GATT database will include a custom Accelerometer Service (with random 128bit UUID) containing 3 custom characteristics.

Accelerometer Characteristics

  1. Press Save and then Generate in the GATT Configurator.

  2. Enable printing to UART by changing DEBUG_LEVEL to 1 in app.h.

  3. Disable sleep by setting DISABLE_SLEEP to 1 in app.h.

    EM2 sleep mode causes the UART connection to not work properly and to avoid that we disable sleep mode by setting the sleep flag to zero via this macro.

  4. Replace existing app.c with the one attached here.

  5. Build and flash your project.

Usage

  1. Attach the expansion board to your WSTK and reset it.

  2. Open a terminal program (such as TeraTerm) and connect to the virtual COM port (JLink CDC UART).

  3. You should see the values measured on the accelerometers. Rotate the board, to see the changes:

    Accelerometer values on serial port

  4. Open Blue Gecko app on your smart phone.

  5. Connect to the device named Accelero.

  6. Find the very last service (Unknown service) in the GATT database and open it.

  7. Open any of the characteristics and tap Notify to enable receiving notifications.

  8. You should see the values changing.

    Reading accelerometer value in Blue Gecko App

    Note: the value is displayed as unsigned here so you have to convert it to a signed integer to get a sensible value.

Source