Connecting an Arduino program on Intel Edison with an Android phone via Bluetooth SPP (Serial Port Profile)

Original author: FRANKY H.
  • Transfer
  • Tutorial
In an Arduino environment, it’s convenient to access Bluetooth with the BT Serial Port Profile (BT SPP) profile to respond to commands sent through the Bluetooth serial port. Many Arduino projects use this feature to remotely control the device. Previously, you needed an additional Bluetooth shield or Bluetooth kit to get this feature on Intel Galileo. And since Intel Edison now has built-in Bluetooth support, it’s easy enough to use an Arduino adapter to create such an Arduino device. No additional shields are required.



We will need:


  • Android phone or tablet with Bluetooth.
  • Wi-Fi-connected Intel Edison board, as written in Get started with Intel® Edison technology . Name the Edison board, for example, myedison.
  • SCP program on a host computer that is connected to the same network.
  • Configured terminal access to your board via serial port or SSH.

The basics


The article “Connecting the Intel Edison board to your Android Phone with Serial Port Profile (SPP)” describes how to connect the Intel Edison board to an Android phone with SPP. However, you will not be able to receive data from SPP in Arduino code. The article “Connecting to Intel Edison via Android with Bluetooth LE (BLE)” explains how to connect Bluetooth via Arduino, but an additional Bluetooth shield was required there.

But since we have built-in Bluetooth, why not take advantage of this? Here I offer an example library to do this.

One effective way to communicate between Arduino and Linux on Intel Edison is to use mmap (). We talked about this in a previous articleEffective interaction between native Arduino and Linux processes . However, it is not at all easy to use a lock in shared memory between the python process and the Arduino process.

Thus, I chose named pipes as the simplest way to organize IPC (interprocess communication) between the Arduino sketch process and the Python process with Bluetooth SPP.

Install Edison Bluetooth


1. Download the bluetooth-service.tar.gz file .

2. Copy the bluetooth-service.tar.gz file to the / home / root / Bluetooth folder and unzip:

mkdir /home/root/bluetooth
cd /home/root/bluetooth
mv /home/root/bluetooth-service.tar.gz ./
tar -xvf bluetooth-service.tar.gz

3. Copy the bluetooth-spp-pin.service file to the / lib / systemd / system / folder:

cp bluetooth-spp-pin.service /lib/systemd/system

4. Enable the systemd service:

systemctl enable bluetooth-spp-pin

5. Restart your device:

reboot

6. Check the service again:

systemctl status bluetooth-spp-pin


Install Arduino sketch on Edison


  1. Download the Intel-Edison-BT-SPP-Library.zip library .
  2. Unzip the file into the folder with the Arduino libraries, for example, C: \ Users \ username \ Documents \ Arduino \ libraries. You can check the path in the Arduino IDE development environment under File-> Preferences-> Sketchbook Location.
  3. Restart your Intel® Arduino IDE version 1.6.0 or higher.
  4. Open the bt_test example from File-> Examples-> Intel Edison BT SPP Driver Library.
  5. Check and upload your sketch to the Edison board.
  6. Open Serial Monitor to check the output after we send something.

Customize your phone


  1. Download and install any BT SPP app from the PlayStore. For example, BLE_SPP_PRO .
  2. Turn on Bluetooth on your phone and join your Edison module.
  3. Enter the pin code, by default it is 8888. In the future it can be changed on line 70 in the bluetooth-pin-service.py file.
  4. In the application, connect to your Edison (myedison) board.
  5. Send something to Edison, you should see the result of the Serial Monitor in the Arduino IDE.





Conclusion:


You now have a fixed-pin Bluetooth device that supports SPP. You can connect to it as easily as to Bluetooth speakers. Bluetooth will work automatically immediately after turning on, and you don’t even need to connect to the device through the terminal. You can access BT SPP in your Arduino code by treating it as a serial device. And he will join the Edison project through an Android phone with BT SPP application. This means that you can manage your Edison project remotely and do what you want. Based on this work, you can develop a large number of interesting applications using the built-in Bluetooth on Intel Edison. Have fun and share your projects with us.

Next steps:


So, we just implemented a way to send commands from your BT SPP device to Edison. You can add fifo to send commands from Edison back to your BT SPP device. Since this is fifo, your Linux application will also benefit by sending commands to the Arduino environment. This is a really easy way to increase your interaction with Arduino. For example, you can process sound in Linux and send commands to the Arduino through fifo. Or you can get tweets from Node.js and then send JSON to Arduino to interact with existing Arduino shields. Now everything is connected! You can also write your own Android BT SPP app with more interactivity!

Also popular now: