0

Bluetooth Detection using Circuit Python
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Bluetooth Detection using Circuit Python

by brobson on Tue May 18, 2021 6:41 pm

Hi all,

I am attempting to connect to my Adafruit Circuit Playground Bluefruit via the Bluefruit Connect app on my Android phone. My app doesn't detect the board. I have followed all of the troubleshooting instructions I could find, including resetting the app, phone, clearing bluetooth cache and still can't detect it. I have tried a different board and still have the same issue. My board is running Circuit Python.

Am I missing something?

Warm regards
Ben

brobson
 
Posts: 6
Joined: Tue May 18, 2021 5:49 pm

Re: Bluetooth Detection using Circuit Python

by adafruit_support_mike on Tue May 18, 2021 10:40 pm

Can you detect the CP-BLE from any other device? There are some known issues with Android BLE.

adafruit_support_mike
 
Posts: 63134
Joined: Thu Feb 11, 2010 2:51 pm

Re: Bluetooth Detection using Circuit Python

by GWeier99 on Sat May 29, 2021 3:19 pm

Hi brobson. What sketch are you using when you try to connect to the Android? Try sketch blueart_multi. As long as the Andriod is finding other BLE devices it should find yours. You can tell if your board is advertising if the green LED next to the cable port is on and stable and the red LED light on the other side of the cable port is blinking.

GWeier99
 
Posts: 4
Joined: Sun Nov 01, 2020 3:14 pm

Re: Bluetooth Detection using Circuit Python

by brobson on Mon Jun 07, 2021 5:29 pm

Hi team,
Thanks for the replies. Sorry for such a delayed response to your suggestions and questions. I will try the suggested sketch and update this post.
Warm regards
Ben

brobson
 
Posts: 6
Joined: Tue May 18, 2021 5:49 pm

Re: Bluetooth Detection using Circuit Python

by brobson on Mon Jun 07, 2021 6:08 pm

I have tested it further and can confirm that it isn't detected by either Android or iOS devices.
In addition, I can't find a example code blueart_multi in then library of examples downloaded. I have tried the following code and the red light is not flashing as you mentioned.

# SPDX-FileCopyrightText: 2020 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT

# CircuitPython NeoPixel Color Picker Example

import board
import neopixel

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()
uart_service = UARTService()
advertisement = ProvideServicesAdvertisement(uart_service)

pixels = neopixel.NeoPixel(board.NEOPIXEL, 10, brightness=0.1)

while True:
# Advertise when not connected.
ble.start_advertising(advertisement)
while not ble.connected:
pass
ble.stop_advertising()

while ble.connected:
if THIS WAS A BANNED WORD BY THE FORUM FOR SOME REASON: //uart_service in_waiting
packet = Packet.from_stream(uart_service)
if isinstance(packet, ColorPacket):
print(packet.color)
pixels.fill(packet.color)


Any ideas?

brobson
 
Posts: 6
Joined: Tue May 18, 2021 5:49 pm

Re: Bluetooth Detection using Circuit Python

by adafruit_support_mike on Wed Jun 09, 2021 5:48 pm

When did you get the board, and has it ever made a BLE connection to a central device?

adafruit_support_mike
 
Posts: 63134
Joined: Thu Feb 11, 2010 2:51 pm

Re: Bluetooth Detection using Circuit Python

by brobson on Sat Jun 12, 2021 7:09 am

We bought the device a few months ago and I'm not sure what you mean by a central device. I have never been able to detect it from any Bluetooth device. All other input and outputs such as light sensor or buzzer have worked fine.

brobson
 
Posts: 6
Joined: Tue May 18, 2021 5:49 pm

Re: Bluetooth Detection using Circuit Python

by adafruit_support_mike on Mon Jun 14, 2021 5:13 pm

Bluetooth has two categories of devices: ‘central’ and ‘peripheral’.

Central devices initiate and control all data connections. Peripherals emit messages called ‘advertising’ to let central devices know they exist, but otherwise wait for a central to tell them what to do.

If you’ve had the board for a few months, it’s past our 30-day return/replace period. I can’t authorize any refund or replacement.

adafruit_support_mike
 
Posts: 63134
Joined: Thu Feb 11, 2010 2:51 pm

