RP2040-BLE

From Waveshare Wiki
Jump to: navigation, search
RP2040-BLE
RP2040-BLE.jpg

RP2040, FPC
{{{name2}}}

{{{name3}}}

{{{name4}}}

{{{name5}}}

Overview

RP2040-BLE is a mini RP2040 development board, with Bluetooth 5.1 dual mode function, allowing controlling by serial AT commands for quick start-up, which can realize Bluetooth wireless communication.
With 14 multi-function GPIO pins on a very small board and castellated holes on the PCB edge, it is easy and fast to integrate into your project.

Features

  • RP2040 microcontroller chip designed by Raspberry Pi in the United Kingdom.
  • Dual-core Arm Cortex M0+ processor, flexible clock running up to 133 MHz.
  • 264KB of SRAM, and 2MB of onboard Flash memory.
  • Supports Bluetooth 5.1 dual mode function.
  • Onboard Bluetooth module, allows controlling by serial AT commands for quick start-up.
  • Castellated module allows soldering directly to carrier boards.
  • Drag-and-drop programming using mass storage over USB.
  • Adapting 24 × pins including 14 × multi-function GPIO pins.
  • 2 × SPI, 2 × I2C, 2 × UART, 3 × 12-bit ADC, 14 × controllable PWM channels.
  • Temperature sensor.
  • Accelerated floating-point libraries on-chip.
  • 8 × Programmable I/O (PIO) state machines for custom peripheral support.

Pinout Definition

RP2040-BLE-Kit-details-inter.png

Dimensions

RP2040-BLE-Kit-details-size.jpg

Cable Connection

  • Please read this section and the precautions before connection, otherwise the device may be damaged or short-circuited!

  • FPC connector update in V1.1 version and above can bring you a better experience, which can be identified by the back of the Rev*. * for version differentiation.
  1. Open the flip cover of the cable connector.
    Ting-connect-00.jpg
  2. Please make sure to install the cable in the center.
    Ting-connect-01.jpg
  3. Close the flip cover. Normally, the flip cover should be closed completely.
    Ting-connect-02.jpg
  4. If the cable is not properly installed, it may prevent the flip cover from closing correctly. Please adjust the position of the cable and try to close the flip cover again.
    Ting-connect-WR.jpg

Note

  • Please do not unplug the cable with electricity, otherwise it may lead to a short circuit.
  • When installing the cable, it is important to pay attention to its proper connection in the center and ensure that it is inserted fully into the socket. Incorrect installation may result in connection issues or even short circuits.

Pico Quick Start

Download Firmware

  • MicroPython Firmware Download

MicroPython Firmware Download.gif

  • C_Blink Firmware Download

C Blink Download.gif

Video Tutorial

  • Pico Tutorial I - Basic Introduction

  • Pico Tutorial II - GPIO

  • Pico Tutorial III - PWM

  • Pico Tutorial IV - ADC

  • Pico Tutorial V - UART

  • Pico Tutorial VI - To be continued...

MicroPython Series

C/C++ Series

Arduino IDE Series

Install Arduino IDE

  1. Download the Arduino IDE installation package from Arduino website.
    RoArm-M1 Tutorial II01.jpg
  2. Just click on "JUST DOWNLOAD".
    Arduino IDE Pico.png
  3. Click to install after downloading.
    RoArm-M1 Tutorial II02.gif
  4. Note: You will be prompted to install the driver during the installation process, we can click Install.

Install Arduino-Pico Core on Arduino IDE

  1. Open Arduino IDE, click the File on the left corner and choose "Preferences".
    RoArm-M1 Tutorial04.jpg
  2. Add the following link in the additional development board manager URL, then click OK.
    https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json

    RoArm-M1 Tutorial II05.jpg
    Note: If you already have the ESP8266 board URL, you can separate the URLs with commas like this:

    https://dl.espressif.com/dl/package_esp32_index.json,https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
    
  3. Click on Tools -> Dev Board -> Dev Board Manager -> Search for pico, it shows installed since my computer has already installed it.
    Pico Get Start 05.png
    Pico Get Start 06.png

