Skip to content

Latest commit

 

History

History
279 lines (146 loc) · 13.2 KB

File metadata and controls

279 lines (146 loc) · 13.2 KB

Bluetooth - BTHome v2 - People Counting (VL53L1X)

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

Overview

This project aims to implement a people-counting application using Silicon Laboratories development kits integrated with the BLE wireless stack and a VL53L1X distance sensor.

This example can be as the first step in developing other upgrade applications based on it. It will be upgraded as a part of the people tracking system in the building or the factory and so on soon. Integrated with BLE wireless technology, therefore the user can control and monitor this system so easily.

Gecko SDK version

Hardware Required

Connections Required

The I2C connection is made from the BGM220 Bluetooth Module Explorer Kit to the Distance Sensor Breakout board and the Micro OLED Breakout by using the Qwiic cable.

The hardware connection is shown in the image below:

hardware connection

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 hardware to My Products, click on it, and click on the EXAMPLE PROJECTS & DEMOS tab. Find the example project with the filter "people counting".

  2. Click Create button on the Bluetooth - People Counting (VL53L1X) with BThome v2 example. Example project creation dialog pops up -> click Create and Finish and Project should be generated. create_project

  3. Build and flash this example to the board.

Start with a "Bluetooth - SoC Empty" project

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

  2. Copy all attached files in inc and src folders into the project root folder (overwriting existing).

  3. Import the GATT configuration:

    • Open the .slcp file in the project.

    • Select the CONFIGURATION TOOLS tab and open the Bluetooth GATT Configurator.

    • Find the Import button and import the configuration bluetooth_people_counting/config/btconfig/gatt_configuration.btconf file.

    • Save the GATT configuration (ctrl-s).

  4. Open the .slcp file. Select the SOFTWARE COMPONENTS tab and install the software components:

    • [Services] → [IO Stream] → [IO Stream: USART] → default instance name: vcom

    • [Application] → [Utility] → [Log]

    • [Platform] → [Driver] → [Button] → [Simple Button] → default instance name: btn0

    • [Platform] → [Driver] → [LED] → [Simple LED] → default instance name: led0

    • [Third Party Hardware Drives] → [Sensors] → [VL53L1X - Distance Sensor Breakout (Sparkfun)]

    • [Third Party Hardware Drives] → [Display & LED] → [SSD1306 - Micro OLED Breakout (Sparkfun - I2C)]

    • [Third Party Hardware Drives] → [Services] → [GLIB - OLED Graphics Library]

    • [Third Party Hardware Drives] → [Services] → [BTHome v2]

  5. Build and flash the project to your device.

Note:

How It Works

GATT Database

Advertisement Packet Device name: People Counting

GATT Database

  • Device name: RFID Notify

  • [Service] People Counting

    • [Char] People Entered So Far UUID: cf88405b-e223-4976-82aa-78c6b305b0a8

      • [R] Get the number of people entering the room.

      • [W] Clear the number of people entering the room.

    • [Char] People Count UUID: 2b9837e1-5560-49e5-a8cf-2f3b0db0bd6b

      • [R] Get the number of people in the room.

      • [W] Clear the number of people in the room.

    • [Char] Min Distance: UUID: f2f7c459-e623-4970-ab36-d3a4651a694e

      • [R] Get minimum distance that is used by counting people algorithm (mm).

      • [W] Set minimum distance that is used by counting people algorithm (mm).

    • [Char] Max Distance: UUID: d0a946d7-a183-4cb7-a9cb-b9c879cdb6fa

      • [R] Get maximum distance that is used by counting people algorithm (mm).

      • [W] Set maximum distance that is used by counting people algorithm (mm).

    • [Char] Distance Threshold: UUID: 0192bd9d-cb4f-49cc-b3dc-2d7facc9edcd

      • [R] Get distance threshold that is used by counting people algorithm (mm).

      • [W] Set distance threshold that is used by counting people algorithm (mm).

    • [Char] Timing Budget: UUID: 01fb0e47-13c9-4369-88cc-07f58759a6a6

      • [R] Get timing budget that is used by counting people algorithm (ms).

      • [W] Set timing budget that is used by counting people algorithm (ms).

    • [Char] Notification Status: UUID: ca89196b-76e2-41a0-9e41-342f4a2ff6f1

      • [R] Get notification status.

      • [W] Enable & disable notification status.

    • [Char] Room capacity: UUID: c714d394-7e0d-4c6a-a864-1183046a244c

      • [R] Get room capacity.

      • [W] Set room capacity.

      • [N] Get notification of room status( full or empty).

People Counting Implementation

Application initialization

Application init

Sensor initialization

Sensor init

Sensor sampling

Sensor sampling

Application Workflows

  1. Initialize the peripherals, the Bluetooth stack

  2. Initialize and load the previous configurations from NVM memory.

  3. Wait for the VL53L1X sensor to be booted and initialize the VL53L1X sensor with the configurations from NVM3:

    • Distance mode: LONG

    • Timing budget: 33 ms

    • Region of interest SPADs: 8x16

  4. Start ranging for the VL53L1X sensor.

  5. Initialize the OLED display.

  6. Start a periodical timer every second. The timer callback will raise an external event to the BLE stack and the event handler will do:

    • Check if the ranging data is ready.

    • Get a new distance sample.

    • Calculate people counting algorithm with new distance sample.

    • Switch the Region of Interest (ROI) center to other zones (front or back)

  7. Start a periodical timer with 1000 milliseconds for each periodic period, The timer callback will raise an external event to the BLE stack. The event handler will display people counting data which was calculated by the people counting algorithm. It also sends the data to Home Assistant server.

  8. After the sl_bt_evt_system_boot_id event arrives, the application sets up the security manager to bond with an iOS or Android device. And then start advertising.

  9. Handle GATT events to help the user configures the counting algorithm and get the result from the algorithm calculation over the EFR Connect mobile application.

People Counting algorithm

The counting algorithm example relies on a list of states that have to occur in a certain order to detect if a person has crossed the specified area and in which direction this area has been crossed. These states are stored in a list and compared to two default lists of states that represent how the area is crossed in two different directions.

When no one is seen in either of the two zones, the list of states is reset. If we consider that a person detected in the front zone equals 2, and a person detected in the back zone equals 1, the algorithm adds these values and stores the result as soon as it changes.

Eventually, if the consecutive states in the list are 0, 1, 3, 2, 0 or 0, 2, 3, 1, 0 this means a person has been detected in one direction or the other, as described in the figure below. List of status values.

Counting Algorithm

Algorithm workflows

Algorithm workflows

Testing

OLED Display

Display the number of people standing in the detected areas and the second value represents the number of people who entered the room.

OLED display

Button

Press the button to clear the number of people who are standing in detected areas.

Room status notification

  • To receive the room's state (full or empty), the user needs to enable notification for the Room Capacity characteristic.

  • If the number of entered people is greater than the room capacity then the device will send a "room is full" notification to the client.

  • If the number of entered people is zero then the device will send a "room is empty" notification to the client.

Reset the counting value

  • To reset the number of people who entered the room, the user has to write 0 to the People Entered So Far characteristic.

  • To reset the number of people currently, the user has to write 0 to the People Count characteristic.

Connect to EFR Connect app

You can use a smartphone app, such as the EFR Connect application on your phone, to connect to the board. Please, follow some steps below:

  • Open the EFR Connect app.

  • Open the Bluetooth Browser.

  • Find the device advertising as People Counting.

  • Click on Connect button.

  • If the application shows the pairing request dialog, press Pair button to confirm authentication for the pairing process. After that, wait for the connection to be established and the GATT database to be loaded.

Note: The pairing process on Android and iOS devices is different. For more information, refer to Bluetooth security.

device_namae device_pairing device_characteristics

Connect to Home Assistant app

The BThome integration in Home Assistant will detect nearby BThome devices. Discovered devices will show up in the discovered section on the integrations page in the configuration panel.

ha1

Open the Home Assistant application on your smartphone. Click [Settings] → [Devices & Services] → [BTHome], and you will see a list of nearby devices, which are sending BTHome advertisements. Find the one named "BGM220P" and click the ADD ENTRY. Enter the BindKey then submit, add device to your home. Now you can see the Count data data show in the screen.

ha2

Console View

You can launch Console that's integrated into Simplicity Studio or use a third-party terminal tool like TeraTerm to receive the data from the USB. A screenshot of the console output is shown in the figure below.

console_log