Contents

Let's create a Pico SDK based Bluetooth Classic SPP example with the Raspberry Pi Pico W in VS Code

   Feb 15, 2023     3 min read

Bluetooth Classic SPP example with the Raspberry Pi Pico W

In this post I will talk about, how to create a Pico SDK based Bluetooth Classic SPP example with the Raspberry Pi Pico W in VS Code.

Introduction

Pico SDK v1.5.0 includes Bluetooth support for the Raspberry Pi Pico W, including both Bluetooth Low Energy (BLE) and Bluetooth Classic. They also released many examples. I thought it would be better if I gave a simple example for anyone who wants to use Bluetooth Classic SPP.

Bluetooth Serial Port Profile(SPP) emulates serial ports over Bluetooth. You can send or receive data from your Raspberry Pi Pico W to your Android phone, PC, etc. over Bluetooth.

Thank you for considering supporting my work!

Compilation

  1. Clone the repo as shown below, or download latest release.

     git clone https://github.com/MrGreensWorkshop/RasPiPicoSDK_BT_Classic_SPP.git
    
  2. Please make sure you are using the Pico SDK v1.5.0 or later.
  3. Open the project in VS Code because it adds SDK to the environment string. (Check the .vscode/settings.json file for details.)
    • Or add PICO_SDK_PATH to your environment string.
  4. Compile using build.sh

     chmod +x build.sh
     ./build.sh
    
    • Or run
     cmake -B build -S . && make -j4 -C build
    

Running

  1. Get the binary or compile the project.
    • You can compile the project and get the binary as explained above.
    • Or you can use precompiled binary files from the latest release, download the “binary.zip” and unzip.
  2. Put the Raspberry Pi Pico into bootloader mode by pushing the bootsel button while plugging it into your computer.
  3. Copy the build/PicoBTSPP.uf2 file to the Raspberry Pi Pico W either by dragging and dropping or using the cp command as shown below.

    LinuxmacOS
    cp build/PicoBTSPP.uf2 /media/<user>/RPI-RP2cp build/PicoBTSPP.uf2 /Volumes/RPI-RP2
  4. Connect to your Raspberry Pi Pico W to your PC.

    Check out CMakeLists.txt file for STDIO settings.

    • Using USB CDC (Default Setting)

      1. Redirect STDIO to USB CDC.
         # Enable or Disable UART
         pico_enable_stdio_uart(${PROJECT_NAME} 0)
        
         # Enable or Disable USB CDC
         pico_enable_stdio_usb(${PROJECT_NAME} 1)
        
      2. Please connect Raspberry Pi Pico W to your PC via USB.
    • Using UART0 over USB serial adapter

      1. Redirect STDIO to UART0.
         # Enable or Disable UART
         pico_enable_stdio_uart(${PROJECT_NAME} 1)
        
         # Enable or Disable USB CDC
         pico_enable_stdio_usb(${PROJECT_NAME} 0)
        
      2. Please connect Raspberry Pi Pico W’s UART0 to your PC via the USB serial adapter.

        PinFunctionUSB / Serial converter
        1UART0 TXRX
        2UART0 RXTX
        3GNDGND
  5. Open your favorite serial terminal app and set the baud rate to 115200, then open the corresponding serial port.
  6. Search for Bluetooth device name “SPP Counter XX:XX:XX:XX:XX:XX” from your PC or Android phone.
  7. For Android you can use Serial Bluetooth Terminal. You can find its source code here.
  8. After connecting to your device, you can see that the Raspberry Pico W sends BTstack counter XXXX to your device. If you type something and tap to send button, you can see RCV: 'text' on your PC’s terminal.

You Can Support My Work

Creating projects like this takes a great amount of time. Much appreciated if you consider supporting me so that I can continue projects like this and creating new contents for everyone.

You might consider supporting me via GitHub Sponsors, Patreon, or Ko-fi. For links, please see the About page.

Final words

You can access the dedicated repository through this link.

Tell me what you think in the comments. What do you want to see on my blog or YouTube channel?