Upload Demo At the First Time

  1. Press and hold the BOOTSET button on the Pico board, connect the Pico to the USB port of the computer via the Micro USB cable, and release the button when the computer recognizes a removable hard drive (RPI-RP2).
    Pico Get Start.gif
  2. Download the demo, open arduino\PWM\D1-LED path under the D1-LED.ino.
  3. Click Tools -> Port, remember the existing COM, do not need to click this COM (different computers show different COM, remember the existing COM on your computer).
    UGV1 doenload02EN.png
  4. Connect the driver board to the computer with a USB cable, then click Tools -> Ports, select uf2 Board for the first connection, and after the upload is complete, connecting again will result in an additional COM port.
    UGV1 doenload03EN.png
  5. Click Tool -> Dev Board -> Raspberry Pi Pico/RP2040 -> Raspberry Pi Pico.
    Pico Get Start02.png
  6. After setting, click the right arrow to upload.
    Pico Get Start03.png
    • If you encounter problems during the period, you need to reinstall or replace the Arduino IDE version, uninstall the Arduino IDE needs to be uninstalled cleanly, after uninstalling the software you need to manually delete all the contents of the folder C:\Users\[name]\AppData\Local\Arduino15 (you need to show the hidden files in order to see it) and then reinstall.


Open Source Demo

Sample Demo

C/C++ Demo

Hardware Interface

1. Bluetooth module initialization.

Initialize RP2040-BLE by calling various low-level interface functions. Main functionalities include waiting for a connection, querying whether the connecting party has enabled the notify feature, querying the baud rate of the Bluetooth module, current operating mode (low-power mode), name, address, and modifying the module's name.

void BLE_Init();
2.Bluetooth module structure

For storing Bluetooth module information such as baud rate, working mode, name, and address.

typedef struct {  
    int Baud_Rate;                       
    uint8_t Low_Power_Mode;              
    uint8_t Name_BLE[64];                
    uint8_t Name_SPP[64];                
    uint8_t ADD[64];                    
    uint8_t BLE_Switch;                 
    uint8_t SPP_Switch;                
} BluetoothModule; 
3. User command

Users can send commands to the RP2040-BLE through the Bluetooth debugging assistant to realize the functions of modifying the main frequency, modifying the sleep time of the Bluetooth module, controlling the RGB, etc.

uint8_t My_Cmd(uint8_t rx_num,uint8_t rx_data[]);

Parameter explanation:

rx_num: command length 
rx_data: command

Users can send the following commands through the Bluetooth.

usb: the main frequency is 20M by default, when the USB stops working, the computer fails to recognize the devices, and you can improve the main frequency of the RP2040 to 50MHz to make the USB get back to normal working status. 
sleepxx: Modify the sleep time of the RP2040, and xx can be set within the range of 0~59. 
red: the RGB LED turns red  
blue: the RGB LED turns blue 
green: the RGB LED turns green  
close: turn off RGB LED.
4. Sleep mode (C demo)

Simply call the rtc_sleep() function to enter sleep mode. By default, the sleep duration is 5 seconds, and you can modify the sleep time using the sleepxx command, where xx can be set in the range of 0 to 59.

static void rtc_sleep(void);
5. Underlying Interface Function

