Skip to content

Commit fbb1cdd

Browse files
committed
adding BLE airlift example for template page
1 parent b5f8086 commit fbb1cdd

File tree

1 file changed

+74
-0
lines changed
  • CircuitPython_Templates/airlift_ble_example

1 file changed

+74
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# SPDX-FileCopyrightText: 2020 Dan Halbert, written for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: Unlicense
4+
5+
# pylint: disable=unused-import
6+
import board
7+
import busio
8+
from digitalio import DigitalInOut
9+
from adafruit_ble import BLERadio
10+
from adafruit_ble.advertising.standard import ProvideServicesAdvertisement
11+
from adafruit_ble.services.nordic import UARTService
12+
from adafruit_esp32spi import adafruit_esp32spi
13+
from adafruit_airlift.esp32 import ESP32
14+
15+
# If you are using a Metro M4 Airlift Lite, PyPortal,
16+
# or MatrixPortal, you can use the default pin settings.
17+
# Leave this DEFAULT line uncommented.
18+
# If you are using a board with pre-defined ESP32 Pins:
19+
esp32 = ESP32()
20+
21+
# If you are using a Metro M7 **OR**
22+
# if you are using CircuitPython 6.0.0 or earlier,
23+
# on PyPortal and PyPortal Titano only, use the pin settings
24+
# below. Comment out the DEFAULT line above and uncomment
25+
# the line below. For CircuitPython 6.1.0, the pin names
26+
# have changed for these boards, and the DEFAULT line
27+
# above is correct.
28+
# esp32 = ESP32(tx=board.TX, rx=board.RX)
29+
30+
# If you are using an AirLift FeatherWing or AirLift Bitsy Add-On,
31+
# use the pin settings below. Comment out the DEFAULT line above
32+
# and uncomment the lines below.
33+
# If you are using an AirLift Breakout, check that these
34+
# choices match the wiring to your microcontroller board,
35+
# or change them as appropriate.
36+
# esp32 = ESP32(
37+
# reset=board.D12,
38+
# gpio0=board.D10,
39+
# busy=board.D11,
40+
# chip_select=board.D13,
41+
# tx=board.TX,
42+
# rx=board.RX,
43+
# )
44+
45+
# If you are using an AirLift Shield,
46+
# use the pin settings below. Comment out the DEFAULT line above
47+
# and uncomment the lines below.
48+
# esp32 = ESP32(
49+
# reset=board.D5,
50+
# gpio0=board.D6,
51+
# busy=board.D7,
52+
# chip_select=board.D10,
53+
# tx=board.TX,
54+
# rx=board.RX,
55+
# )
56+
57+
adapter = esp32.start_bluetooth()
58+
59+
ble = BLERadio(adapter)
60+
uart = UARTService()
61+
advertisement = ProvideServicesAdvertisement(uart)
62+
63+
while True:
64+
ble.start_advertising(advertisement)
65+
print("waiting to connect")
66+
while not ble.connected:
67+
pass
68+
print("connected: trying to read input")
69+
while ble.connected:
70+
# Returns b'' if nothing was read.
71+
one_byte = uart.read(1)
72+
if one_byte:
73+
print(one_byte)
74+
uart.write(one_byte)

0 commit comments

Comments
 (0)