Re: Bluetooth Detection using Circuit Python

by brobson on Wed Jun 16, 2021 1:32 am

Hi there, I haven't asked for a replacement :).

I would like to resolve whatever the issue is with the existing boards. I have 16 Circuit Playground Bluefruit devices that are being used for a design project idea https://learn.adafruit.com/bluefruit-lu ... h/overview

I need to find a way to get the Bluetooth working so my students can control their LEDs separate to the capacitive touch input.

I have the following libraries of code on my CIRCUITPY:
adafruit_ble
adafruit_ble_adafruit
adafruit_bluefruit_connect
adafruit_bus_device
adafruit_circuitplayground
adafruit_fancyled
adafruit_gizmo
adafruit_hid
adafruit_lis3dh.mpy
adafruit_thermistor.mpy
neopixel.mpy

Perhaps I am missing libraries of code that would make it broadcast itself?

The following is the code I have saved as code.py

Code: Select all | TOGGLE FULL SIZE
""" FancyLED Palette and Color Picker Control with BlueFruit App
    Code by Phil Burgess, Dan Halbert & Erin St Blaine for Adafruit Industries
"""
import board
import neopixel
import touchio
import time
import adafruit_fancyled.adafruit_fancyled as fancy
from adafruit_bluefruit_connect.packet import Packet
from adafruit_bluefruit_connect.button_packet import ButtonPacket
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

# adjust brightness
#cp.pixels.brightness = 0.3

NUM_LEDS = 24             # change to reflect your total number of ring LEDs
RING_PIN = board.A1       # change to reflect your wiring
CPX_PIN = board.D8        # CPX Neopixels live on pin D8

touch_A2 = touchio.TouchIn(board.A2)
touch_A3 = touchio.TouchIn(board.A3)
touch_A4 = touchio.TouchIn(board.A4)
touch_A5 = touchio.TouchIn(board.A5)
touch_A6 = touchio.TouchIn(board.A6)
touch_TX = touchio.TouchIn(board.TX)

# Palettes can have any number of elements in various formats
# check https://learn.adafruit.com/fancyled-library-for-circuitpython/colors
# for more info
# Declare a 6-element RGB rainbow palette
PALETTE_RAINBOW = [fancy.CRGB(1.0, 0.0, 0.0),  # Red
                   fancy.CRGB(0.5, 0.3, 0.0),  # Orange
                   fancy.CRGB(0.5, 0.5, 0.0),  # Yellow
                   fancy.CRGB(0.3, 0.7, 0.0),  # Yellow Green
                   fancy.CRGB(0.0, 1.0, 0.0),  # Green
                   fancy.CRGB(0.0, 0.7, 0.3),  # Teal
                   fancy.CRGB(0.0, 0.5, 0.5),  # Cyan
                   fancy.CRGB(0.0, 0.3, 0.7),  # Blue
                   fancy.CRGB(0.0, 0.0, 1.0),  # Blue
                   fancy.CRGB(0.5, 0.0, 0.5),  # Magenta
                   fancy.CRGB(0.7, 0.0, 0.3)]  # Purple

# Reading Lamp mode - Warm Yellow
PALETTE_BRIGHT = [fancy.CRGB(255, 183, 55)]

# Black Only palette for "off" mode
PALETTE_DARK = [fancy.CRGB(0, 0, 0)]

# Declare a FIRE palette
PALETTE_FIRE = [fancy.CRGB(160, 30, 0),  # Reds and Yellows
                fancy.CRGB(27, 65, 0),
                fancy.CRGB(0, 0, 0),
                fancy.CRGB(224, 122, 0),
                fancy.CRGB(0, 0, 0),
                fancy.CRGB(250, 80, 0),
                fancy.CRGB(0, 0, 0),
                fancy.CRGB(0, 0, 0),
                fancy.CRGB(200, 40, 0)]

# Declare a NeoPixel object on NEOPIXEL_PIN with NUM_LEDS pixels,
# no auto-write.
# Set brightness to max because we'll be using FancyLED's brightness control.
ring = neopixel.NeoPixel(RING_PIN, NUM_LEDS, brightness=1.0, auto_write=False)
cpx = neopixel.NeoPixel(CPX_PIN, NUM_LEDS, brightness=1.0, auto_write=False)