1. Bluetooth Module Interface Function

  • Query the baud rate of the Bluetooth module:
    uint8_t Query_Baud_Rate(BluetoothModule *ble);
  • Query the working mode of the Bluetooth module:
    uint8_t Query_Power_Low(BluetoothModule *ble);
  • Query the BLE connection name of the Bluetooth module:
    uint8_t Query_Name_BLE(BluetoothModule *ble);
  • Query the SPP connection name of the Bluetooth module:
    uint8_t Query_Name_SPP(BluetoothModule *ble);
  • Query the address of the Bluetooth module:
    uint8_t Query_ADD(BluetoothModule *ble);
  • Query the BLE on/off status of the Bluetooth module:
    uint8_t Query_BLE_Switch(BluetoothModule *ble);
  • Query the SPP connection On/Off of the Bluetooth module:
    uint8_t Query_SPP_Switch(BluetoothModule *ble);
  • Read the attribute of the printing Bluetooth module:
    uint8_t Read_Attribute(BluetoothModule *ble);
  • Set the baud rate of the Bluetooth module:
    uint8_t Set_Baud_Rate(BluetoothModule *ble);
  • Set the BLE connection name of the Bluetooth module:
    uint8_t Set_Name_BLE(BluetoothModule *ble);
  • Set the SPP connection name of the Bluetooth module:
    uint8_t Set_Name_SPP(BluetoothModule *ble);
  • Set the address of the Bluetooth module:
    uint8_t Set_ADD(BluetoothModule *ble);
  • Enable the BLE function of the Bluetooth module:
    uint8_t ON_BLE(BluetoothModule *ble);
  • Disable the BLE function of the Bluetooth module:
    uint8_t OFF_BLE(BluetoothModule *ble);
  • Enable the SPP function of the Bluetooth module:
    uint8_t ON_SPP(BluetoothModule *ble);
  • Close the SPP function of the Bluetooth module:
    uint8_t OFF_SPP(BluetoothModule *ble);
  • Enable the low-power mode of the Bluetooth module:
    uint8_t ON_Low_Power_Mode(BluetoothModule *ble);
  • Close the low-power mode of the Bluetooth module:
    uint8_t OFF_Low_Power_Mode(BluetoothModule *ble);

2. RGB LED Interface Function

  • Red LED:
    void RGB_red();
  • Green LED:
    void RGB_green();
  • Blue LED:
    void RGB_blue();
  • RGB LED Off:
    void RGB_close();

Code Explanation

1.BLE.h

Serial port and pin configurations are in BLE.h and can be modified as required:

#define UART_ID uart1                  
#define BAUD_RATE 115200               
#define DATA_BITS 8                  
#define STOP_BITS 1                 
#define PARITY    UART_PARITY_NONE      
#define UART_TX_PIN 20               
#define UART_RX_PIN 21                
#define BLE_MODE_PIN 15                 
2.BLE.c

The main code:

void BLE_test()
{
    stdio_init_all();
    vreg_set_voltage(VREG_VSEL);
    sleep_ms(10);
    set_sys_clock_khz(20000, true);
    BluetoothModule *ble = (BluetoothModule *)malloc(sizeof(BluetoothModule));
    UART_Init(UART_IRQ_OFF);
    BLE_Init(ble);
}
  • stdio_init_all();
    Standard initialization of input and output
  • vreg_set_voltage(VREG_VSEL);
    Configure the CPU voltage as VREG_VSEL, and the VREG_VSEL value is 0.9V.
  • set_sys_clock_khz(20000, true);
    Configure the system clock as 20MHz.
  • BluetoothModule *ble = (BluetoothModule *)malloc(sizeof(BluetoothModule));
    Request a block of memory space and point to the address with ble
  • BLE_Init(ble);
    Wait for connection and the Bluetooth module initializes

The main cycle alternates between a 5-second working state and a 5-second sleeping state:

while (1) {
    uint64_t start_time = time_us_64();
    uint64_t duration = 5 * 1000000;

    while (time_us_64() - start_time < duration) {
        UART_Read_Write();
    }

    rtc_sleep();
}
  • UART_Read_Write();
    The working state involves cyclic execution of serial read/write operations for 5 seconds. The Bluetooth module will return the received data, and it will be checked whether the received data is a user command.
  • rtc_sleep();
    Enter sleep mode and wait for the RTC clock to wake up, the sleep duration can be modified by sending the command sleepxx, xx can be set in the range of 0~59.

Run the Demo

1. Download Pico Extras:

  • The demo uses low-power related APIs and requires the pico_sleep library from Pico Extras.
  • Download the link: Pico-extras-master.zip.
  • Unzip and save locally after download.

