This chapter will give you a brief introduction to the Arduino and iOS platforms and the integration methods between them. Moreover, you will learn how to set up the development environments on both the platforms and get them ready for the projects in the following chapters.
We will assume that you already have some basic knowledge of the two platforms and electronics, and you are able to build a circuit, at least by using a breadboard. However, the main subject of the chapter is to learn how to integrate the two platforms together.
Arduino has been an Open Hardware device since its early origin, and you can easily find any kind of information you need about it. Conversely, the iOS platform is not very open, especially from the hardware point of view. You cannot design and build a hardware device that works with iOS devices without joining an Apple dedicated program (MFi). The program has strong requirements that only large companies can fulfill.
More information on Arduino and iOS
Nevertheless, at the end of the chapter, you will learn how to transfer data between the two platforms in ways that also allow your applications to be sold on the iTunes App Store. This consists of nothing that is too complex. We are going to use TCP/IP or Bluetooth BLE.
The following are the topics that will be covered in this chapter:
Arduino UNO R3 (http://bit.ly/1IInOke).
A USB cable (A to B type).
A 9V external DC power supply (optional but recommended).
A Bluetooth BLE nRF8001 breakout board from Adafruit (http://bit.ly/1MvkyJm).
A digital multimeter (optional but strongly recommended).
A breadboard (the larger, the better).
Some tools (skewdrivers, pliers, tweezers, nippers, and so on).
Some Male/Male and Male/Female jumper wires (the more, the better; they are never enough!)
Some electronics components, which will be shown chapter by chapter.
A rover robot for a project in Chapter 5, TV Set Constant Volume Controller.
Buy original products only!
There are a lot of counterfeited Arduino products, especially online, that are sold for a few dollars. Apart from the moral considerations, an original product will provide you with much more quality and certainty to right functioning. Projects in this book are developed and tested on original products. You have been warned!
The official Wi-Fi Shield
The official Wi-Fi Shield is not cheap, and it can be tough to make it work with iOS sometimes. Many other products are cheaper. Some are compatible, others are not. If you choose to use a different Wi-Fi Shield, you need to be sure that it works with the Wi-Fi library that is included in the Arduino IDE. Otherwise, you will have to modify the Arduino code in this book on your own. You can also buy this Shield at http://bit.ly/1i5k1Cn.
Arduino.cc versus Arduino.org conflict
At the time of writing this book, Arduino split in two companiesâarduino.cc and arduino.org. They are in the middle of a legal battle, and there is a lot of confusion about products with the same name, which are sold by both the companies. Though the situation is getting clearer in USA and Asia, it is still unpredictable in Europe. In this book, we will be using the products and development environment from arduino.cc.
The Bluetooth Breakout board
The Bluetooth device that we chose has been tested many times on different projects and works well. There are many other devices that are available on the market and which can do exactly the same job. If you decide to use a different Bluetooth device, be sure that is a BLE (Bluetooth Low Energy) device, which is also known as Bluetooth 4.0, Bluetooth Low Energy and Bluetooth Smart. You can easily write iOS applications, which communicate through Bluetooth only if it is Bluetooth BLE.
The Apple development environment that is needed to write iOS applications (Xcode) is available only for the Mac OS X operating system (the 10.10.3 Yosemite version). So, you need a recent Intel-based Mac computer to run Yosemite.
Moreover, you need an iOS device (iPhone, iPad, or iPod touch) that runs iOS 8.4 and supports Bluetooth 4.0.
If you are already a member of the Apple Developer Program (ADP) for iOS (which costs about $99 per year), your life will be easy. Unfortunately, Apple doesn't allow you to upload programs that are written with Xcode to your own device if you are not a member of ADP. You can still run the programs in the device simulator, but it will not be able to simulate the Bluetooth BLE subsystem. This will be a problem for projects that use Bluetooth BLE. Anyway, adapting the code presented in this book to use Wi-Fi instead of Bluetooth BLE should not be too complex.
Xcode and the new Apple rules
At the time of writing this book, Apple announced a new version of iOS (version 9) and Xcode (version 7) that are now in their beta versions. Some restriction rules will be removed from these versions, and the user should be able to upload self-written apps to their own devices even if they are not subscribed to the Apple Developer Program.
As already mentioned, to write applications for the iOS platform, you need Xcode (6.4 at the time of writing this book) and some additional open source libraries that are available online. You will be instructed to download them when needed. Xcode runs exclusively on Mac with OS X (version 10.10.3 Yosemite or higher). Even if most of the code of this book can run on the previous versions of iOS, your iOS device has to be able to run iOS 8.3 and higher since it is the version that is used across the book.
You can find all the details about this device at http://bit.ly/1IInOke.
What makes it different from many other similar (or even more powerful) devices on the market is that it has a very simple development environment (IDE) and plenty of libraries, which allow you to make projects in a matter of hours. Most of these libraries are already available in the IDE or are very easy to add.
Arduino UNO â Arduino MEGA
In this book, we are going to refer to Arduino UNO. Many other boards from Arduino are available with different hardware characteristics, FLASH, and the RAM memory size. Most of the projects in this book will run on Arduino MEGA with no changes in their code and minor changes in hardware.
Every few weeks, a new platform that is compatible with Arduino comes out. Two of these platforms, which are known to be compatible with the projects in this book, are RFduino, which supports Bluetooth BLE without any additional hardware, (for more information, visit http://www.rfduino.com) and Teensy (to know more about Teensy, visit https://www.pjrc.com/teensy). Some changes in hardware and/or software may be necessary to work with these platforms.
You can use the following steps to have the development environment ready in minutes:
Make sure that you have installed an application that can open a ZIP file. If you don't have such an application, you can find them available for free on the App Store (The Unarchiver may be an option, which can be downloaded from http://apple.co/1gT7W2D).
Download Arduino IDE 1.6.4 from http://bit.ly/1gT8u8E.
Usually, the browser will download the file in your
Downloadsfolder. Open this folder and unzip the ZIP file (
Arduino.appfile to your app folder.
The development environment is now ready to run.
Just to be sure that everything is working as expected, upload one of the included examples (Blink is fine) to your UNO. Refer to http://bit.ly/1KsUhqv in order to properly configure the board and port in the IDE.
The IDE version to use
The code in this book was tested with IDE 1.6.4, which is the latest version that is available at the time of writing this book. Even if a new version of the IDE is available, you should use the suggested version. The libraries that are included in different versions of the IDE usually vary, and this may cause unexpected behavior. You can test a newer IDE once you have completely built and tested the project on Arduino and iOS.
In the last few years, commonly named smartphones have become the most used personal devices. iPhone is one of the most used smartphones all over the world, and iPads have replaced personal computers in many cases.
iPhone, iPad, and iPod touch run the same operating system, which is called iOS. They have a neat and homogeneous user interface, which allows its users to interact with the device through simple gestures (such as tapping and double-tapping the screen) or complex gestures (such as swiping or pinching the screen).
Applications that run on both iPhone and iPad can be easily written with minor changes, and the platforms are so powerful that almost any application can run on them.
We can directly go to the process of installing the development environment so that we can start having fun with iOS and Arduino.
Open the App Store application. Usually, you will find it in the Dock. Alternatively, you can run it from Launchpad or by navigating to Finder | Applications | App Store.
Connect to the App Store by using your account (browse Store | Sign in).
Locate Xcode (navigate to Categories | Developer Tools or search for it).
Click on the Get button to start downloading.
iOS is not so open platform, especially from the hardware point of view. Apple requires that the hardware devices connected to iPhone or iPad should not only be compliant with straight requirements, but also be certified by Apple itself. For this, they need to join an Apple dedicated program (MFi: http://apple.co/1PwSeWO). The requirements to join the program are very tight, and only a large company can fulfill them.
Nevertheless, Apple allows the use of TCP/IP and Bluetooth BLE to communicate with any external device. These are the two methods that we are going to use all over the book to transfer data with Arduino. On Arduino's side, we have to choose additional hardware that is compatible with these two methods or, in a more technical jargon, these two protocols.
Arduino provides the following two Shields for TCP/IP communication:
The Ethernet Shield
The Wi-Fi Shield
Both these Shields include an SD card bay to store data.
The Ethernet Shield is relatively cheap and very reliable. Since it uses an Ethernet connection, it's drawback is that it needs physical wiring to your home network or router. This reduces the flexibility of your projects.
The other connection method (protocol) that is allowed by Apple to transfer data to and from external devices is Bluetooth BLE (also known as Bluetooth 4.0). This protocol consumes less energy, but it's not compatible with the previous versions. If your iOS device is quite new, Bluetooth BLE will be supported. Please check this out on your device page at the Apple site.
BLE supporting devices
If you wish to check whether a device supports BLE, visit http://bit.ly/1blI106.
You can learn more about Bluetooth 4.0 by visiting http://bit.ly/1Pj9caw.
You may wonder which is the best communication method for iOS and Arduino. There is no right answer. This actually depends on your project and your requirements. The following table shows the main pros and cons of each method:
In this chapter, you mainly learned the basics of integrating the Arduino and iOS devices. In the following chapters, you will learn how to write code for this integration in practice.
Moreover, you installed the Arduino IDE to write and upload programs to Arduino and Xcode to write and upload programs to your iOS devices.
So, sit back. We just got the ball rolling! Let's get rolling!