This project aims to implement a doorlock system using Silicon Labs development Kits and external sensors integrated with the BLE wireless stack.
More detailed information can be found in the section How it works.
This code example referred to the following code examples. More detailed information can be found here:
-
GSDK v4.4.0
NOTE: Tested boards for working with this example:
Board ID | Description |
---|---|
BRD2704A | SparkFun Thing Plus Matter - MGM240P - BRD2704A |
BRD2601B | EFR32xG24 Dev Kit - xG24-DK2601B |
BRD2703A | EFR32xG24 Explorer Kit - XG24-EK2703A |
BRD4108A | BG22 Bluetooth SoC Explorer Kit - BG22-EK4108A |
BRD4314A | BGM220 Bluetooth Module Explorer Kit - BGM220-EK4314A |
The hardware connection is shown in the image below:
The I2C connection is made from the Silicon Labs's Kit to the RFID board and the Micro OLED Breakout by using the qwiic cable.
Listed below are the port and pin mappings for working with this example.
-
Board: BRD2704A - SparkFun Thing Plus Matter - MGM240P
GPIO Pin Connection Pin function GPIOB PB00 GPIO input SCL PB03 I2C Clock SDA PB04 I2C Data -
Board: BRD2601B - EFR32xG24 Dev Kit- xG24
GPIO Pin Connection Pin function GPIOB PB02 GPIO input SCL PC04 I2C Clock SDA PC05 I2C Data -
Board: BRD2703A - EFR32xG24 Explorer Kit - XG24
GPIO Pin Connection Pin function GPIOB PB02 GPIO input SCL PC04 I2C Clock SDA PC05 I2C Data -
Board: BRD4108A - BG22 Bluetooth SoC Explorer Kit - BG22
GPIO Pin Connection Pin function GPIOB PC07 GPIO input SCL PD02 I2C Clock SDA PD03 I2C Data -
Board: BRD4314 Bluetooth Module Explorer Kit
GPIO Pin Connection Pin function GPIOB PB00 GPIO input SCL PD02 I2C Clock SDA PD03 I2C Data
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.
NOTE:
-
Make sure that the SDK extension is already installed and this repository is added to Preferences > Simplicity Studio > External Repos.
-
SDK Extension must be enabled for the project to install the required components.
-
From the Launcher Home, add your hardware to MyProducts, click on it, and click on the EXAMPLE PROJECTS & DEMOS tab. Find the example project with the filter "rfid".
-
Click the Create button on the Bluetooth - Door Lock RFID (ID-12LA) example. Example project creation dialog pops up -> click Create and Finish and Project should be generated.
or you can start with an empty example project as the following:
-
Create a "Bluetooth - SoC Empty" using Simplicity Studio v5. Use the default project settings.
-
Copy all attached files in inc and src folders into the project root folder (overwriting existing the app.c file).
-
Install the software components:
-
Open the .slcp file in the project.
-
Select the SOFTWARE COMPONENTS tab.
-
Install the following components:
- [Services] → [Sleep Timer]
- [Services] → [NVM3] → NVM3 Core
- [Services] → [NVM3] → NVM3 Default Instance
- [Services] → [IO Stream] → [IO Stream: USART] → default instance name: vcom
- [Application] → [Utility] → [Log]
- [Application] → [Utility] → [Assert]
- [Platform] → [Driver] → [I2C] → [I2CSPM] → instance name: qwiic. Configure this instance to suit your hardware.
- [Third Party Hardware Drivers] → [Display & LED] → [SSD1306 - Micro OLED Breakout (Sparkfun) - I2C]
- [Third Party Hardware Drivers] → [Service] → [GLIB - OLED Graphics Library]
- [Third Party Hardware Drivers] → [Wireless Connectivity] → [ID-12LA - RFID Reader (Sparkfun) - I2C]
-
-
Import the GATT configuration:
-
Open the .slcp file in the project.
-
Select the CONFIGURATION TOOLS tab and open the Bluetooth GATT Configurator.
-
Click on the Import button and import the attached gatt_configuration.btconf file.
-
Save the GATT configuration (ctrl-s).
-
-
Build and flash this example to the board.
NOTE:
- Do not forget to flash a bootloader to your board, see Bootloader for more information.
The application is based on the Bluetooth - SoC Empty example. Since the example already has the Bluetooth GATT server, advertising, and connection mechanisms, only minor changes are required.
The GATT changes were adding a new custom service (RFID Door Lock) which are 4 characteristics:
-
Mode:
-
[Readable] - Get mode value
-
[Writable] - Set operation mode (0 - normal, 1 - register, remove, 2 - show)
-
-
Remove Card:
- [Writable] - Provide card slot id to remove it from the registered cards.
-
Get card ID:
- [Readable] - Get selected card's ID
- [Writable] - Set selected card slot (default is 0).
-
Open Lock:
- [Writable] - Write 1 to open the lock.
-
Initialize the peripherals, the Bluetooth stack
-
Initialize the OLED display, show Silabs Logo on the screen
-
Initialize and load the NVM3 configurations
-
Wait for the sensor to be booted and initialize the sensor with the configurations from NVM3:
-
Initialize RFID
-
Initialize application
-
After the sl_bt_evt_system_boot_id event arrives, the application sets up the security manager to bond with an iOS/Android device. And then start advertising.
-
Handle GATT event to help users configure the Use EFR Connect Mobile Application and get the result from the algorithm calculation over the EFR32 connect mobile application
- Show LOCKED/UNLOCKED label
- LOCKED
- Show BLE connection status
- UNLOCKED
- RFID Card
- Show the used card's ID
- BLE
- Show CONNECTED label
- RFID Card
- Show CONFIG label
- Show the number of registered cards (max. 10)
- Show REMOVED label
- Show the number of registered cards (max. 10)
- Show ADDED label
- Show added/removed card's ID
- Has registered cards
- Show each slot data for 4 seconds
- Show slot index.
- Show card ID
- Show each slot data for 4 seconds
- Card slot is empty
- Show NO CARDS and "-" labels
Below are illustrations for each case
The Silicon Labs EFR Connect application utilizes the Bluetooth adapter on your phone/tablet to scan, connect and interact with BLE devices. To run this example, an iOS or Android smartphone with the installed EFR Connect application is required.
Open the EFR Connect application on your smartphone and allow the permission request when opened for the first time. Click [Develop] -> [Browser] and you will see a list of nearby devices which are sending Bluetooth advertisements. Find the one named People Counting and click the connect button on the right side. 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.
The parameters of this example application can be easily configured via BLE characteristics. Values for the characteristics are handled by the application as ASCII strings. Tap on the main service to see the available characteristics. Please refer GATT Configurator to choose the correct characteristic. Read
Push the read button to request the value of a characteristic. (See ASCII fields.) Write
For setting a parameter select a characteristic and tap on its write button. Type a new value in the ASCII field and push the Send button.