Click here to Skip to main content
15,353,757 members
Articles / Internet of Things / Arduino
Article
Posted 15 Jun 2015

Stats

20.3K views
2 bookmarked

Communicate to Arduino code with your Android Phone by Bluetooth Serial Port Profile (SPP) on Intel® Edison

15 Jun 2015CPOL5 min read
In Arduino environment, it's convenient to access BT SPP like a serial port and react to the command string sent from the BT serial port.

This article is in the Product Showcase section for our sponsors at CodeProject. These articles are intended to provide you with information on products and services that we consider useful and of value to developers.

Get access to the new Intel® IoT Developer Kit, a complete hardware and software solution that allows developers to create exciting new solutions with the Intel® Galileo and Intel® Edison boards. Visit the Intel® Developer Zone for IoT.

In Arduino environment, it's convenient to access BT SPP like a serial port and react to the command string sent from the BT serial port. Many Arduino projects have utilized this way to allow remote control for their projects. In the past, you'll need additional BT shield or BT kit to archive it on Intel® Galileo. Now, since we have built-in BT support on Intel® Edison, you can use Edison module with Arduino breakout board to do it. NO additional BT shield is required!

Image 1

Requirements

  • An Android* phone or tablet running Android and has Bluetooth.

  • Connect your Intel® Edison board to a Wi-Fi* network, see Get started with Intel® Edison technology. Specified a name for your Edison, for ex: myedison.

  • SCP using a host computer connected to the same network

  • Establish a terminal to your board either Via Serial port or SSH.

Background

Connecting the Intel® Edison board to your Android* Phone with Serial Port Profile (SPP) describes how to connect your Edison board to Android* Phone with SPP, however, you cannot get the input from SPP in your Arduino code. In Connecting to Intel® Edison from Android* with Bluetooth* LE (BLE) describes a way to access BT via Arduino code but additional BT shield/kit is required.

Since we have built-in BT, why don't we just take the advantage of it? Here I provide an example library to do that.

One efficient way to communicate between Arduino and Linux in Intel® Edison is to use mmap(). See Efficient communication between Arduino* and Linux native processes. However, it's not easy to use the in-memory shared lock between python process and Arduino process.

So I choose named pipe as a simple way to implement IPC between Arduino sketch process and BT SPP python service process.

Setup for Edison Bluetooth service

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

2. Copy bluetooth-service.tar.gz to /home/root/Bluetooth and extract it

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

3. Copy bluetooth-spp-pin.service to /lib/systemd/system/

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

4. Enable the systemd service

systemctl enable bluetooth-spp-pin

5. Reboot your device

reboot

6. Double check the service

systemctl status bluetooth-spp-pin

Setup for Edison Arduino sketch

1. Download the library Intel-Edison-BT-SPP-Library.zip.

2. Extract to your Arduino library path, ex: C:\Users\username\Documents\Arduino\libraries, check it in your Arduino IDE, File->Preferences->Sketchbook Location

3. Restart your Intel® Arduino IDE v1.6.0 or later version

4. Open the example bt_test under File->Examples->Intel Edison BT SPP Driver Library

5. Verify and Upload the sketch to your Edison

6. Open Serial Monitor so we can check the output after we send something to it.

Setup for your Phone

1. Download and install any BT SPP APP from PlayStore. For ex: BLE_SPP_PRO.

2. Turn on BT on your phone and connect to your Edison module

3. Enter the PIN code, the default PIN is 8888, feel free the change it later at line 70 of bluetooth-pin-service.py

4. Connect to your Edison in the APP, for ex: myedison

5. Send something to your Edison, you should be able to see the result on Serial Monitor of Arduino IDE

Image 2

Image 3

Conclusion

Now you have a fixed PIN BT device which support SPP. So you can connect to it very easily just like you connect to your BT speaker. The BT works after boot automatically, and you don’t need to pair the device via terminal. You can access BT SPP in your Arduino code, treat it as a serial device and connect to your Edison project via Android phone with BT SPP App. This means you can control your Edison projects remotely to do whatever you want. Base on this work, you can develop a lot of interesting applications with build-in BT function of Intel® Edison. Have fun and do share your projects with us!

Next steps

So far we only implemented the way to send command from your BT SPP device to Edison. You can add additional fifo to send command from Edison back to your BT SPP device. Since it’s a fifo, your applications under Linux can also take the advantage to send command to Arduino environment through it. It’s really a simple and easy way to increase more possibility to have versatile ways to interact with Arduino. For ex, you can process the audio in Linux and send the command to Arduino through this fifo. Or, you can get a twits from Node.js and then send the JSON to Arduino code to interact with your existing Arduino shields. Now everything is connected! You can also write your own Android BT SPP application do more interactions!

Intel® Developer Zone for IoT

Start inventing today with the Intel® IoT Developer Program which offers knowledge, tools, kits and a community of experts to quickly and easily turn your innovative ideas into IoT Solutions.

Dream it, Build it with the Intel® IoT Developer Kit for Intel® Edison and Intel® Galileo platforms. These kits are versatile, performance-optimized and fully integrated end-to-end IoT solutions supporting a variety of programming environments, tools, security, cloud connectivity and hardware.

For more resources and to learn how the new Intel® IoT Developer Kit v1.0 can help streamline your IoT projects:

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Intel
United States United States
You may know us for our processors. But we do so much more. Intel invents at the boundaries of technology to make amazing experiences possible for business and society, and for every person on Earth.

Harnessing the capability of the cloud, the ubiquity of the Internet of Things, the latest advances in memory and programmable solutions, and the promise of always-on 5G connectivity, Intel is disrupting industries and solving global challenges. Leading on policy, diversity, inclusion, education and sustainability, we create value for our stockholders, customers and society.
Group type: Organisation

42 members


Comments and Discussions

 
-- There are no messages in this forum --