RP2040-BLE
| ||
Overview
RP2040-BLE is a mini RP2040 development board, with Bluetooth 5.1 dual mode function, allowing controlling by serial AT commands, 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
Dimensions
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 Rev*.* on the back for version differentiation.
- Open the flip cover of the cable connector.
- Please make sure to install the cable in the center.
- Close the flip cover. Normally, the flip cover should be closed completely.
- 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.
Note
- Please do not unplug or plug 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 Getting Started
Firmware Download
Introduction
MicroPython Series
Install Thonny IDE
In order to facilitate the development of Pico/Pico2 boards using MicroPython on a computer, it is recommended to download the Thonny IDE
- Download Thonny IDE and follow the steps to install, the installation packages are all Windows versions, please refer to Thonny's official website for other versions
- After installation, the language and motherboard environment need to be configured for the first use. Since we are using Pico/Pico2, pay attention to selecting the Raspberry Pi option for the motherboard environment
- Configure MicroPython environment and choose Pico/Pico2 port
- Connect Pico/Pico2 to your computer first, and in the lower right corner of Thonny left-click on the configuration environment option --> select Configture interpreter
- In the pop-up window, select MicroPython (Raspberry Pi Pico), and choose the corresponding port
Flash Firmware
- Click OK to return to the Thonny main interface, download the corresponding firmware library and burn it to the device, and then click the Stop button to display the current environment in the Shell window
- Note: Flashing the Pico2 firmware provided by Micropython may cause the device to be unrecognized, please use the firmware below or in the package
- How to download the firmware library for Pico/Pico2 in windows: After holding down the BOOT button and connecting to the computer, release the BOOT button, a removable disk will appear on the computer, copy the firmware library into it
- How to download the firmware library for RP2040/RP2350 in windows: After connecting to the computer, press the BOOT key and the RESET key at the same time, release the RESET key first and then release the BOOT key, a removable disk will appear on the computer, copy the firmware library into it (you can also use the Pico/Pico2 method)
MicroPython Series
【MicroPython】 machine.Pin class function details
【MicroPython】machine.PWM class function details
【MicroPython】machine.ADC class function details
【MicroPython】machine.UART class function details
【MicroPython】machine.I2C class function details
【MicroPython】machine.SPI class function details
【MicroPython】rp2.StateMachine class function details
C/C++ Series
For C/C++, it is recommended to use Pico VS Code for development. This is a Microsoft Visual Studio Code extension designed to make it easier for you to create, develop, and debug projects for the Raspberry Pi Pico series development boards. No matter if you are a beginner or an experienced professional, this tool can assist you in developing Pico with confidence and ease. Here's how to install and use the extension.
- Official website tutorial: https://www.raspberrypi.com/news/pico-vscode-extension/
- This tutorial is suitable for Raspberry Pi Pico, Pico2 and the RP2040 and RP2350 series development boards developed by Waveshare
- The development environment defaults to Windows11. For other environments, please refer to the official tutorial for installation
Install VSCode
-
First, click to download pico-vscode package, unzip and open the package, double-click to install VSCode
Note: If vscode is installed, check if the version is v1.87.0 or later
Install Extension
-
Click Extensions and select Install from VSIX
-
Select the package with the vsix suffix and click Install
-
Then vscode will automatically install raspberry-pi-pico and its dependency extensions, you can click Refresh to check the installation progress
-
The text in the right lower corner shows that the installation is complete. Close VSCode
Configure Extension
-
Open directory C:\Users\username and copy the entire .pico-sdk to that directory
-
The Copy is completed
-
Open vscode and configure the paths for the Raspberry Pi Pico extensions
The configuration is as follows:Cmake Path: ${HOME}/.pico-sdk/cmake/v3.28.6/bin/cmake.exe Git Path: ${HOME}/.pico-sdk/git/cmd/git.exe Ninja Path: ${HOME}/.pico-sdk/ninja/v1.12.1/ninja.exe Python3 Path: ${HOME}/.pico-sdk/python/3.12.1/python.exe
New Project
-
The configuration is complete, create a new project, enter the project name, select the path, and click Create to create the project
To test the official example, you can click on the Example next to the project name to select
-
The project is created successfully
-
Select the SDK version
-
Select Yes for advanced configuration
-
Choose the cross-compilation chain, 13.2.Rel1 is applicable for ARM cores, RISCV.13.3 is applicable for RISCV cores. You can select either based on your requirements
-
Select default for CMake version (the path configured earlier)
-
Select default for Ninjaversion
-
Select the development board
-
Click Complie to compile
-
The uf2 format file is successfully compiled
Import Project
- The Cmake file of the imported project cannot have Chinese (including comments), otherwise the import may fail
-
To import your own project, you need to add a line of code to the Cmake file to switch between pico and pico2 normally, otherwise even if pico2 is selected, the compiled firmware will still be suitable for pico
set(PICO_BOARD pico CACHE STRING "Board type")
Update Extension
-
The extension version in the offline package is 0.15.2, and you can also choose to update to the latest version after the installation is complete
Arduino IDE Series
Install Arduino IDE
-
First, go to Arduino official website to download the installation package of the Arduino IDE.
-
Here, you can select Just Download.
-
Once the download is complete, click Install.
Notice: During the installation process, it will prompt you to install the driver, just click Install
600px
Arduino IDE Interface
-
After the first installation, when you open the Arduino IDE, it will be in English. You can switch to other languages in File --> Preferences, or continue using the English interface.
-
In the Language field, select the language you want to switch to, and click OK.
Install Arduino-Pico Core in the Arduino IDE
-
Open the Arduino IDE, click on the file in the top left corner, and select Preferences
-
Add the following link to the attached board manager URL, and then click OK
https://github.com/earlephilhower/arduino-pico/releases/download/4.0.2/package_rp2040_index.json
Note: If you already have an ESP32 board URL, you can use a comma to separate the URLs as follows:https://dl.espressif.com/dl/package_esp32_index.json,https://github.com/earlephilhower/arduino-pico/releases/download/4.0.2/package_rp2040_index.json
-
Click Tools > Development Board > Board Manager > Search pico, as my computer has already been installed, it shows that it is installed
Upload Demo at the First Time
-
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 after the computer recognizes a removable hard disk (RPI-RP2).
- Download the program and open D1-LED.ino under the arduino\PWM\D1-LED path
-
Click Tools --> Port, remember the existing COM, do not click this COM (the COM displayed is different on different computers, remember the COM on your own computer)
-
Connect the driver board to the computer using a USB cable. Then, go to Tools > Port. For the first connection, select uf2 Board. After uploading, when you connect again, an additional COM port will appear
-
Click Tools > Development Board > Raspberry Pi Pico > Raspberry Pi Pico or Raspberry Pi Pico 2
- After setting it up, click the right arrow to upload the program
- If issues arise during this period, and if you need to reinstall or update the Arduino IDE version, it is necessary to uninstall the Arduino IDE completely. After uninstalling the software, you need to manually delete all contents within the C:\Users\[name]\AppData\Local\Arduino15 folder (you need to show hidden files to see this folder). Then, proceed with a fresh installation.
Open Source Demos
MircoPython video demo (github)
MicroPython firmware/Blink demos (C)
Raspberry Pi official C/C++ demo (github)
Raspberry Pi official micropython demo (github)
Arduino official C/C++ demo (github)
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 connection on/off status of the Bluetooth module:
uint8_t Query_BLE_Switch(BluetoothModule *ble);
- Query the SPP connection on/off status 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);
- Disable 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 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 on/off status of the Bluetooth module:
ble.Query_SPP_Switch()
- Read the attribute of the print 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 of the RGB LED for the Bluetooth module are all in the file "bluetooth_commands.py". The demo imports the BluetoothModule class and then calls the functions through the 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:
Open the software on the smartphone. (This is just a demo, you can download any Bluetooth APP from the app store.)
Click to pair:
Click on Pairing and the following will appear on the computer and the phone:
Enter the data on your cell phone and click send (your computer will show you the data you sent):
PS: Apps using the BLE protocol on the mobile side need to open the notify interface.
Resource
Document
Demo
Software
Development Software
FAQ
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)