How to Use a BLE Module — A RN4020 Tutorial
By: Lesther B.
Tags: Embedded Systems, Programming, Hardware, Electronics, Tutorial

Checking out some of the results there seems to be a prevalent proposition from manufacturers like Silicon Labs, Cypress Semiconductor, Taiyo Yuden, Microchip. But we need to find something in good enough quantities so we aren’t left without stock, with good documentation, example usage and a good demo.

And some offerings from Microchip seemed to fit the bill pretty well, specially the RN4020, a first look into the IC’s datasheet and user manual provides valuable information on how easy this device is to use (sort of).

Basic connectivity to the device

While Bluetooth Low Energy provides much lower power consumption than the standard Bluetooth classic, it does not offer a standardized way to transmit data over the air, so manufacturers are left to themselves or to end user to find a way to do so, Microchip developed their own called Microchip Low-energy Data Profile (MLDP) which in a nutshell is a private profile to ease the burden.

RN4020 internal diagram

A quick look at the internal block diagram reveals that this is a 1.8V — 3.6V device, meaning your microcontroller power must be within that range, otherwise you can damage your module.

Following the basic connectivity diagram, a small ATtiny412 (great little devices) from microchip to do the basic configuration coupled with a Serial to USB IC to do the heavy lifting of receiving the incoming data from our other device did the trick for the computer side.

A wild jumper to fix post creation error

RN4020’s manual explain on how to configure a device as peripheral. The command you issue determines if it becomes a peripheral or a central module.

To enable MLDP communication you must use the SR command to set the Enable MLDP, Auto Advertise, and UART Flow Control bits on the peripheral module; SS command to set Heart Rate and Health Thermometer services. Always reboot the device for the changes to take effect!

Flow control is recommended if you plan or transmitting data as fast as the module allows, otherwise your data or commands will be simply ignored.

Budges are the hardware version of bug fixing

For the central device we must issue similar commands.

To enable MLDP in the central device you need to issue SS command to set Device information and Battery services. SR command to set Enable MLDP and UART Flow Control. Always reboot the device for the changes to take effect!

Once both modules are configured, you can issue the ‘F’ command to find the device. You should have a response from your central device like this:

Response from the central device

Once the device is found, we can send the ‘X’ command stop the scan. The string marked in yellow is the peripheral MAC address, which is what we need to connect to the device, the other 3 parameters show the MAC address type, name, and signal strength.

To connect to your peripheral we must issue the ‘E’ command, followed by the target MAC address, like so:

Connecting to peripheral

Once connection has been established, you will receive a ‘connected’ response. And to finally enable MLDP and have your super awesome over the air serial channel, you simply set the CMD/MLPD pin high, and you will be greeted with the ‘MLDP’ response and your data should start flowing.

Success!

Scaling up

Now that you have the basics, you can integrate this module to any of your projects and start communicating them with other gadgets to your heart desires.

Selecting devices like the RN4020 enhances your design for manufacturing capabilities, which will allow you have your device assembled by one of the low cost services without breaking the bank.

I hope you’ve enjoyed this quick peek into the wild world of BLE modules!

If you liked this post, you can also have a look at my own website nicatronix.com that I am currently building to share more related stuff on Electronics!