A Simple Serial Application

Our first application making use of the serial cable will be a simple serial terminal, replicating the functionality of the serial console in the Arduino development environment. Open Xcode, choose to create a new project, select a View-based Application for the iPhone, and when prompted name it “SerialConsole” and save it to the Desktop.

Let’s start by building our interface. Click on the SerialConsoleViewController.xib file to open it in Interface Builder. Open up the Utilities pane and then drag and drop a UINavigationBar, UITextField, UIButton, and a UITextView into the View from the Object library. Arrange them in a fashion similar to Figure 2-9.

Building the SerialConsole app’s user interface

Figure 2-9. Building the SerialConsole app’s user interface

We’re going to make use of the real estate offered by the navigation bar later in the chapter to add a UIBarButtonItem. But for now, change the title text to read “Serial Console,” and we’ll come back to it later on.

Finally, select and delete the Lorem ipsum text from the UITextView, and uncheck the Editable checkbox in the Attributes tab of the Utilities pane so that users won’t be able to obscure the view of the text window by accidentally popping up the keyboard.

Close the Utilities pane and open the Assistant Editor, making sure it’s set to Automatic and is displaying the SerialConsoleViewController.h file.

Then Ctrl-click and drag from the UITextField ...

Get iOS Sensor Apps with Arduino now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.