Using the Adafruit Bluefruit modules with Arduino Uno

In this tutorial we will discuss how to use some of the Adafruit Bluefruit modules with an Arduino Uno. Note that other models of Arduino might require some changes to these instructions.

Preparation

Reading

Read the appropriate Adafruit tutorial:

Download and install the Adafruit library

  1. Sketch -> Include Library -> Manage Libraries
  2. Search for Adafruit BluefruitLE nRF51
  3. Select Adafruit BluefruitLE nRF51
  4. Click “Install” button
  5. Verify that library installed properly by opening library example
    File -> Examples -> Adafruit BluefruitLE nRF51
  6. If there are no Adafruit BluefruitLE entries in the Examples folder you must shut down and restart Arduino

Testing that the library is properly installed

  1. Open File -> Examples -> Adafruit BluefruitLE nRF51 -> controller
  2. Test that the example compiles properly by clicking “Compile”

Get the Adafruit Bluefruit app to your phone

  1. Download the appropriate Adafruit Bluefruit LE Connect app:  iOS App or Android App

Using the Adafruit Bluefruit LE UART Friend

Prepare your Bluefruit LE UART Friend

  1. DO NOT SOLDER JUMPER WIRES TO THE MODULE!!!!
  2. If necessary, solder a header to your Bluefruit module.
    Whether you use male or female, right angle or straight headers is up to you.
  3. Place the switch in the UART position

Wire up the Adafruit Bluefruit LE UART module to your Arduino

  1. Look for the section titled “Wiring for Arduino Uno” in the Adafruit tutorial. The default wiring works fine with Arduino Uno.

Testing that the Adafruit Bluefruit LE UART Friend is working properly

  1. In the Adafruit tutorial, go to the software section and scroll down a few paragraphs to the “Select the Serial Bus” section.
  2. Follow the instructions for “UART Based Boards (Bluefruit LE UART Friend)”, which instructs you to uncomment the Software Serial lines and to comment out the hardware SPI lines in the example.
  3. Upload the sketch. Note that the hardware serial port is initialized with a baud rate of 11520 (Serial.begin(115200) )
  4. Open your serial port and change the baud rate to 115200
  5. Wait until you see the message “Please use Adafruit Bluefruit LE app to connect in UART mode”
  6. Open the Bluefruit app on your phone and connect to the Adafruit Bluefruit LE
  7. You may be told that updated firmware is available. Go ahead and install it.
  8. Once you connect, select “UART”
  9. Type a message on your phone and hit send. It should appear on the Arduino serial monitor (along with the code for each letter, making it hard to read)
  10. Type a message on the Arduino serial monitor (the blank line at the top) and hit send, and it should appear on your phone.
  11. Congratulations!

Controlling an Arduino project from your phone using the Adafruit Bluefruit LE UART Friend

  1. Make sure the MODE switch on your Adafruit Bluefruit LE UART Friend is in DATA mode
  2. In the  Adafruit tutorial search for the Controller section
  3. Open File -> Examples -> Adafruit BluefruitLE nRF51 -> controller
  4. As before, uncomment the Software Serial lines and comment out the hardware SPI lines in the example
  5. Upload the sketch
  6. Open your serial monitor and change the baud rate to 115200.
  7. Wait until you see the message “Please use Adafruit Bluefruit LE app to connect in Controller mode”
  8. In the Adafruit Bluefruit LE Connect phone app, connect to your Bluefruit but this time as a Controller
  9. Scroll down to the bottom of the available sensors and select Control Pad
  10. Press the buttons and note that the Arduino software reports the button pressed. You can use this to control something e.g.
     
    if (buttnum == 5) {
          Serial.println("Turning on LED");
          digitalWrite(13, HIGH);
        } 
        if (buttnum == 6) {
          Serial.println("Turning off LED");
          digitalWrite(13, LOW);
        }
    

    Don’t forget to add the appropriate pinMode() command in setup()

Using the Adafruit Bluefruit LE SPI Friend

Prepare your Bluefruit LE SPI Friend

  1. DO NOT SOLDER JUMPER WIRES TO THE MODULE!!!!
  2. If necessary, solder a header to your Bluefruit module. Whether you use male or female, right angle or straight headers is up to you.

Connect the Adafruit Bluefruit LE SPI Friend to your Arduino

  1. Connect the module to your Arduino according to the Adafruit tutorial here