2. Compile to run:

  • Set the absolute address where your pico-sdk is located to PICO_SDK_PATH, e.g. my pico-sdk address is "D:\pico\pico-sdk"
    setx PICO_SDK_PATH "D:\pico\pico-sdk"
  • Download the sample demo, enter the build directory.
    cd build
  • Specify the Pico Extras path to generate the Makefile file.
    cmake -G "NMake Makefiles" -DPICO_EXTRAS_PATH=F:\Pico\pico-extras-master ..
  • Compile the demo:
    nmake
  • Program the firmware:
    Wait for the compilation to complete and then copy the .uf2 files generated in the build directory to pico.

MicroPython Demo

Hardware Interface

1. Bluetooth module interface function

The interface functions of the Bluetooth module are all in the Python/bluetooth_commands.py file, and the demo imports the BluetoothModule class and calls it through the ble object.

  • Create the Bluetooth module object:
    ble = BluetoothModule(uart)
  • Query the baud rate of the Bluetooth module:
    ble.Query_Baud_Rate()
  • Query the working mode of the Bluetooth module:
    ble.Query_Low_Power()
  • Query the BLE connection name of the Bluetooth module:
    ble.Query_Name_BLE()
  • Query the SPP connection name of the Bluetooth module:
    ble.Query_Name_SPP()
  • Query the address of the Bluetooth module:
    ble.Query_ADD()
  • Query the BLE connection On/Off status of the Bluetooth module:
    ble.Query_BLE_Switch()
  • Query the SPP connection status of the Bluetooth module:
    ble.Query_SPP_Switch()
  • Read the attribute of the printinf Bluetooth module:
    ble.Read_Attributes()
  • Set the baud rate of the Bluetooth module:
    ble.Set_Baudrate(Baudrate)
  • Set the BLE connection name of the Bluetooth module:
    ble.Set_Name_BLE(name)
  • Set the SPP connection name of the Bluetooth module:
    ble.Set_Name_SPP(name)
  • Set the address of the Bluetooth module:
    ble.Set_ADD(address);
2.RGB LED Interface Function

The interface functions for the Bluetooth module are all located in the Python file "bluetooth_commands.py". The demo imports the BluetoothModule class and then calls the functions through the ble object.

  • Create RGB LED object:
    rgb = WS2812()
  • Red LED:
    rgb.RGB_Red()
  • Green LED:
    rgb.RGB_Green()
  • Blue LED:
    rgb.RGB_Blue()
  • RGB LED Off:
    void RGB_Close();

Demo Code Analysis

The main code is shown below:

if __name__ == "__main__":
    Pico_BLE_init()
    while True:
        rxData = ble.Read_Write()
        if rxData is not None:
            print(rxData)
            if(True == ble.My_Cmd(rxData)):
                ble.Write(" cmd takes effect!")
        time.sleep_ms(20)
  • Pico_BLE_init()
    Call the underlying interface function to initialize the Bluetooth module.
  • if(True == ble.My_Cmd(rxData))
    Call My_Cmd() function to determine whether the received data is a user command, if so, perform the user operation and return True.

Run the Demo

  • Program the micropython firmware, upload bluetooth_commands.py and WS2812.py, run the demos.

Example

Smartphone APP Example

Connect the Pico and Pico-BLE:
Open the Python demo and run:

Pico-BEL04.jpg

Open the software on the smartphone. (This is just a demo, you can download any Bluetooth APP from the app store.)

Pico-BEL-7.jpg

Click to pair:

Pico-BEL-8.jpg

Click on Pairing and the following will appear on the computer and the phone:

Pico-BEL-9.jpg
Pico-BEL-10.jpg

Enter the data on your cell phone and click send (your computer will show you the screen where you sent it):

Pico-BEL-5.jpg

Pico-BEL012.jpg

PS: Apps using the BLE protocol on the mobile side need to open the notify interface.

Resource

Document

Demo

Software

Development Software

FAQ

 Answer:

No, only slave mode is currently supported.

{{{5}}}


Support



Technical Support

If you need technical support or have any feedback/review, please click the Submit Now button to submit a ticket, Our support team will check and reply to you within 1 to 2 working days. Please be patient as we make every effort to help you to resolve the issue.
Working Time: 9 AM - 6 PM GMT+8 (Monday to Friday)