Maker Portal

View Original

BLE Nano Arduino Board - Bluetooth Control with an iPhone (BLExAR App)

“As an Amazon Associates Program member, clicking on links may result in Maker Portal receiving a small commission that helps support future projects.”

See this content in the original post

See this content in the original post

In this tutorial, the BLE Nano, RGB LED, and BLExAR app are the main components needed to follow along. A full list of components are given below:

The wiring diagram and table are given below:

See this content in the original post

BLExAR iOS App

As stated in the introduction, the BLE Nano can be treated identically as an Arduino Nano board, with the small adjustment of the serial port being part of pins D0/D1. With that in mind, the RGB LED (or any sensor, indicator, motor, etc.) can be wired to pins D2 - D13, or even A0 - A7.

See this content in the original post

See this content in the original post

The BLE Nano can be treated just as an Arduino Nano: coding in the Arduino IDE is nearly identical, wiring components to it is exactly the same, and uploading code to the board can be treated just the same. The main difference is that we have to consider the serial port on pins D0/D1. This essentially means that when we write to the serial port, we are effectively writing to both the hardware serial port and the BLE serial port. This is especially important when connected to a Bluetooth device.

Before uploading any code to the BLE Nano, it must be plugged into the USB port of a computer (Raspberry Pi is used in this tutorial). Then, follow the guidelines below to ensure that the correct Arduino board is chosen, along with the respective processor (this is very important).

The following is a simple code that loops through the RGB LED pins and turns them on/off. If the code below works, then your BLE Nano is functioning as it should. If it doesn’t work, check the wiring, and ensure the board properties are correct as per the suggestions above.

See this content in the original post

At this point, the BLE Nano is acting as a standard Arduino Nano board - it can look through the pins wired to the RGB LED and turn them on and off. The BLE Nano is capable of PWM, which allows the board to change the brightness of the LEDs, and it can read analog/digital pins, and it can even handle I2C device communication. In the next section, the Bluetooth Low Energy (BLE) portion of the BLE Nano will be explored - where the full breadth of the BLE Nano board will be utilized by interfacing with an iPhone BLE app, called BLExAR.


See this content in the original post

The BLE Nano uses the universal asynchronous receiver-transmitter (UART) communication protocol to communicate between the ATmega328P microcontroller and the CC2540 Bluetooth module. In short, the BLE Nano uses its serial port to send and receive information to and from other BLE-enabled devices from its CC2540 chip. Thus, in this section, the codes will be focused on serial communication with the Nano board to receive commands. The commands are received as 8-bit Unicode Transformation Format (UTF-8) characters, which we will decode as letters and numbers. These letters and numbers will help us decipher how the BLE Nano will be controlled. For example, in the code below, pins D2 - D13 are allocated as outputs on the Nano board. In the continuous loop, the BLE Nano waits for a number to be inputted (from 2-13); then, this number is taken as the pin to control. Lastly, the pin is changed based on its current state, i.e. if the pin is on, it turns off; and if the pin is off, it turns on.

The BLExAR app allows serial communication between the BLE Nano and an iOS device (iPhone or iPad). The BLExAR app was designed by our team specifically for reasons such as this - to interface between an iPhone and Arduino board.

Below is the code to control pins 2-13 on the BLE Nano using simple UTF-8 character inputs:

See this content in the original post

A video demonstration is given below using the code above:

See this content in the original post

See this content in the original post

Now, this process is not ideal for switching indicators on and off in an efficient manner. The BLExAR app has specific identifiers associated with the digital and analog pins of the ATmega328P boards. This means that the BLE Nano pins can be turned on and off by clicking the radio buttons on the ‘Control’ menu of the BLExAR app. The control code for the BLE Nano is given below:

See this content in the original post

The BLExAR control code for the BLE Nano given above allows control of any of the digital pins 2 - 13, and analog pins 0 - 5. A video demonstration is again give below, showing the BLExAR radio buttons controlling the BLE Nano and RGB LED. The BLExAR control code given above also allows control of PWM values on the PWM pins (digital pins 3, 5, 6, 9, 10, 11). The PWM control allows us to dim and brighten the LEDs. This is also demonstrated in the video below:

See this content in the original post

See this content in the original post

The BLE Nano board is a great advancement for hobbyists and DIY electronics enthusiasts interested in connected devices and internet of things (IoT) technologies. The BLE Nano, as demonstrated above, is a hybrid Arduino and Bluetooth Low Energy (BLE) board. The BLE chip, Texas Instruments’ CC2540, is wired to the serial port on an ATmega328P microcontroller, housed in an Arduino Nano profile. This gives the BLE Nano a small profile, with great capabilities. Uploading code to the BLE Nano was demonstrated as an equivalent process compared to the standard Arduino Nano board. When handling Bluetooth information on the BLE Nano, it must be done through serial port communication. In this tutorial, the BLExAR iOS application was used to send commands to the BLE Nano. An RGB LED was used as an indicator wired to the BLE Nano board and controlled with an iPhone. The iPhone acted as a wireless controller of the RGB LED by using the CC2540 as the Bluetooth peripheral, and the ATmega328P as the physical controller. This allow commands to be read by the BLE Nano via the serial port, where the ATmega328P carries out commands based on the information received over Bluetooth. This tutorial is meant as an introduction to merging an iOS application and an Arduino board using Bluetooth technology. The BLE Nano can be used as a peripheral controlled, as demonstrated here, and it can also be used to send data from a sensor to a smart phone. The possibilities are endless and the opportunities are vast with this Bluetooth-enabled Arduino board.

See this content in the original post

See More in Arduino and IoT:

See this content in the original post