offset = 0  # Positional offset into color palette to get it to 'spin'
offset_increment = 6
OFFSET_MAX = 1000000

# Setup BLE
ble = BLERadio()
uart = UARTService()
advertisement = ProvideServicesAdvertisement(uart)


def set_palette(palette):
    for i in range(NUM_LEDS):
        # Load each pixel's color from the palette using an offset, run it
        # through the gamma function, pack RGB value and assign to pixel.
        color = fancy.palette_lookup(palette, (offset + i) / NUM_LEDS)
        color = fancy.gamma_adjust(color, brightness=1.0)
        ring[i] = color.pack()
    ring.show()
    time.sleep(0.5)

    for i in range(NUM_LEDS):
        # Load each pixel's color from the palette using an offset, run it
        # through the gamma function, pack RGB value and assign to pixel.
        color = fancy.palette_lookup(palette, (offset + i) / NUM_LEDS)
        color = fancy.gamma_adjust(color, brightness=1.0)
        cpx[i] = color.pack()
    cpx.show()

# set initial palette to run on startup
palette_choice = PALETTE_FIRE

# True if cycling a palette
cycling = True

# Are we already advertising?
advertising = False


while True:

    if cycling:
        set_palette(palette_choice)
        offset = (offset + offset_increment) % OFFSET_MAX

    if not ble.connected and not advertising:
        ble.start_advertising(advertisement)
        advertising = True

    # Are we connected via Bluetooth now?
    if ble.connected:
        # Once we're connected, we're not advertising any more.
        advertising = False
        # Have we started to receive a packet?
        if uart.in_waiting:
            packet = Packet.from_stream(uart)
            if isinstance(packet, ColorPacket):
                cycling = False
                # Set all the pixels to one color and stay there.
                ring.fill(packet.color)
                cpx.fill(packet.color)
                ring.show()
                cpx.show()
            elif isinstance(packet, ButtonPacket):
                cycling = True
                if packet.pressed:
                    if packet.button == ButtonPacket.BUTTON_1:
                        palette_choice = PALETTE_DARK
                    elif packet.button == ButtonPacket.BUTTON_2:
                        palette_choice = PALETTE_BRIGHT
                    elif packet.button == ButtonPacket.BUTTON_3:
                        palette_choice = PALETTE_FIRE
                        offset_increment = 6
                    elif packet.button == ButtonPacket.BUTTON_4:
                        palette_choice = PALETTE_RAINBOW
                        offset_increment = 1

                # change the speed of the animation by incrementing offset
                    elif packet.button == ButtonPacket.UP:
                        offset_increment += 1
                    elif packet.button == ButtonPacket.DOWN:
                        offset_increment -= 1

    # Whether or not we're connected via Bluetooth,
    # we also want to handle touch inputs.
    if touch_A2.value:
        cycling = True
        palette_choice = PALETTE_DARK
    elif touch_A3.value:
        cycling = True
        palette_choice = PALETTE_BRIGHT
    elif touch_A4.value:
        cycling = True
        palette_choice = PALETTE_FIRE
        offset_increment = 6
    elif touch_A5.value:
        cycling = True
        palette_choice = PALETTE_RAINBOW
        offset_increment = 1
    # Also check for touch speed control
    if touch_A6.value:
        offset_increment += 1
    if touch_TX.value:
        offset_increment -= 1


Any advice?

brobson
 
Posts: 6
Joined: Tue May 18, 2021 5:49 pm

Re: Bluetooth Detection using Circuit Python

by brobson on Thu Jun 24, 2021 6:16 pm

Hi team, any chance you have a solution after the previous posts information?

brobson
 
Posts: 6
Joined: Tue May 18, 2021 5:49 pm

Re: Bluetooth Detection using Circuit Python

by adafruit_support_mike on Sun Jun 27, 2021 12:25 am

In that case I have to repeat my previous question: have you ever gotten any of the boards to connect to any central device?

Some versions of Android have problems with BLE. Boards that don't show up on one phone are able to connect normally to different phones, or to desktop computers with BLE capability.

adafruit_support_mike
 
Posts: 63134
Joined: Thu Feb 11, 2010 2:51 pm

Please be positive and constructive with your questions and comments.