1

I'm trying to set up bluetooth with the pico w with the c/c++ sdk for it to communicate wirelessly with my laptop.

I'm using btstack's and rasberry pi's example of spp_streamer.c. Also shown here.

The code I've added:

main.c:

#include "pico/cyw43_arch.h"
#include "pico/stdlib.h"
#include "btstack_run_loop.h"

int btstack_main(int argc, const char * argv[]);

int main() { stdio_init_all();

// initialize CYW43 driver
if (cyw43_arch_init()) {
    printf("cyw43_arch_init() failed.\n");
    return -1;
}

// run the app
btstack_main(0, NULL);
btstack_run_loop_execute();

}

CMakeLists.txt:

# Set minimum required version of CMake
cmake_minimum_required(VERSION 3.12)

Include build functions from Pico SDK

include($ENV{PICO_SDK_PATH}/external/pico_sdk_import.cmake)

Set name of project (as PROJECT_NAME) and C/C standards

project(btest C CXX ASM) set(CMAKE_C_STANDARD 11) set(CMAKE_CXX_STANDARD 17) set(PICO_BOARD pico_w)

Creates a pico-sdk subdirectory in our project for the libraries

pico_sdk_init()

Tell CMake where to find the executable source file

add_executable(${PROJECT_NAME} main.c spp_streamer.c )

Create map/bin/hex/uf2 files

pico_add_extra_outputs(${PROJECT_NAME})

Link to pico_stdlib (gpio, time, etc. functions)

target_link_libraries(${PROJECT_NAME} pico_stdlib pico_btstack_ble pico_btstack_classic pico_btstack_cyw43 pico_cyw43_arch_none )

target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_LIST_DIR} # For btstack config )

Enable usb output, disable uart output

pico_enable_stdio_usb(${PROJECT_NAME} 1) pico_enable_stdio_uart(${PROJECT_NAME} 0)

I've also added btstack_config.h as shown in the standalone example by Raspberry pi.

Compiling worked. Then after copying the .uf2 file to the Pico, on my laptop in the Bluetooth settings, the Pico appeared but wouldn't pair when clicked on:

pico not pairing

Also when trying to connect using python:

Traceback (most recent call last):
  File "C:\Users\Gring\Desktop\bt.py", line 11, in <module>
    sock.connect((bt_mac, port))
  File "C:\Users\Gring\AppData\Local\Programs\Python\Python310\lib\site-packages\bluetooth\msbt.py", line 96, in connect
    bt.connect (self._sockfd, addr, port)
OSError: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

I've also tried spp_counter.c and got the same error.

0 Answers0