Skip to content

Latest commit

 

History

History

bluetooth_container_level_detection

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

Bluetooth - Container Level Detection (VL53L1X)

Type badge Technology badge License badge SDK badge Build badge Flash badge RAM badge

Overview

This project proposes the development of an application that uses the Silabs xG24 Explorer kits, Sparkfun Distance sensor breakout and Adafruit IS31FL3741 components to monitor the levels of two containers and display the information graphically. The application will use BLE for wireless communication between the devices

The following picture shows the overview of the application:

con overview

Sensor:

The sensor device measures the distance between the distance sensor and the content of the container. The sensor device calculates the average distance and advertises it via BLE

Client:

The client device scans the BLE devices and reads the measured distance values from the sensor device advertisement package. The client device displays the container level on the display using a vertical bar.

The client device can display levels of up to 4 container level sensors. The lowest and highest level values can be configured for each container slot.

Once measurement data is not updated for a slot within a period, the client device shows NO DATA on the display for that.

Gecko SDK Suite version

Hardware Required

Sensor:

Client:

NOTE: Tested boards for working with this example:

Board ID Description
BRD2703A EFR32xG24 Explorer Kit - XG24-EK2703A
BRD4108A BG22 Bluetooth SoC Explorer Kit - BG22-EK4108A
BRD4314A BGM220 Bluetooth Module Explorer Kit - BGM220-EK4314A
BRD2601B EFR32xG24 Dev Kit Board - xG24 -EK2601B
BRD2704A Sparkfun Thing Plus MGM240P - EK2704A

Connections Required

The hardware connection is shown in the images below:

con hardware

Sensor:

The Distance Sparkfun sensor can be easily connected to the EFR32 xG24 Explorer Kit via Qwiic connection. con hardware

Client:

The Adafruit RGB LED Matrix board can be easily connected to the EFR32 xG24 Explorer Kit by using a Qwiic cable. con hardware

Setup

To test this application, you can either create a project based on an example project or start with a "Bluetooth - SoC Empty" project based on your hardware.

Create a project based on an example project

  1. From the Launcher Home, add your product name to My Products, click on it, and click on the EXAMPLE PROJECTS & DEMOS tab. Find the example project with the filter "container".

  2. Click Create button on both Bluetooth - Container Level Dectection Sensor and Bluetooth - Container Level Dectection Client examples. Example project creation dialog pops up -> click Create and Finish and Project should be generated.

    board

  3. Build and flash these examples to the boards.

Start with a "Bluetooth - SoC Empty" project

  1. Create a Bluetooth - SoC Empty project for your hardware using Simplicity Studio 5.

  2. copy all the .h and .c files to the following directory of the project root folder (overwriting the existing files).

  3. Install the software components:

    • Open the .slcp file in the project.

    • Select the SOFTWARE COMPONENTS tab.

    • Install the following components for sensor device:

      • [Services] → [Sleep Timer]
      • [Bluetooth] → [NVM] → NVM Support
      • [Services] → [NVM3] → NVM3 Core
      • [Services] → [NVM3] → NVM3 Default Instance
      • [Services] → [IO Stream] → [IO Stream: USART] → vcom
      • [Application] → [Utility] → Log
      • [Platform] → [Driver]→ [I2C] → [I2CSPM] → qwiic
      • [Third Party Hardware Drivers] → [Sensors] → VL53L1X - Distance Sensor Breakout (Sparkfun)
      • [Bluetooth] → [OTA] → [In-Place OTA DFU] → uninstall
      • [Platform] → [Bootloader Application Interface] → uninstall.
    • Install the following components for client device:

      • [Services] → [Sleep Timer]
      • [Bluetooth] → [NVM] → NVM Support
      • [Services] → [NVM3] → NVM3 Core
      • [Services] → [NVM3] → NVM3 Default Instance
      • [Services] → [IO Stream] → [IO Stream: USART] → vcom
      • [Application] → [Utility] → Log
      • [Platform] → [Driver] → [Button] → [Simple Button] → btn0
      • [Platform] → [Driver]→ [I2C] → [I2CSPM] → qwiic
      • [Third Party Hardware Drivers] → [Display & LED] → IS31FL3741 - 13x9 PWM RGB LED Matrix (Adafruit) - I2C
      • [Third Party Hardware Drivers] → [Services] → GLIB - OLED Graphics Library
      • [Bluetooth] → [OTA] → [In-Place OTA DFU] → uninstall
      • [Platform] → [Bootloader Application Interface] → uninstall.
  4. Import the GATT configuration:

    • Open the .slcp file in the project again.
    • Select the CONFIGURATION TOOLS tab and open the "Bluetooth GATT Configurator".
    • Find the Import button and import the gatt_configuration.btconf file.
      • Sensor: config/btconf/sensor/gatt_configuration.btconf
      • Client: config/btconf/client/gatt_configuration.btconf
    • Save the GATT configuration (ctrl-s).
  5. Build and flash these projects to the boards.

