-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Silicon Labs CircuitPython Applications v1.3.0
- Loading branch information
1 parent
8e434d9
commit 8fef025
Showing
18 changed files
with
181 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# CircuitPython - Bluetooth - SoC - Blinky # | ||
|
||
![Type badge](https://img.shields.io/badge/dynamic/json?url=https://raw.githubusercontent.com/SiliconLabs/application_examples_ci/master/circuitpython/cp_bluetooth_blinky_common.json&label=Type&query=type&color=green) | ||
![Technology badge](https://img.shields.io/badge/dynamic/json?url=https://raw.githubusercontent.com/SiliconLabs/application_examples_ci/master/circuitpython/cp_bluetooth_blinky_common.json&label=Technology&query=technology&color=green) | ||
![License badge](https://img.shields.io/badge/dynamic/json?url=https://raw.githubusercontent.com/SiliconLabs/application_examples_ci/master/circuitpython/cp_bluetooth_blinky_common.json&label=License&query=license&color=green) | ||
## Overview ## | ||
|
||
This example application is the "Hello World" of Bluetooth Low Energy (BLE). It allows a BLE central device to control the LED on the mainboard and receive button press notifications. | ||
|
||
## Hardware Required ## | ||
|
||
- [EFR32xG24 Dev Kit](https://www.silabs.com/development-tools/wireless/efr32xg24-dev-kit?tab=overview) | ||
|
||
## Connections Required ## | ||
|
||
Power the EFR32xG24 Dev Kit with a micro-usb cable connected to a usb port on a laptop or an USB Charger | ||
|
||
## Prerequisites ## | ||
|
||
Getting started with [CircuitPython on EFR32 boards](../doc/running_circuitpython.md). | ||
|
||
## Setup ## | ||
|
||
To run the example you need to install **[Thonny](https://thonny.org/)** editor and then follow the steps below: | ||
|
||
1. Flash the corresponding CircuitPython binary for your board. You can visit [circuitpython.org/downloads](https://circuitpython.org/downloads?q=silabs) to download the binary. | ||
|
||
> **_NOTE:_** The examples in this repository require CircuitPython v8.2.0 or higher. | ||
2. Upload all the files and folders from the device_root folder to the CircuitPython device. The files and folders should be copied into the root of the file system on the target device. | ||
|
||
3. Run the scripts on the board. | ||
|
||
## How it Works ## | ||
|
||
### Getting started ### | ||
|
||
This example implements a simple custom GATT service with two characteristics. One characteristic controls the state of the LED (ON/OFF) via write operations from a GATT client, and the second characteristic sends notifications to subscribed clients when the button state changes (pressed or released). | ||
|
||
To test this demo, install EFR Connect for [Android](https://play.google.com/store/apps/details?id=com.siliconlabs.bledemo&hl=en&gl=US) or [iOS](https://apps.apple.com/us/app/efr-connect/id1030932759). Source code for the mobile app is available on [Github](https://github.com/SiliconLabs?q=efrconnect&type=&language=&sort=). | ||
|
||
After launching the app go to the demo view and select the Blinky demo. A pop-up will show all the devices around you that are running the SoC-Blinky firmware. Tap on the device to go into the demo view. | ||
|
||
![Demo view](docs/efr_connect1.jpg) ![Pop up](docs/efr_connect2.jpg) | ||
|
||
Tap the light on the mobile app to toggle the LED on the mainboard. When you press/release the button on the mainboard the state changes for the virtual button on the app as well. | ||
|
||
![Blinky all off](docs/efr_connect3.jpg) ![Blinky all on](docs/efr_connect4.jpg) | ||
|
||
### GATT database ### | ||
|
||
- [Service] Blinky Example | ||
- [Char] LED Control - led_control | ||
- [R] Get LED status | ||
- [W] Set LED on/off | ||
- [Char] Report Button - report_button | ||
- [R, N] Get button status | ||
|
||
## Output ## | ||
|
||
The animation below showcases the demo running on a EFR32xG24 Dev Kit (BRD2601B) with the mobile app running on an Android device. | ||
|
||
![Radio board power supply switch](docs/result.gif) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import digitalio | ||
import board | ||
from adafruit_ble import BLERadio | ||
from BlinkyApp import BlinkyApp | ||
from BlinkyService import BlinkyService | ||
|
||
DEVICE_NAME = 'Blinky Example' | ||
|
||
|
||
# application init | ||
app = BlinkyApp( | ||
BlinkyService(), | ||
BLERadio(), | ||
board.LEDG, | ||
board.BTN0 | ||
) | ||
|
||
# config the advertisement | ||
app.configure_advertisement(DEVICE_NAME) | ||
|
||
# start looping the main function | ||
while True: | ||
app.main_function() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from adafruit_ble.advertising.standard import Advertisement | ||
from adafruit_ble import BLERadio | ||
import digitalio | ||
import board | ||
|
||
|
||
class BlinkyApp(): | ||
def __init__(self, | ||
service: BlinkyService, | ||
ble: BLERadio, | ||
led_pin: microcontroller.Pin, | ||
button_pin: microcontroller.Pin) -> None: | ||
self.service = service | ||
self.adv = Advertisement() | ||
self.ble = ble | ||
self.button = digitalio.DigitalInOut(button_pin) | ||
self.button.direction = digitalio.Direction.INPUT | ||
self.led = digitalio.DigitalInOut(led_pin) | ||
self.led.direction = digitalio.Direction.OUTPUT | ||
|
||
|
||
def configure_advertisement(self, | ||
device_name, | ||
connectable = True) -> None: | ||
self.adv.short_name = device_name | ||
self.adv.connectable = connectable | ||
|
||
def main_function(self): | ||
if not self.ble.connected and not self.ble.advertising: | ||
print('>>> Start advertising') | ||
self.ble.start_advertising(self.adv) | ||
|
||
if self.ble.connected: | ||
if self.ble.advertising: | ||
self.ble.stop_advertising() | ||
print('>>> Connected, stop advertising') | ||
|
||
if self.service.report_button != int(self.button.value): | ||
self.service.report_button = int(self.button.value) | ||
print("Button: {0}".format(int(self.button.value))) | ||
|
||
if self.service.led_control == 0 and self.led.value == False: | ||
self.led.value = True | ||
print("LED on."); | ||
elif self.service.led_control == 1 and self.led.value == True: | ||
self.led.value = False | ||
print("LED off."); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from adafruit_ble.services import Service | ||
from adafruit_ble.uuid import VendorUUID | ||
from adafruit_ble.attributes import Attribute | ||
from adafruit_ble.characteristics import Characteristic | ||
from adafruit_ble.characteristics.int import Uint8Characteristic | ||
|
||
class BlinkyService(Service): | ||
uuid = VendorUUID('de8a5aac-a99b-c315-0c80-60d4cbb51224') | ||
|
||
led_control = Uint8Characteristic( | ||
uuid = VendorUUID('5b026510-4088-c297-46d8-be6c736a087a'), | ||
properties = (Characteristic.READ | Characteristic.WRITE), | ||
write_perm = Attribute.NO_ACCESS, | ||
) | ||
|
||
report_button = Uint8Characteristic( | ||
uuid = VendorUUID('61a885a4-41c3-60d0-9a53-6d652a70d29c'), | ||
properties = (Characteristic.READ | Characteristic.NOTIFY), | ||
write_perm = Attribute.NO_ACCESS, | ||
) | ||
|
||
|
||
def __init__(self, service=None): | ||
super().__init__(service=service) | ||
self.connectable = True |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters