Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

1. Introduction to the Arduino > Making a Serial Connection

Making a Serial Connection

Now that we’ve seen how a basic Arduino sketch works, let’s move on to sending and receiving data from the Arduino board. We’ll need to know how to do this because this is how we’ll control the Arduino or get sensor readings from it when we connect it to our iOS device. For now, however, we’re going to use the Serial Monitor (see Figure 1-7 again), inside the development environment.

Open a new sketch by clicking FileNew (⌘N) to open a new window:

void setup() {
  Serial.begin(9600);1
}

void loop() {
  while (Serial.available() <= 0) {2
    Serial.println("Hello world");3
    delay(300);
  }
}
1

Sets the data rate in bits per second (baud) for serial data transmission.

2

Here we get the number of bytes available for reading from the serial port. If there are no bytes waiting in the buffer, we loop until some arrive.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint