Control and Configure RN52 Bluetooth using Arduino

Learn how to connect, control and configure RN52 Bluetooth module using Arduino Due

In this tutorial you will learn how to control and configure RN52 Bluetooth using Arduino Due. The RN52 Bluetooth module is a audio Bluetooth module to which you can send audio(songs) and listen it via speaker attached to the module(below figure illustrates this). You can also activate hand free profile(HFP) to accept call, deny call on your cell phone via Bluetooth.

Before you do this tutorial we encourage you to look at the basic RN52 Bluetooth Tutorial which teaches how to power up the module and how to configure the RN52 Bluetooth module via terminal. Also if you haven’t done much with Arduino Due then see this starter Arduino Due tutorial.

Controlling and configuring is useful in embedded system design where wireless Bluetooth module is used. In this scenario, you have to be able to configure the module via a microcontroller. In this tutorial we will illustrate this using Arduino Due as our microcontroller. While there are many things on the Bluetooth module that you can configure here you will learn how to send command from Arduino Due to RN52 Bluetooth module to change its default name. Once you learn this, sending other command to control other aspects of the Bluetooth features is similar.

So here is the picture that shows the setup for this tutorial.

Control and Configure RN52 Bluetooth using Arduino

 

The command has to be sent using UART port on Arduino Due. But there are couples of UART port in Arduino Due. In this tutorial we will use the UART port 1 also called serial port 1.

Below is a general diagram of how to connect a microcontroller to the RN52 module.

The figure shows 6 connection between the microcontroller and RN52. The RX, TX, CTS and RTS are the UART port pins. The other two GPIO2 and GPIO9, are for receiving status information from the module and to set the module into command mode, respectively.

For our purpose we need only three of them. These are RX, TX and GPIO9.

The RX, TX in the above diagram in our case is the RX1 and TX1 on the Arduino Due Board. The transmit pin TX1 is at pin18 and receive pin RX1 is at pin 19. These two pins should be connected to the Bluetooth module UART TX and RX pin. Note that TX1 of the Arduino due should be connected to RX of RN52 and the RX1 of Arduino Due to the TX of RN52.

The GPIO9 pin of the module can be connected to the general digital pin on Arduino Due. Here we will use the pin 12 on Arduino Due.

Note that you can also use Arduino UNO but you have to ensure that you have correct voltage level required by RN52 Bluetooth module. RN52 is 3.3V device while Arduino UNO is 5V microcontroller board. Arduino Due on the other hand is a 3.3V microcontroller board which makes it excellent to interface with RN52 module.

Program

The aim of the program is to change the name of the bluetooth module. For this we have to send the command sn,myRN52 where myRN52 is the new name for the bluetooth device. You can change myRN52 to any other name you like. To send this command we write the following.

where Serial1 refers the the serial port 1 of the Arduino Due.

After sending that we have to reboot the module which is done using the following code.

This was about how to send the command to the module.

But there are couple of things we can do in our program. For example we can add a switch and a LED. The switch will be used to put the Bluetooth module into command mode. And the LED should turn on after we have used the switch. This gives us visual information that we have put the module into command mode and that command has been sent.

Now the complete program code is as under.

The LED is connected to pin 13 on Arduino Due, the switch is connected to the pin 11 and the GPIO9 pin of the module is connected to the pin 12 of the Arduino Due.

In the figure below you can see the SPDT switch on the left bottom corner.

Control and Configure RN52 Bluetooth using Arduino

After you have done this you should open a terminal to the Bluetooth module and check whether the name has changed or not. Below shows the current setting of the module.

change name of RN52

So in this way you can connect RN52 to microcontroller and configure it via UART port.

See also Arduino Bluetooth Module HC-05 Tutorial where we have used data Bluetooth module and Arduino.

What do you think?

0 points
Upvote Downvote

Total votes: 0

Upvotes: 0

Upvotes percentage: 0.000000%

Downvotes: 0

Downvotes percentage: 0.000000%

Leave a Reply

Your email address will not be published. Required fields are marked *

Simplest MPLAB Harmony Project with PIC32 microcontroller

USART pin selection in MHC

PIC32MX and RN52 bluetooth using MPLAB Harmony