Our project is designed to receive commands remotely via Bluetooth. To facilitate this transfer, the UART peripheral in the Pico will have to be set up. The UART is a protocol that controls serial communication between supported devices.
The Pico has two independent UARTs. We'll use UART1 for this task.
Table of Contents
- Flowchart
- Requirements
Implementation
- Serial Bluetooth App
- Connections
- UART Configuration
- Test
- Interrupt
- Final Code
Flowchart
Implementation
Remote commands will be sent from a Serial Bluetooth Terminal App on a phone and will be a byte each. They are shown below.
| Command | Execution |
|---|---|
| A | Toggle the system between Manual and Auto modes |
| B | Move the PTZ kit Clockwise |
| C | Move the PTZ kit Counter-clockwise |
| D | Move the PTZ kit Up |
| E | Move the PTZ kit Down |
| F | Move the PTZ kit to Position Zero |
We will organize the above options into a Direction enum.
enum Direction {
Cw,
Ccw,
Up,
Down,
Zero,
}
Create a global static variable DIRECTION that will hold the position of the system at any given time.
static DIRECTION: Mutex<RefCell<Option<Direction>>> = Mutex::new(RefCell::new(None));
The Serial Bluetooth App is linked to the HC-05 module which is in turn physically connected to gp8 and gp9 pins in the Pico. A complete path is therefore created from the phone issuing the command to the RP2040 processing it.
Serial Bluetooth App
As mentioned earlier we will be using the Serial Bluetooth App to send our commands to our system remotely.
We first have to set up the app so that it sends precisely one byte per press. Navigate to settings and under Newline select None. This is to enable the transmission of the command byte only and therefore match the UART interrupt, which we'll also set up to receive only one byte at a time.
We will also allow local echo to help us visualize the commands we are sending.
Also edit the macro rows to have the commands discussed above i.e. Auto/Manual, CW, CCW, UP, DOWN and Zero.
You should have something of this sort:
The electrical connections will be as shown above.
UART Configuration
To begin we must configure the pins on the Pico board associated with UART1. These shall provide the physical connection to the HC-05 module in our program.
Now that we have confirmed UART is working, we can proceed with writing the interrupt service routine that'll receive the command bytes.
Interrupt
The algorithm below gives the general flow of the UART interrupt service routine.
final copy.
Here are highlights of the changes made from the previous program.
Running this program will flash it into the Pico and we'll be set to receive commands remotely via Bluetooth.
In the next part of the series we shall finish up on command reception by implementing the application section of the program.
SOCIAL SHARE CARD GENERATOR