def run(cycles_per_second=30, device_name=None): ble = BLERadio() if device_name: ble.name = device_name uart = UARTService() advertisement = ProvideServicesAdvertisement(uart) expected_seconds_per_tick = 1 / cycles_per_second while True: print("waiting for bluetooth connection") ble.start_advertising(advertisement) while not ble.connected: _tick(expected_seconds_per_tick=expected_seconds_per_tick) print("connected to bluetooth") smartphone._set_uart(uart=uart) while ble.connected: _tick(expected_seconds_per_tick=expected_seconds_per_tick) print("lost bluetooth connection") smartphone._unset_uart()
def main(): # initialize I2C i2c = board.I2C() # initialize sensors bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C(i2c) sht31d = adafruit_sht31d.SHT31D(i2c) # initialize BLE ble = BLERadio() # create custom advertisement object advertisement = IOTGAdvertisement() # set device name ble.name = "IOTG1" # set initial value # will use only first 5 chars of name advertisement.md_field = ble.name[:5] + "0000" # BLRE advertising interval in seconds BLE_ADV_INT = 0.2 # start BLE advertising ble.start_advertising(advertisement, interval=BLE_ADV_INT) # main loop while True: # print values - this will be available on serial print("Temperature: {:.1f} C".format(bmp280.temperature)) print("Humidity: {:.1f} %".format(sht31d.relative_humidity)) # get sensor data T = int(bmp280.temperature) H = int(sht31d.relative_humidity) # stop advertsing ble.stop_advertising() # update advertisement data advertisement.md_field = ble.name[:5] + chr(T) + chr(H) + "00" # start advertising ble.start_advertising(advertisement, interval=BLE_ADV_INT) # sleep for 2 seconds time.sleep(2)
def post_init(self, ble_name='KMK Keyboard', **kwargs): self.devices = {} hid = HIDService() advertisement = ProvideServicesAdvertisement(hid) advertisement.appearance = BLE_APPEARANCE_HID_KEYBOARD ble = BLERadio() ble.name = ble_name # ble.tx_power = 2 if not ble.connected: ble.start_advertising(advertisement) while not ble.connected: pass for device in hid.devices: us = device.usage up = device.usage_page if up == HIDUsagePage.CONSUMER and us == HIDUsage.CONSUMER: self.devices[HIDReportTypes.CONSUMER] = device continue if up == HIDUsagePage.KEYBOARD and us == HIDUsage.KEYBOARD: self.devices[HIDReportTypes.KEYBOARD] = device continue if up == HIDUsagePage.MOUSE and us == HIDUsage.MOUSE: self.devices[HIDReportTypes.MOUSE] = device continue if up == HIDUsagePage.SYSCONTROL and us == HIDUsage.SYSCONTROL: self.devices[HIDReportTypes.SYSCONTROL] = device continue
last_seen_update_ns = time.monotonic_ns() # Reintroduce screen_update_ns to limit call to change color screen_update_ns = 250 * 1000 * 1000 ### If no advertisement received for 'hide_time_ns' that RGB LED turn BLUE and will be forgotten hide_time_ns = 20 * 1000 * 1000 * 1000 ### If no advertisement is received for 'stale_time_ns' that RGB LED is flushed for reuse stale_time_ns = 200 * 1000 * 1000 * 1000 scan_time_s = 10 from adafruit_airlift.esp32 import ESP32 esp32 = ESP32(tx=board.TX, rx=board.RX) adapter = esp32.start_bluetooth() ble = BLERadio(adapter) ble.name = "PyPortal" ###ble = BLERadio() ###ble.name = "CPB" ### An array of timestamp and advertisement by key (addr) last_ad_by_key = {} MINI_BLUE = (0, 0, 1) SHADE_BLUE = [(0, 0, 63), (0, 0, 31), (0, 0, 15), (0, 0, 7), (0, 0, 3)] TIME_BLUE = [50 * 1000 * 1000 * 1000, 80 * 1000 * 1000 * 1000, 110 * 1000 * 1000 * 1000, 140 * 1000 * 1000 * 1000, 170 * 1000 * 1000 * 1000] RSSI_DEFAULT_COLOR = (63, 0, 0) RSSI_COLOR = [(0, 31, 0), (15, 31, 0), (15, 15, 0), (31, 15, 0), (31, 0, 0), (63, 0, 0)] RSSI_VALUE = [-80, -75, -70, -65, -60, -55]
from board import A0, RED_LED from analogio import AnalogIn from digitalio import DigitalInOut, Direction last_x = 0 last_y = 0 led = AnalogIn(A0) # Initialize blue LED light detector solenoid = DigitalInOut(RED_LED) # Initialize solenoid solenoid.direction = Direction.OUTPUT solenoid.value = False ble = BLERadio() ble.name = 'infrapale' # uart_server = UARTServer() uart = UARTService() advertisement = ProvideServicesAdvertisement(uart) def bytes_to_ble_addr(byte_arr): b = list(byte_arr) if len(b) == 6: hex_6 = ''.join('{:02X}:'.format(a) for a in reversed(b))[:-1] else: hex_6 = '' return hex_6 print(bytes_to_ble_addr(ble.address_bytes)) sleep(5) while True:
from adafruit_ble_adafruit.adafruit_service import AdafruitServerAdvertisement from adafruit_ble_adafruit.quaternion_service import QuaternionService from adafruit_bno08x import BNO08X i2c = board.I2C() bno = BNO08X(i2c) quat_svc = QuaternionService() quat_svc.measurement_period = 50 quat_last_read = 0 ble = BLERadio() # The Web Bluetooth dashboard identifies known boards by their # advertised name, not by advertising manufacturer data. ble.name = "Adafruit Hillcrest Laboratories BNO08x Breakout" adv = AdafruitServerAdvertisement() adv.pid = 0x8088 while True: # Advertise when not connected. ble.start_advertising(adv) while not ble.connected: pass ble.stop_advertising() while ble.connected: now_msecs = time.monotonic_ns() // 1000000 # pylint: disable=no-member if now_msecs - quat_last_read >= quat_svc.measurement_period:
说明:编程实现手机控制彩灯。 ''' #导入相关模块 import board, neopixel from adafruit_ble import BLERadio from adafruit_ble.advertising.standard import ProvideServicesAdvertisement from adafruit_ble.services.nordic import UARTService from adafruit_bluefruit_connect.packet import Packet from adafruit_bluefruit_connect.color_packet import ColorPacket #构建蓝牙对象 ble = BLERadio() #定义广播名称 ble.name = '01Studio' #构建UART服务 uart_server = UARTService() #广播添加UART服务 advertisement = ProvideServicesAdvertisement(uart_server) #定义neopixel引脚,默认使用板载neopixel pixels = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.1) while True: # 广播 ble.start_advertising(advertisement) #等待连接
###strip = neopixel.NeoPixel(board.NEOPIXEL, rows, brightness=BRIGHTNESS) ### CPB strip = neopixel.NeoPixel(board.P2, rows, brightness=BRIGHTNESS) ### CLUE with SnowPi RGB strip.fill((0, 0, 31)) time.sleep(0.5) strip.fill((0, 0, 0)) ### If no advertisement received for 'hide_time_ns' that RGB LED turn BLUE and will be forgotten hide_time_ns = 20 * 1000 * 1000 * 1000 ### If no advertisement is received for 'stale_time_ns' that RGB LED is flushed for reuse stale_time_ns = 200 * 1000 * 1000 * 1000 scan_time_s = 10 ble = BLERadio() ble.name = "CPB" ### An array of timestamp and advertisement by key (addr) last_ad_by_key = {} MINI_BLUE = (0, 0, 1) SHADE_BLUE = [(0, 0, 63), (0, 0, 31), (0, 0, 15), (0, 0, 7), (0, 0, 3)] TIME_BLUE = [50 * 1000 * 1000 * 1000, 80 * 1000 * 1000 * 1000, 110 * 1000 * 1000 * 1000, 140 * 1000 * 1000 * 1000, 170 * 1000 * 1000 * 1000] RSSI_DEFAULT_COLOR = (63, 0, 0) RSSI_COLOR = [(0, 31, 0), (15, 31, 0), (15, 15, 0), (31, 15, 0), (31, 0, 0), (63, 0, 0)] RSSI_VALUE = [-80, -75, -70, -65, -60, -55] ### Decide color based on rssi and age_ns def gimme_color(age_ns, rssi):
IMAGE_DIR + "/rps-sprites-ind4.bmp", ble_color=JG_RX_COL) ### Transmit maximum times in seconds JG_MSG_TIME_S = 20 FIRST_MSG_TIME_S = 12 STD_MSG_TIME_S = 4 LAST_ACK_TIME_S = 1.5 ### Intro screen with audio rps_display.introductionScreen() ### Enable the Bluetooth LE radio and set player's name (from secrets.py) ble = BLERadio() if ble_name is not None: ble.name = ble_name game_no = 1 round_no = 1 wins = 0 losses = 0 draws = 0 voids = 0 ### TOTAL_ROUNDS = 5 TOTAL_ROUNDS = 3 CRYPTO_ALGO = "chacha20" KEY_SIZE = 8 ### in bytes KEY_ENLARGE = 256 // KEY_SIZE // 8
# from games import CenterGame from adafruit_ble import BLERadio, Advertisement from adafruit_ble.advertising.standard import ProvideServicesAdvertisement from adafruit_ble.uuid import VendorUUID from adafruit_ble.characteristics.stream import StreamIn from adafruit_ble.services import Service # from adafruit_display_text.label import Label # import terminalio import time from draw import Drawer # import displayio ble = BLERadio() ble.name = "CLUE BLE" class CustomUART(Service): uuid = VendorUUID("8ba86973-935c-447c-91ad-bdcbad575f31") _server_rx = StreamIn( uuid=VendorUUID("8ba86974-935c-447c-91ad-bdcbad575f31"), timeout=1.0, buffer_size=64, ) def __init__(self, service=None): # just steal the uuid code from MIDISerivce super().__init__(service=service)
MIC_NUM_SAMPLES = 256 mic_svc = MicrophoneService() mic_svc.number_of_channels = 1 mic_svc.measurement_period = 100 mic_last_update = 0 mic_samples = ulab.zeros(MIC_NUM_SAMPLES, dtype=ulab.uint16) temp_svc = TemperatureService() temp_svc.measurement_period = 100 temp_last_update = 0 ble = BLERadio() # The Web Bluetooth dashboard identifies known boards by their # advertised name, not by advertising manufacturer data. ble.name = "PhysBryk" # The Bluefruit Playground app looks in the manufacturer data # in the advertisement. That data uses the USB PID as a unique ID. # Feather Bluefruit Sense USB PID: # This board is not yet support on the app. # Arduino: 0x8087, CircuitPython: 0x8088 adv = AdafruitServerAdvertisement() adv.pid = 0x8088 while True: # Advertise when not connected. ble.start_advertising(adv) while not ble.connected: pass ble.stop_advertising()
if (time.monotonic_ns() // 1000000) - last_blink > period: last_blink = time.monotonic_ns() // 1000000 last_on = last_blink led.value = False if (time.monotonic_ns() // 1000000) - last_on > blink_time: led.value = True serv_env_sense = EnvironmentalSensingService() serv_env_sense.measurement_period = 10000 # 10s last_update = 0 ble = BLERadio() # The Web Bluetooth dashboard identifies known boards by their # advertised name, not by advertising manufacturer data. ble.name = "SI7021_01" si7021 = adafruit_si7021.SI7021(i2c) # The Bluefruit Playground app looks in the manufacturer data # in the advertisement. That data uses the USB PID as a unique ID. # Adafruit CLUE USB PID: # Arduino: 0x8071, CircuitPython: 0x8072, app supports either adv = SolicitServicesAdvertisement() adv.complete_name = "EnvSensing" adv.solicited_services.append(serv_env_sense) #adv.pid = 0x1802 last_t = 0 last_h = 0
def main(): DEBUG = True BOARD = True #flag indicating whether attached to a board. try: import board except NotImplementedError: # no board attached so mock sensors, services etc import mock as mk print('No valid board. Using mock sensors and services') BOARD = False # sensors import adafruit_lsm6ds.lsm6ds33 # motion import adafruit_lis3mdl # magnetometer import adafruit_apds9960.apds9960 # EMR import time dummy_sensor = DummySensor() if BOARD: # valid board present use real sensors import analogio battery = analogio.AnalogIn(board.VOLTAGE_MONITOR) motion = adafruit_lsm6ds.lsm6ds33.LSM6DS33(board.I2C()) magnet = adafruit_lis3mdl.LIS3MDL(board.I2C()) emr = adafruit_apds9960.apds9960.APDS9960(board.I2C()) # emr.enable_proximity = True emr.enable_color = True # Create and initialize the available services. ble = BLERadio() battery_svc = BatteryService() motion_svc = MotionService() magnet_svc = MagnetService() emr_svc = EMRService() dummy_svc = DummyService() adv = PhysBrykServerAdvertisement() else: #use mock sensors and services # Accelerometer and gyro motion = mk.Sensor() magnet = mk.Sensor() emr = mk.Sensor() battery = mk.Sensor() ble = mk.Service() battery_svc = mk.Service() motion_svc = mk.Service() magnet_svc = mk.Service() emr_svc = mk.Service() dummy_svc = mk.Service() adv = mk.Service() ble.name = "PhysBryk_Alpha" last_update = 0 while True: # Advertise when not connected. ble.start_advertising(adv) if DEBUG: print('Connecting...') while not ble.connected: pass ble.stop_advertising() if DEBUG: print('Connected!') while ble.connected: now_msecs = time.monotonic_ns() // 1000000 # pylint: disable=no-member if now_msecs - last_update >= MEASUREMENT_PERIOD: battery_svc.voltage = battery_svc.get_voltage(battery) motion_svc.acceleration = motion.acceleration # m/s/s motion_svc.gyro = motion.gyro # rad/s magnet_svc.magnetic = magnet.magnetic # microT emr_svc.intensity = emr_svc.get_lux(emr.color_data) emr_svc.spectrum = emr.color_data emr_svc.proximity = emr.proximity dummy_svc.value = 42 dummy_sensor.update() last_update = now_msecs if DEBUG: print(f'motion acceleration: {motion_svc.acceleration}') print(f'motion gyro: {motion_svc.gyro}') print(f'magnet magnet: {magnet_svc.magnetic}') print(f'emr intensity: {emr_svc.intensity}') print(f'emr spectrum: {emr_svc.spectrum}') print(f'emr proximity: {emr_svc.proximity}') print(f'battery: {battery_svc.voltage}') print(f'dummy: {dummy_svc.value}') if not BOARD: for s in mk.sensors: s.update()
strip.fill((0, 0, 0)) ### If no advertisement received for 'hide_time_ns' that RGB LED turn BLUE and will be forgotten hide_time_ns = 20 * 1000 * 1000 * 1000 ### If no advertisement is received for 'stale_time_ns' that RGB LED is flushed for reuse stale_time_ns = 200 * 1000 * 1000 * 1000 scan_time_s = 10 last_seen_update_ns = time.monotonic_ns() # Reintroduce screen_update_ns to limit call to change color screen_update_ns = 1 * 1000 * 1000 * 1000 ### Time before not blinking for a phone that does not advertise anymore noblink_time_ns = 10 * 1000 * 1000 * 1000 ble = BLERadio() ble.name = "ItsyBitsy" ### An array of timestamp and advertisement by key (addr) last_ad_by_key = {} def delete_very_old(rows_n, ad_by_key): """Delete older key above the number of rows_n""" ### If we have more entry than space if len(ad_by_key)>rows_n: ### Sort by last seen to identify earliest that should be cleaned sorted_data = sorted(ad_by_key.items(), key=lambda item: (item[1][1])) ### Number of entries to remove to_delete = len(ad_by_key)-rows_n ### Iterate on the first entry and delete them from the list received for key, value in sorted_data[:to_delete]:
from adafruit_ble.services.nordic import UARTService from adafruit_bluefruit_connect.packet import Packet # Only the packet classes that are imported will be known to Packet. from adafruit_bluefruit_connect.button_packet import ButtonPacket from adafruit_bluefruit_connect.color_packet import ColorPacket import adafruit_fancyled.adafruit_fancyled as fancy import adafruit_fancyled.fastled_helpers as helper from audiopwmio import PWMAudioOut as AudioOut from audiocore import WaveFile import board import time ble = BLERadio() uart_service = UARTService() ble.name = "BabyYoda" advertisement = ProvideServicesAdvertisement(uart_service) advertisement.complete_name = "BabyYoda" RainbowStripeColors = [ 0xFF0000, 0x000000, 0xAB5500, 0x000000, 0xABAB00, 0x000000, 0x00FF00, 0x000000, 0x00AB55, 0x000000, 0x0000FF, 0x000000, 0x5500AB, 0x000000, 0xAB0055, 0x000000 ] color = (0, 0, 255) RED = (255, 0, 0) ORANGE = (255, 50, 0) YELLOW = (255, 165, 0) GREEN = (0, 255, 0)
if (time.monotonic_ns() // 1000000) - last_blink > period: last_blink = time.monotonic_ns() // 1000000 last_on = last_blink led.value = False if (time.monotonic_ns() // 1000000) - last_on > blink_time: led.value = True serv_env_sense = EnvironmentalSensingService() serv_env_sense.measurement_period = 10000 # 10s last_update = 0 ble = BLERadio() # The Web Bluetooth dashboard identifies known boards by their # advertised name, not by advertising manufacturer data. ble.name = "BME680_02" bme680 = adafruit_bme680.Adafruit_BME680_I2C(i2c, address=0x76) # The Bluefruit Playground app looks in the manufacturer data # in the advertisement. That data uses the USB PID as a unique ID. # Adafruit CLUE USB PID: # Arduino: 0x8071, CircuitPython: 0x8072, app supports either adv = SolicitServicesAdvertisement() adv.complete_name = "EnvSensing" adv.solicited_services.append(serv_env_sense) #adv.pid = 0x1802 last_t = 0 last_h = 0 last_p = 0
# Only the packet classes that are imported will be known to Packet. from adafruit_bluefruit_connect.packet import Packet from adafruit_bluefruit_connect.accelerometer_packet import AccelerometerPacket from adafruit_bluefruit_connect.button_packet import ButtonPacket from adafruit_bluefruit_connect.color_packet import ColorPacket from adafruit_bluefruit_connect.gyro_packet import GyroPacket from adafruit_bluefruit_connect.location_packet import LocationPacket from adafruit_bluefruit_connect.magnetometer_packet import MagnetometerPacket from adafruit_bluefruit_connect.quaternion_packet import QuaternionPacket # Print out the color data from ColorPackets. # To use, start this program, and start the Adafruit Bluefruit LE Connect app. # Connect, and then select colors on the Controller->Color Picker screen. ble = BLERadio() ble.name = "Bike Lights" print(f"Bluetooth name: {ble.name}") uart_server = UARTService() advertisement = ProvideServicesAdvertisement(uart_server) # advertisement.complete_name = "Blue Lights" # print(f"Advertisement complete name {advertisement.complete_name}") # print(f"Advertisement short name {advertisement.short_name}") led = DigitalInOut(board.BLUE_LED) led.direction = Direction.OUTPUT # rgb_led_g = DigitalInOut(board.RGB_LED_GREEN) # rgb_led_g.direction = Direction.OUTPUT # rgb_led_r = DigitalInOut(board.RGB_LED_RED) # rgb_led_r.direction = Direction.OUTPUT
# funny import board import time import math from adafruit_ble import BLERadio from adafruit_ble.advertising.standard import ProvideServicesAdvertisement from adafruit_ble.services.nordic import UARTService from adafruit_bluefruit_connect.packet import Packet from adafruit_bluefruit_connect.button_packet import ButtonPacket from adafruit_circuitplayground import cp ble = BLERadio() ble.name = "JuggleCounter" uart = UARTService() advertisement = ProvideServicesAdvertisement(uart) while True: ble.start_advertising(advertisement) while not ble.connected: pass # Now we're connected while ble.connected: if uart.in_waiting: recvd = uart.read(32) if recvd is not None:
button_svc.set_pressed(cp.switch, cp.button_a, cp.button_b) light_svc = LightSensorService() light_svc.measurement_period = 100 light_last_update = 0 temp_svc = TemperatureService() temp_svc.measurement_period = 100 temp_last_update = 0 tone_svc = ToneService() ble = BLERadio() # The Web Bluetooth dashboard identifies known boards by their # advertised name, not by advertising manufacturer data. ble.name = "CPlay" # The Bluefruit Playground app looks in the manufacturer data # in the advertisement. That data uses the USB PID as a unique ID. # Adafruit Circuit Playground Bluefruit USB PID: # Arduino: 0x8045, CircuitPython: 0x8046, app supports either adv = AdafruitServerAdvertisement() adv.pid = 0x8046 while True: # Advertise when not connected. ble.start_advertising(adv) while not ble.connected: pass ble.stop_advertising()
pixel = neopixel.NeoPixel(pixel_pin, num_pixels, brightness=0.1, auto_write=False) # setup for haptic motor driver i2c = busio.I2C(board.SCL, board.SDA) drv = adafruit_drv2605.DRV2605(i2c) # onboard blue LED blue_led = DigitalInOut(board.BLUE_LED) blue_led.direction = Direction.OUTPUT # setup for BLE ble = BLERadio() ble.name = "CoDi" if ble.connected: for c in ble.connections: c.disconnect() advertisement = ProvideServicesAdvertisement() # add device info service and UART service for BLE to advertise device_info_service = DeviceInfoService(manufacturer="CoDi Co.") uart_service = UARTService() advertisement.services.append(device_info_service) advertisement.services.append(uart_service) # function for haptic motor vibration # num: # of times to vibrate
import board import digitalio import busio import adafruit_lis3dh import pulseio import math from adafruit_ble import BLERadio from adafruit_ble.advertising.standard import ProvideServicesAdvertisement from adafruit_ble.services.nordic import UARTService # Defining a new bluetooth low energy service ble = BLERadio() # Setting the advertisement name to Park Med ble.name = "Park Med" #defining a new UART protocol #UART is a bluetooth protocol that allows the transmission of short messages uart_service = UARTService() #bluetooth stream message global streamMessage = None #advertising the bluetooth device with uart_service advertisement = ProvideServicesAdvertisement(uart_service) #small red LED led = digitalio.DigitalInOut(board.D13)
# common configuration SERVICE_NAME = "My UART" # 8 chars max # setup UART uart = busio.UART(board.TX, board.RX) # setup bluetooth from adafruit_bluefruit_connect.packet import Packet from adafruit_bluefruit_connect.color_packet import ColorPacket from adafruit_ble import BLERadio from adafruit_ble.advertising.standard import ProvideServicesAdvertisement from adafruit_ble.services.nordic import UARTService ble = BLERadio() ble.name = "UART With BLE" uart_service = UARTService() advertisement = ProvideServicesAdvertisement(uart_service) advertisement.short_name = SERVICE_NAME # advertisement.complete_name = "UART BLE" # no more than 8 to not go into extended adv ? was_connected = False while True: # Advertise BLE when not connected. if not ble.connected: was_connected = False if not ble.advertising: print(f'Start advertising as "{SERVICE_NAME}"') ble.start_advertising(advertisement, interval=0.5, timeout=5)
if (time.monotonic_ns() // 1000000) - last_blink > period: last_blink = time.monotonic_ns() // 1000000 last_on = last_blink led.value = False if (time.monotonic_ns() // 1000000) - last_on > blink_time: led.value = True serv_env_sense = EnvironmentalSensingService() serv_env_sense.measurement_period = 10000 # 10s last_update = 0 ble = BLERadio() # The Web Bluetooth dashboard identifies known boards by their # advertised name, not by advertising manufacturer data. ble.name = "bme280_02" bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c) # The Bluefruit Playground app looks in the manufacturer data # in the advertisement. That data uses the USB PID as a unique ID. # Adafruit CLUE USB PID: # Arduino: 0x8071, CircuitPython: 0x8072, app supports either adv = SolicitServicesAdvertisement() adv.complete_name = "EnvSensing" adv.solicited_services.append(serv_env_sense) #adv.pid = 0x1802 last_t = 0 last_h = 0 last_p = 0
mic_svc = MicrophoneService() mic_svc.number_of_channels = 1 mic_svc.measurement_period = 100 mic_last_update = 0 mic_samples = ulab.zeros(MIC_NUM_SAMPLES, dtype=ulab.uint16) temp_svc = TemperatureService() temp_svc.measurement_period = 100 temp_last_update = 0 tone_svc = ToneService() ble = BLERadio() # The Web Bluetooth dashboard identifies known boards by their # advertised name, not by advertising manufacturer data. ble.name = "CLUE" # The Bluefruit Playground app looks in the manufacturer data # in the advertisement. That data uses the USB PID as a unique ID. # Adafruit CLUE USB PID: # Arduino: 0x8071, CircuitPython: 0x8072, app supports either adv = AdafruitServerAdvertisement() adv.pid = 0x8072 while True: # Advertise when not connected. ble.start_advertising(adv) while not ble.connected: pass ble.stop_advertising()
# Send 256 16-bit samples at a time. MIC_NUM_SAMPLES = 256 mic_svc = MicrophoneService() mic_svc.number_of_channels = 1 mic_svc.measurement_period = 100 mic_last_update = 0 mic_samples = ulab.zeros(MIC_NUM_SAMPLES, dtype=ulab.uint16) temp_svc = TemperatureService() temp_svc.measurement_period = 100 temp_last_update = 0 ble = BLERadio() # The Web Bluetooth dashboard identifies known boards by their # advertised name, not by advertising manufacturer data. ble.name = "Sense" # The Bluefruit Playground app looks in the manufacturer data # in the advertisement. That data uses the USB PID as a unique ID. # Feather Bluefruit Sense USB PID: # This board is not yet support on the app. # Arduino: 0x8087, CircuitPython: 0x8088 adv = AdafruitServerAdvertisement() adv.pid = 0x8088 while True: # Advertise when not connected. ble.start_advertising(adv) while not ble.connected: pass ble.stop_advertising()
# CircuitPython recieve a color via BLE # adapted from https://learn.adafruit.com/adafruit-circuit-playground-bluefruit/playground-color-picker # Philip van Allen import board import analogio import neopixel from adafruit_ble import BLERadio from adafruit_ble.advertising.standard import ProvideServicesAdvertisement from adafruit_ble.services.nordic import UARTService from adafruit_bluefruit_connect.packet import Packet from adafruit_bluefruit_connect.color_packet import ColorPacket ble = BLERadio() ble.name = "yourUniqueName" uart_server = UARTService() advertisement = ProvideServicesAdvertisement(uart_server) pixels = neopixel.NeoPixel(board.NEOPIXEL, 10, brightness=0.1) light = analogio.AnalogIn(board.LIGHT) while True: # Advertise when not connected. ble.start_advertising(advertisement) while not ble.connected: pass ble.stop_advertising() while ble.connected: packet = Packet.from_stream(uart_server) if isinstance(packet, ColorPacket):