Serial Lab 2

For this second serial communication lab, we had to send two different sensor readings from the Arduino to Processing. First, I attached three different sensors to the Arduino and created a string of numbers separated by a comma.

But, in this example, Processing can’t decide which reading correlates with which sensor. So putting a linebreak after the third reading solves this problem:

Next, the code is sent to Processing using the “Serial” command. Processing reads the information using the serial library. From there, we can trim extra white space using the “trim” command, and we can split the three readings into an array using the “split” command.

From here, it’s easy: The sensor numbers can be used to control anything. Here, I’m controlling a little ball on the screen — it’s X and Y coordinates. (My third sensor was, uh, broken.)

The other way to do this is the “call and response” method. This seems simple: The Arduino doesn’t send any information over until it receives a byte from processing. This prevents information from getting backlogged in the queue. However, it was still a bit more complicated for me than using the punctuation method.

Leave a Reply