Note:

How It Works

This application has 2 roles: Client and Sensor.

Normally, Sensor devices send the advertisement packets frequently in the BLE network. The client device which reads the information of the container from sensor devices, will show the level of containers in the led matrix. The client provides 2 operational modes:

  • Config mode: When the BTN0 is pressed during the initialization sequence. the client boots into the configuration mode. The Client advertises itself to connect to another device such as a smartphone. In that, user can configure the configuration of the container like ID, highest and lowest level.

  • Normal mode: When the BTN0 is released during the initialization phase, This device starts scanning the advertisement packet of the sensor devices which have the name started with 'CON_LEV_S_'. It analyzes this packet and gets the information of the container. After that, it will calculate to corresponding value and update the led matrix which shows the status of containers.

Sensor Overview

Application Overview

Sensor Implementation

Application initialization:

Application init

On Timer callback:

This handler is called when the timer expires in every configured process period time.

Application callback

Advertisement Packet:

The AdvData field in the advertisement packet is as the table below:

DeviceName SampleCounter Distance
CON_LEV_S_< MAC unique 2 byte > 4 byte 4 byte
  • SampleCounter: the device increases the counter value for each new measurement
  • Distance: Calculate the level of the container
  • The device is not connectable. It sends manufacturer-specific advertisement packets.

Client

Client Overview

Application Overview

Client GATT Database

GATT Database:

  • [Service] Container Level Detection
    • [Char] Select Container to configure
      • [R] Get selected container slot
      • [W] Set selected container slot (0-3)
    • [Char] Container Slot Configuration
      • [R] Get the selected container slot configuration
      • [W] Set the selected container slot configuration (2 bytes - the MAC last 2 bytes e.g.: AABB)
    • [Char] Container Lowest Level
      • [R] Get the lowest level value for the selected container
      • [W] Set the lowest level value for the selected container (40-4000 is the valid range)
    • [Char] Container Highest Level
      • [R] Get the highest level value for the selected container
      • [W] Set the highest level value for the selected container (40-4000 is the valid range)

Client Implementation

Application initialization:

Application init

Runtime - Configuration Mode:

Config mode

Runtime - Normal Mode:

Client events:

Client logic

Sleep timer expires Client logic

BLE External Event Handler:

Container level device check event handler check and update the new container level data.

app_sleep_timer_main_callback is a function invoked periodically by the sleep timer service with the configured period. Client logic

Container level detection event handler retrieves and processes the measured distance data. Client logic

Display:

If the Client is in the normal mode, the LED matrix will show the level of the container to the corresponding slot which expresses the status of the container.

Display

Testing

Sensor:

You can use a smartphone app such as the EFR Connect app, to see the advertising packet from the Sender.

  • Open the EFR Connect app.

  • Open the Bluetooth Browser.

  • Find the device advertising as CON_LEV_S_<>.

  • Click on the instance of CON_LEV_S_<>. Now, you should see the counter and the container level value on the Manufacturer Specific Data row. Please have a look at the red highlighted area below in the result pictures.

    Display

  • After flashing code to the sensor board, an output from a serial terminal as shown below

    Sensor Log

Client:

  • Upon reset, the application will display the Silicon Labs logo on the LED matrix screen for a few seconds.

  • After the firmware is configured, the device starts in normal mode. In this state, it starts scanning advertising devices.

  • Open your terminal emulator and connect to your client device over its serial port. Set baudrate to 115200. In the console log, the information of the sensor device will be shown.

    Client log

  • Note: Button PB0 should be pressed during startup (power-on or reset) to run the client in Configuration Mode. The terminal will display the information like below

    user configuration