Testing that the Adafruit Bluefruit LE Shield is working properly

  1. In Arduino, open File -> Examples -> Adafruit BluefruitLE nRF51 -> controller.
  2. Scroll down to the setup() function.
  3. Note that the hardware serial port is initialized with a baud rate of 11520 (Serial.begin(115200) ) which is unusual. Keep this in mind.
  4. Upload the sketch.
  5. Open your serial port and change the baud rate to 115200.
  6. Wait until you see the message “Please use Adafruit Bluefruit LE app to connect in Controller mode”
  7. Open the Bluefruit app on your phone and connect to the Adafruit Bluefruit LE. This might take a few moments.
  8. You may be told that updated firmware is available. Go ahead and install it.
  9. Once you connect, select “Controller”
  10. Scroll down to the bottom of the page and select “Control Pad”
  11. Press the various buttons on the “Control Pad” app and notice the the Arduino Serial Monitor tells you which buttons you pressed. This proves that your phone is communicating by Bluetooth with your Arduino
  12. Congratulations!

Controlling an Arduino project from your phone using the Adafruit Bluefruit LE SPI Friend

  1. In the Arduino “Controller” example look for the section titled “Buttons” in the loop() function.
  2. The information from the phone comes in an array called packetbuffer[]. The second entry in that array (packetbuffer[1]) is the letter ‘B’ signifying that this message is a button event. The third entry (packetbuffer[2]) is the button number and the fourth entry indicates whether the button was pressed or released.
  3. You can use the variables buttnum and pressed to decide what to turn on or off.
  4. For instance, connect a couple of LEDs to unused pins on your Arduino. (Note that the Bluefruit Shield uses pin 13, so you can not use the LED on pin 13.)
  5. This example uses one button to turn an LED on and a different button to turn it off:
     
       if (buttnum == 5) {
         Serial.println("Turning on LED");
         digitalWrite(3, HIGH);
       }
       if (buttnum == 6) {
         Serial.println("Turning off LED");      
         digitalWrite(3, LOW);
       }
    
  6. This example uses the state of the button (whether it is pressed or not) to turn an LED on or off:
     
        if (buttnum == 8) {
          if (pressed == 1) {
            digitalWrite(2, HIGH);
          } else {
            digitalWrite(2, LOW);
          }
        }
    
  7. Important:
    1. Any code that you add must be within the if (packetbuffer[1] == 'B') { section
    2. Don’t forget to add the appropriate pinMode() command in setup()
    3. Note that the Arduino “Controller” example will only work if the serial monitor is open. This is due to the following line in setup():
      while (!Serial);  // required for Flora & Micro
      If you want your program to operate without the serial monitor (for instance if your project is not connected to your laptop) you must remove this line.

Changing the name of your Bluefruit Friend

  1. In Arduino, go to File->Examples->Adafruit Bluetooth nRF51->atcommand
  2. Upload to Arduino, then go to serial monitor
  3. In the top  line of the Serial Monitor type
    AT+GAPDEVNAME=x
    where “x” is the new name for your module.
  4. Click the “send” button. Your module should respond with  “OK”
  5. In the top  line of the Serial Monitor type
    ATZ
  6. Click the “send” button. Your module should respond with  “OK”
  7. Your module name should now be changed, however, a factory reset will clear your name so you must disable factor reset in any other program you upload. To disable Factory Reset:
    1. Open the sketch you are going to use for the Bluetooth controller.
    2. Find the line that looks like this:
      #define FACTORYRESET_ENABLE 1
    3. Change the “1” to a “0” to disable factory reset

Making it Robust using Prototyping Shield instead of Solderless Breadboard

The Solderless Breadboard is great for prototyping and testing, but as I have discussed , the first step to making a circuit robust and reliable is to move away from the solderless breadboard to some soldered installation. Since we are using Arduino, an Arduino Prototyping Shield is an excellent candidate.

Also, as I have discussed , you should hardly ever solder modules, such as the Bluetooth Friend, to anything. Instead, mount a header to mate with the module:

The holes next to the Arduino pins are connected by the Prototyping Shield to the Arduino pins, but the holes next to the header for the Bluefruit module must be done by hand. I like to put the wires on top, bring them down through holes near their destination, and then fold the wires over and solder to the appropriate pins:

Here is the final shield sitting on top of an Adafruit Motor Controller shield which is on top of an Arduino:

Save

Print Friendly
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Leave a Reply

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