Introduction: Wireless Arduino Control Using the BeagleBone Black or Raspberry Pi

Introduction

If you have been looking for an easy and inexpensive way to wirelessly integrate an Arduino and a BeagleBone Black (BBB), or Raspberry Pi (RPi) look no further, this tutorial will show you how!

What You Will Need

  1. A BeagleBone Black Microcontroller with the Debian 2014-05-14 image installed or RPi with wheezy installed.
  2. An Arduino Mirocontroller.
  3. An HC-06 Bluetooth Slave Module.
  4. A Plugable USB-BT4LE Bluetooth 4.0 USB Adapter
  5. Three 1k Ohm resistors.
  6. A copy of the PyMata software library, version 1.58 or greater.
  7. An external 9 volt power source for Arduino.
  8. An external 5 volt power source for BeagleBone Black or RPi.

Step 1: Using the Arduino to Program the HC-06 for 57600 BPS

Why Change Speed?

The HC-06 has a default baud rate of 9600 bps. Since we will be running PyMata on the BBB to control the Arduino, we will need to change the speed of the HC-06 to 57600.

Wiring Up - Preparing to Program the HC-06

Wire the HC-06 as shown in the illustration above with the following temporary exceptions:

  1. The blue wire that's connected to pin 1 (TxD) of the Arduino in the diagram, should be moved to Pin 4.
  2. The yellow wire connected to pin 0 (RxD) of the Arduino, should be moved Pin 3.

3.3 Volts?

Make sure that you connect the HC-06 VCC pin to the 3.3 volt pin of the Arduino, since the HC-06 is a 3.3 volt device. Also, make sure that you create the voltage divider using the three 1k Ohm resistors. The divider is needed because Arduino output pins provide 5 volts and not the 3.3 volts the HC-06 require. If you were to connect the Arduino TxD pin to the HC-06 RxD pin without the divider, you might damage the HC-06.

Ready, Set, Program !

Others have written articles about programming the HC-06, and so as not to duplicate their fine efforts, here are 2 excellent links:

The first reference provides a link to a sketch that I used to program my HC-06.

HC-06 Bluetooth Module – Getting this sucker into AT Command Mode

Modify The HC-05 Bluetooth Module Defaults Using AT Commands

Once the programming is complete and you are satisfied with its success, return the blue and yellow wires to their original positions as shown in the illustration. Also, disconnect the USB cable from the Arduino and power the Arduino with an external 9 volt power source. This is to prevent having a signal conflict between the USB interface and the HC-06 device for Arduino pins 0 and 1.

Step 2: Configuring the BBB or RPi for Bluetooth Operation

Let's get started:

I will use the word device to mean either the BBB or RPi in the following discussion

  • Disconnect the USB cable and/or power from the device.
  • Plug the USB Bluetooth Dongle into the device.
  • Connect an Ethernet cable to the device.
  • Power the device using an external 5 volt supply.
  • "ssh" into the device from your PC by typing the following:
 ssh root@YOUR_BBB_IP_ADDRESS

for RPi use:

ssh pi@YOUR_RPI_IP_ADDRESS
  • Make sure the Dongle is recognized by entering the following command:
lsusb
  • You should see an entry that looks something like the following for the Dongle:
Bus 001 Device 002: ID 0a5c:21e8 Broadcom Corp.
  • Do an apt-get update
sudo apt-get update
  • Install the bluez package
sudo apt-get install bluez
  • After installation, the bluetooth service should have started and you will see a screen that looks like:
root@beaglebone:~# service bluetooth status

bluetooth.service - Bluetooth service
	  Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled)
	  Active: active (running) since Wed, 14 May 2014 22:19:00 -0400; 4h 15min ago
	Main PID: 594 (bluetoothd)
	  CGroup: name=systemd:/system/bluetooth.service
		  └ 594 /usr/sbin/bluetoothd -n
  • Make sure that the HC-06 is powered up. Its LED should be blinking.
  • To find the HC-06 MAC address, type the following (this may take a few moments):
sudo hcitool scan

Write down the mac address. We will need it for the next step.

Using you favorite text editor, open up /etc/bluetooth/rfcomm.conf and modify it as follows:

# RFCOMM configuration file.
rfcomm0 {

     # Automatically bind the device at startup for BBB or no for RPi
     bind yes; 
     #bind no;

     # Bluetooth address of the device
     device THE_MAC_ADDRESS_FROM_HCITOOL_SCAN;

     # RFCOMM channel for the connection
     channel 1;

     # Description of the connection 
     comment "HC-06";
}
  • Save and close the file.
  • Pair the Dongle with the HC-06. This command is being issued in the background by the "&" appended at the end of the command. 1234 is the default pairing address used by the HC-06.
sudo bluetooth-agent 1234 &
  • Finally connect your device to rfcomm, using the mac address you wrote down above. Notice that this command is run in the background, as was the previous command:
sudo rfcomm connect hci0 DEVICE_MAC_ADDRESS &
  • You are now ready to use Bluetooth.
  • From this point forward, to start Bluetooth , you only need to type therfcomm connect command.

Step 3: Installing PyMata on the BeagleBone Black or Raspberry Pi and a Firmata Sketch on the Arduino

Installing PyMata on the BeagleBone Black or Raspberry Pi

  • Go to https://github.com/MrYsLab/PyMata and download the latest version of PyMata onto your BBB or RPi.
  • Unzip the file, and install the library described in PyMata_Install_Instructions.pdf, located in the PyMata documentation directory.

Installing a PyMata Compatible Sketch on the Arduino

  • Temporarily remove the HC-06 leads from pin 0 and 1 of the Arduino and reconnect the USB cable to the Arduino.
  • On your PC, install the Arduino libraries located in the PyMata ArduinoSketch directory as described in PyMata_Install_Instructions.pdf
  • Upload FirmataPlus to the Arduino.
  • NOTE FOR LEONARDO USERS: You must upload FirmatPlusLBT for Bluetooth operation instead of FirmataPlus.
  • Remove the USB cable and reattach the leads to pin 0 and 1.

Step 4: Running a Quick "Hello World" LED Blink Test

On the BBB or RPi, go to the PyMata examples directory and using your favorite editor, open pymata_blink.py. Modify the existing code from:

#  Create a PyMata instance using the Arduino COM Port as the input parameter
firmata = PyMata("/dev/ttyACM0")

to:

#  Create a PyMata instance using the Arduino COM Port as the input parameter
firmata = PyMata("/dev/rfcomm0")

And finally, to start the script, on the BBB and blink the LED on the Arduino, type: python ./pymata_blink.py

python ./pymata_blink.py


PyMata version 1.58  Copyright(C) 2013-14 Alan Yorinks    All rights reserved.
<p>Opening Arduino Serial port /dev/rfcomm0 <br>Please wait while Arduino is being detected. This can take up to 30 seconds ...
Board initialized in 0 seconds
Total Number of Pins Detected = 20
Total Number of Analog Pins Detected = 6
Blinking LED 13 10 times
1
2
3
4
5
6
7
8
9
10
PyMata close(): Calling sys.exit(0): Hope to see you soon</p>

There are some time delays involved, so be patient while this script runs. You may see some exceptions after PyMata close(). If you do, these can be ignored.

Step 5: If You Need Help

If you have any comments, or questions, please contact us at:

MisterYsLab@gmail.com