Skip to content

Commit

Permalink
Silicon Labs CircuitPython Applications v1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
silabs-DanielN authored Oct 31, 2023
1 parent 8e434d9 commit 8fef025
Show file tree
Hide file tree
Showing 18 changed files with 181 additions and 21 deletions.
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

# Silicon Labs CircuitPython Applications #

[![Version Badge](https://img.shields.io/badge/-v1.2.1-green)](https://github.com/SiliconLabs/circuitpython_applications/releases)
[![Version Badge](https://img.shields.io/badge/-v1.3.0-green)](https://github.com/SiliconLabs/circuitpython_applications/releases)
[![CircuitPython](https://img.shields.io/badge/CircuitPython-v8.2.0+-green)](https://circuitpython.org/downloads?q=silabs)
![License badge](https://img.shields.io/badge/License-Zlib-green)

Expand All @@ -24,14 +24,16 @@ All examples in this repository are considered to be EXPERIMENTAL QUALITY, which

| No | Example name | Link to example |
|:--:|:-------------|:---------------:|
| 1 | CircuitPython - Bluetooth - Distance Monitor (VL53L1X) | [Click Here](./cp_bluetooth_distance_monitor)|
| 2 | CircuitPython - Bluetooth - Environmental Sensing (CCS811/BME280) | [Click Here](./cp_bluetooth_environmental_sensing) |
| 3 | CircuitPython - Bluetooth - Neopixel Humidity Gauge (SHTC3) | [Click Here](./cp_bluetooth_neopixel_humidity_gauge) |
| 4 | CircuitPython - Bluetooth - Light Detector (AS7265x) | [Click Here](./cp_bluetooth_light_detector) |
| 5 | CircuitPython - Non-Wireless Display Demo (IS31FL3741) | [Click Here](./cp_non_wireless_display_demo) |
| 6 | CircuitPython - RGB Display Drawing (ILI9341) | [Click Here](./cp_rgb_display_drawing_ili9341) |
| 7 | CircuitPython - Temperature and Humidity Monitor with LED Matrix Display (SI2071/IS31FL3741) | [Click Here](./cp_temperature_and_humidty_monitor) |
| 8 | CircuitPython - xG24 Dev Kit Sensors (ILI9341) | [Click Here](./cp_xg24_dev_kit_sensors) |
| 1 | CircuitPython - Bluetooth - SoC - Blinky | [Click Here](./cp_bluetooth_blinky) |
| 2 | CircuitPython - Bluetooth - Distance Monitor (VL53L1X) | [Click Here](./cp_bluetooth_distance_monitor)|
| 3 | CircuitPython - Bluetooth - Environmental Sensing (CCS811/BME280) | [Click Here](./cp_bluetooth_environmental_sensing) |
| 4 | CircuitPython - Bluetooth - Neopixel Humidity Gauge (SHTC3) | [Click Here](./cp_bluetooth_neopixel_humidity_gauge) |
| 5 | CircuitPython - Bluetooth - Light Detector (AS7265x) | [Click Here](./cp_bluetooth_light_detector) |
| 6 | CircuitPython - Non-Wireless Display Demo (IS31FL3741) | [Click Here](./cp_non_wireless_display_demo) |
| 7 | CircuitPython - RGB Display Drawing (ILI9341) | [Click Here](./cp_rgb_display_drawing_ili9341) |
| 8 | CircuitPython - Temperature and Humidity Monitor with LED Matrix Display (SI2071/IS31FL3741) | [Click Here](./cp_temperature_and_humidty_monitor) |
| 9 | CircuitPython - xG24 Dev Kit Sensors (ILI9341) | [Click Here](./cp_xg24_dev_kit_sensors) |



## Get CircuitPython firmware ##
Expand Down
63 changes: 63 additions & 0 deletions cp_bluetooth_blinky/README.md
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)
23 changes: 23 additions & 0 deletions cp_bluetooth_blinky/device_root/code.py
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()
47 changes: 47 additions & 0 deletions cp_bluetooth_blinky/device_root/lib/BlinkyApp.py
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.");
25 changes: 25 additions & 0 deletions cp_bluetooth_blinky/device_root/lib/BlinkyService.py
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
Binary file added cp_bluetooth_blinky/docs/efr_connect1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added cp_bluetooth_blinky/docs/efr_connect2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added cp_bluetooth_blinky/docs/efr_connect3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added cp_bluetooth_blinky/docs/efr_connect4.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added cp_bluetooth_blinky/docs/result.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions cp_bluetooth_distance_monitor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Getting started with [CircuitPython on EFR32 boards](../doc/running_circuitpytho

## Setup ##

To run the example you need to install **Thonny** editor and then follow the steps below:
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.

Expand Down Expand Up @@ -81,4 +81,4 @@ To run the example you need to install **Thonny** editor and then follow the ste

Run the **code.py** file, monitor the OLED, and try to place your hand beyond the sensor you will see the result below.

![result](docs/result.GIF)
![result](docs/result.GIF)
2 changes: 1 addition & 1 deletion cp_bluetooth_environmental_sensing/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Getting started with [CircuitPython on EFR32 boards](../doc/running_circuitpytho

## Setup ##

To run the example you need to install **Thonny** editor and then follow the steps below:
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.

Expand Down
4 changes: 2 additions & 2 deletions cp_bluetooth_light_detector/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Getting started with [CircuitPython on EFR32 boards](../doc/running_circuitpytho

## Setup ##

To run the example you need to install **Thonny** editor and then follow the steps below:
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.

Expand Down Expand Up @@ -130,4 +130,4 @@ Sensor Shell

![sensor_result](docs/sensor_result.png)

From the log and picture, you can see that value of the violet channel is the highest so the brightness of the violet LEDs group is also the highest, the red channel has the lowest value so the red LEDs group also has the lowest brightness, similar to other channels.
From the log and picture, you can see that value of the violet channel is the highest so the brightness of the violet LEDs group is also the highest, the red channel has the lowest value so the red LEDs group also has the lowest brightness, similar to other channels.
2 changes: 1 addition & 1 deletion cp_bluetooth_neopixel_humidity_gauge/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ The gathered humidity data is displayed on the connected NeoPixel Ring.

## Setup ##

To run the example you need to install **Thonny** editor and then follow the steps below:
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.

Expand Down
2 changes: 1 addition & 1 deletion cp_non_wireless_display_demo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Getting started with [CircuitPython on EFR32 boards](../doc/running_circuitpytho

## Setup ##

To run the example you need to install **Thonny** editor and then follow the steps below:
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.

Expand Down
4 changes: 2 additions & 2 deletions cp_rgb_display_drawing_ili9341/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Getting started with [CircuitPython on EFR32 boards](../doc/running_circuitpytho

## Setup ##

To run the example you need to install **Thonny** editor and then follow the steps below:
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.

Expand Down Expand Up @@ -81,4 +81,4 @@ Run the **code.py** file.
- You can start to draw or pick color by tab the color you want in color pallete and the present pen color will show in small rectangle at the top left of screen.
- Or you can clear all the screen by tab the Silabs logo.

![result](docs/result.gif)
![result](docs/result.gif)
2 changes: 1 addition & 1 deletion cp_temperature_and_humidty_monitor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Getting started with [CircuitPython on EFR32 boards](../doc/running_circuitpytho

## Setup ##

To run the example you need to install **Thonny** editor and then follow the steps below:
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.

Expand Down
4 changes: 2 additions & 2 deletions cp_xg24_dev_kit_sensors/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Getting started with [CircuitPython on EFR32 boards](../doc/running_circuitpytho

## Setup ##

To run the example you need to install **Thonny** editor and then follow the steps below:
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.

Expand Down Expand Up @@ -77,4 +77,4 @@ After you powered the devices, the boot screen is visible for 5 seconds. Then th

You can run the code.py file or press the Reset button. On the display, you will see the result below:

![demo](docs/demo.gif)
![demo](docs/demo.gif)

0 comments on commit 8fef025

Please sign in to comment.