Arduino iOS Blueprints

4 (1 reviews total)
By Fabrizio Boco
  • Instant online access to over 8,000+ books and videos
  • Constantly updated with 100+ new titles each month
  • Breadth and depth in over 1,000+ technologies

About this book

Arduino and iOS devices have reached wide popularity due to their simple way of use and flexibility. Hence, their integration opens up new opportunities, allowing everyone to build devices that are extremely useful in everyday life.

You will first learn how to control Arduino from an iPhone or iPad by writing the Arduino sketch, the iOS application, and integrating everything together via Wi-Fi or Bluetooth BLE. You will then learn about various components that interact with the Arduino such as digital and analog I/O, Wi-Fi shield, Bluetooth BLE, SD card, OneWire, I2C, and so on. You will also learn about iOS, which includes the development of an application from scratch, GUI design and MVC, UIKit, iOS sensors, TCP and Bluetooth BLE communication, and more.

All the projects are described in detail, providing you with a learning tool, not just some sketches or some iOS code to copy.

Publication date:
September 2015
Publisher
Packt
Pages
240
ISBN
9781785283666

 

Chapter 1. Arduino and iOS – Platforms and Integration

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.

Tip

More information on Arduino and iOS

More information on Arduino and iOS development can be found at http://www.arduino.cc and http://apple.co/1HThS1O respectively.

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:

  • Hardware and software requirements

  • Arduino and the development environment setup

  • iOS and the development environment setup

  • Communication methods between the Arduino and iOS devices

 

Hardware and software requirements


To implement all the projects in this book, you will need some hardware and software components, which can be easily bought from any of your local stores or over the Internet.

Hardware requirements for the Arduino platform

To execute the projects in this book, you mainly need Arduino UNO and the following additional hardware components:

  1. Arduino UNO R3 (http://bit.ly/1IInOke).

  2. A USB cable (A to B type).

  3. A 9V external DC power supply (optional but recommended).

  4. An official Wi-Fi Shield (http://bit.ly/1UQgq9v, http://bit.ly/1i5k1Cn).

  5. A Bluetooth BLE nRF8001 breakout board from Adafruit (http://bit.ly/1MvkyJm).

  6. A digital multimeter (optional but strongly recommended).

  7. A breadboard (the larger, the better).

  8. Some tools (skewdrivers, pliers, tweezers, nippers, and so on).

  9. Some Male/Male and Male/Female jumper wires (the more, the better; they are never enough!)

  10. Some electronics components, which will be shown chapter by chapter.

  11. A rover robot for a project in Chapter 5, TV Set Constant Volume Controller.

  12. An iBeacon for a project in Chapter 6, Automatic Garage Door Opener (http://apple.co/1GXnt7Z).

Tip

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.

Software requirements for the Arduino platform

All that you need is Arduino IDE 1.6.4, the libraries included in the IDE, and some additional libraries that are available online. You will be instructed to download them when needed.

Hardware requirements for the iOS platform

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.

Tip

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.

Software requirements for the iOS platform

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.

 

Arduino and the development environment setup


Arduino is a very basic but powerful microprocessor board. It allows you to acquire digital and analog inputs, process them, and control external devices.

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.

Tip

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.

Other platforms

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.

IDE installation

The process of installing the IDE is very quick and easy, especially because you don't need to install additional drivers on OS X.

You can use the following steps to have the development environment ready in minutes:

  1. 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).

  2. Download Arduino IDE 1.6.4 from http://bit.ly/1gT8u8E.

  3. Usually, the browser will download the file in your Downloads folder. Open this folder and unzip the ZIP file (Arduino-1.6.4-macosx.zip).

  4. Move the Arduino.app file 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.

Tip

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.

 

iOS and the development environment setup


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.

Xcode installation

You can perform the following steps to install Xcode in minutes:

  1. 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.

  2. Connect to the App Store by using your account (browse Store | Sign in).

  3. Locate Xcode (navigate to Categories | Developer Tools or search for it).

  4. Click on the Get button to start downloading.

In a short span of time, the application will be downloaded and installed (depending on the speed of your Internet connection).

 

Communication methods between Arduino and iOS devices


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.

Conversely, the Wi-Fi Shield allows you to install your Arduino board everywhere in your house without the awkwardness of wires. This is the reason why we chose to use the Wi-Fi Shield in this book.

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.

Tip

BLE supporting devices

If you wish to check whether a device supports BLE, visit http://bit.ly/1blI106.

Arduino doesn't provide a Bluetooth BLE Shield, but other vendors do. We chose the Bluetooth BLE nRF8001 breakout board from Adafruit.

Tip

Bluetooth 4.0

You can learn more about Bluetooth 4.0 by visiting http://bit.ly/1Pj9caw.

TCP/IP versus Bluetooth

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:

Method

Pros

Cons

Wi-Fi

  • Arduino can be located almost everywhere in your house.

  • The iOS device can be everywhere (if the network is properly set, even on the other side of the world).

  • An SD card can be used to store data.

  • This is expensive.

  • Even if data could be transferred with up to 54 Mbps, the Wi-Fi Shield is not so responsive in transferring data.

  • The power consumption is so high that you cannot use a battery to power Arduino and the Wi-Fi Shield.

Bluetooth

  • Arduino can be located almost everywhere in your house.

  • BLE devices consume much less power. So, a battery can be used to power it.

  • Data transfer speeds reach up to 1 Mbps but with no latency.

  • The iOS device has to be near Arduino (about 100 meters; lesser for indoors).

  • No SD card is available on the board if you wish to store additional data.

 

Summary


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!

About the Author

  • Fabrizio Boco

    Fabrizio Boco was born in Italy in 1964. He started with electronics when he was a teen and with programming in 1980. In 1992, he received his degree in electronics engineering. Currently, he is a freelance IT manager and architect and has more than 20 years of experience in consulting for private and public companies in Italy. Even when he occupied executive positions, he worked on the design and implementation of IT projects (mostly on enterprise applications, data warehousing, and business intelligence). He has been an iOS developer since 2009, and he has designed and developed Arduino Manager, which is an iOS, Mac OS X, and Android application that can be used to control Arduino (and Arduino-compatible) boards through a powerful and easy-to-use interface, that is based on more than 20 specialized widgets (a switch, knob, display, and gauge, among others). Fabrizio believes that his engineering skills are hardcoded within his DNA; the studies and experiences only completed them.

    Browse publications by this author

Latest Reviews

(1 reviews total)
I purchased the book after finding one of the projects online. Only after reading the book I found there are additional requirements I probably can't meet. It would be nice the online project had the requirements mentioned.
Book Title
Unlock this full book with a FREE 10-day trial
Start Free Trial