Skip to content

Commit 5aab2b0

Browse files
author
brentru
committed
fixup files, add pico wiring for uart echo script!
1 parent 68e2091 commit 5aab2b0

File tree

3 files changed

+70
-71
lines changed

3 files changed

+70
-71
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
import board
2+
import neopixel
3+
4+
from adafruit_bluefruit_connect.packet import Packet
5+
from adafruit_bluefruit_connect.color_packet import ColorPacket
6+
7+
28
from adafruit_ble import BLERadio
39
from adafruit_ble.advertising.standard import ProvideServicesAdvertisement
410
from adafruit_ble.services.nordic import UARTService
11+
512
from adafruit_airlift.esp32 import ESP32
613

14+
715
# If you are using an AirLift FeatherWing or AirLift Bitsy Add-On,
8-
# use the pin settings below:
16+
# use the pin settings below.
17+
# If you are using an AirLift Breakout, check that these
18+
# choices match the wiring to your microcontroller board,
19+
# or change them as appropriate.
920
esp32 = ESP32(
1021
reset=board.D12,
1122
gpio0=board.D10,
@@ -15,33 +26,23 @@
1526
rx=board.RX,
1627
)
1728

18-
# If you are using an AirLift Breakout, comment out the DEFAULT lines
19-
# above and uncomment the lines below:
20-
# esp32 = ESP32(
21-
# reset=board.D12,
22-
# gpio0=board.D10,
23-
# busy=board.D11,
24-
# chip_select=board.D13,
25-
# tx=board.TX,
26-
# rx=board.RX,
27-
# )
28-
29-
3029
adapter = esp32.start_bluetooth()
3130

3231
ble = BLERadio(adapter)
33-
uart = UARTService()
34-
advertisement = ProvideServicesAdvertisement(uart)
32+
uart_service = UARTService()
33+
advertisement = ProvideServicesAdvertisement(uart_service)
34+
35+
pixels = neopixel.NeoPixel(board.NEOPIXEL, 10, brightness=0.1)
3536

3637
while True:
38+
# Advertise when not connected.
3739
ble.start_advertising(advertisement)
38-
print("waiting to connect")
3940
while not ble.connected:
4041
pass
41-
print("connected: trying to read input")
42+
4243
while ble.connected:
43-
# Returns b'' if nothing was read.
44-
one_byte = uart.read(1)
45-
if one_byte:
46-
print(one_byte)
47-
uart.write(one_byte)
44+
if uart_service.in_waiting:
45+
packet = Packet.from_stream(uart_service)
46+
if isinstance(packet, ColorPacket):
47+
print(packet.color)
48+
pixels.fill(packet.color)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import board
2+
from adafruit_ble import BLERadio
3+
from adafruit_ble.advertising.standard import ProvideServicesAdvertisement
4+
from adafruit_ble.services.nordic import UARTService
5+
from adafruit_airlift.esp32 import ESP32
6+
7+
# If you are using an AirLift FeatherWing or AirLift Bitsy Add-On,
8+
# use the pin settings below:
9+
esp32 = ESP32(
10+
reset=board.D12,
11+
gpio0=board.D10,
12+
busy=board.D11,
13+
chip_select=board.D13,
14+
tx=board.TX,
15+
rx=board.RX,
16+
)
17+
18+
# If you are using an AirLift Breakout, comment out the DEFAULT lines
19+
# above and uncomment the lines below:
20+
# esp32 = ESP32(
21+
# reset=board.GP16,
22+
# gpio0=board.GP9,
23+
# busy=board.GP14,
24+
# chip_select=board.GP13,
25+
# tx=board.GP0,
26+
# rx=board.GP1,
27+
# )
28+
29+
30+
adapter = esp32.start_bluetooth()
31+
32+
ble = BLERadio(adapter)
33+
uart = UARTService()
34+
advertisement = ProvideServicesAdvertisement(uart)
35+
36+
while True:
37+
ble.start_advertising(advertisement)
38+
print("waiting to connect")
39+
while not ble.connected:
40+
pass
41+
print("connected: trying to read input")
42+
while ble.connected:
43+
# Returns b'' if nothing was read.
44+
one_byte = uart.read(1)
45+
if one_byte:
46+
print(one_byte)
47+
uart.write(one_byte)

rp2040_ble_airlift/ble-fruitfruit-uart-echo-rp2040.py

-49
This file was deleted.

0 commit comments

Comments
 (0)