Lab 4: Two-way serial communication

When reading multiple sensors a question that comes up is “which value corresponds with which sensor?” There are two ways to set sensor values in order: punctuation method, which involves punctuating each set of data uniquely, and call-and-response (handshake) method, which works very much like it sounds, sending one set of values at a time by setting the programs to call and respond to each other.

We tried each method in this lab, neither worked very well for me. And I have a lot of questions regarding the additional code.

This is what I’ve learned so far:

Punctuation method

To send data from the Arduino, we use Serial.print() and Serial.println() to send out each set of values, separated by commas Serial.print(“,”);.

To receive the values in Processing, we add myPort.bufferUntil(‘\n’); in setup() so that the string of values would be saved to the buffer and read together. In the serialEvent() function, the string is read with myPort.readStringUntil(‘\n’);. Then trim out any whitespace character (newline, carriage returns, spaces, tabs) with trim(stringx), split the values at each comma with split(stringx, ‘,’);, convert the values into integers and store them in an array, for instance int sensor[] = int(split(stringx, ‘,’));.

There are a few downsides to this method, namely the program may slow down if the buffer is full and that we can’t easily send binary values.

Call-and-response method

In the Arduino IDE, we setup a new function establishContact(). This function sends out a message until receives data from Processing. We check for data by checking whether Serial.available() is greater than 0 (true) or less then/equal to 0 (false). We call for this new function in setup(). Then, with an if statement, make sure that the strings of values in loop() would only send when Serial.available() is greater than 0.

In Processing, we check for contact with a new variable boolean firstContact = false;. In serialEvent() we let the program first check if the message from the Arduino is the right one with myString.equals(), then send back a character with myPort.write() to start receiving actual data. If firstContact is true, the code from the rest of serialEvent() would run, trimming, splitting, converting, and storing the values.


  • With the lab (make a simple DIY mouse), my digital input worked well, allowing the ball to appear and disappear from the screen. But with the ball fluttered about when I moved the accelerometer. Instead of moving on the x and y axis smoothly, the ball was all over the place.
  • Often the program didn’t even run. It displayed an error message.
Error message in Processing.

Error message in Processing.


  • Why is the call-and-response method better for sending binary data, even though it’s also sending and receiving strings with commas, then trimming, splitting, and storing them in a buffer? Also, wouldn’t this also slow down the program if the buffer gets full?
  • Why do we need to call-and-respond between the programs?
  • Explain more about the new functions in Arduino IDE and Processing. e.g. Serial.available(), trim(), split(), myPort.bufferUntil(), myPort.readStringUntil(), myString.equals(), etc.
Values show up properly in the Arduino IDE serial monitor.

Values show up properly in the Arduino IDE serial monitor.

Digital input works. Issues with analog input values.

Digital input works. Issues with analog input values.

Lab 4: Serial Communication

This week in P Comp, we are learning about serial communication. Serial communication is a way to allow computers to talk to each other. This is very exciting because we can now start to create projects where physical interfaces interact with interfaces on the screen and we can start to think about how a network of connected physical objects can be controlled through one computer. At the same time there are a lot of materials covered this week and after going over the videos and labs I’m filled with questions.

What I’ve learned so far:

Serial communication works by sending a series of digital pulses back and forth between devices. In order for these two devices to communicate they need to agree on three things: the rate at which data is sent and read, the voltage levels that would represent 1 and 0 bits, and the meaning of the voltage levels (does 1 mean high and 0 mean low or reversed). Serial communication protocol defines the structure of communication. It’s kind of similar to facilitating a conversation between two people.

The Arduino uses a USB-to-serial converter so that the USB connection would show up as serial port on the computer. The serial port can only be controlled by one program at a time. So if I have the serial monitor open in the Arduino IDE, I need to close it to run my Processing sketch that also use the serial port. Aside from Processing, any other environment (?) that can access the serial port can also be used to communicate with the Arduino. The physical connection happens through three lines: the transmit (Tx) to receive (Rx) line, the Rx to Tx line, and the ground line.


There is an area in the processor’s memory where incoming data from the serial port is stored. This is the serial buffer. I used this in the lab to smooth out signals from Arduino IDE (?) by storing data in to strings and sending them only after the end of a line.


  • The graph from the Serial to Processing lab looked quite different for mine. I’m not sure whether it’s because I used a different sensor. The graph had started looking smoother (with each line touching) but after I changed something in the code a gap showed up between each line.


  • Other devices connecting with the Arduino vs. connecting directly with a computer. What are some examples of application for both methods?
  • Explain more about serial buffer.
  • Why can only send 1 byte with Serial.write() but Serial.println() can send more than 1 byte?
  • Explain more about the difference between RS-232 and USB.
The ball didn't respond the first time I tried, because I had called Serial.println() instead of Serial.write().

The ball didn’t respond the first time I tried, because I had called Serial.println() instead of Serial.write().

Different formats (HEX, binary, ASCII) of the same data can be read through CoolTerm.

Different formats (HEX, binary, ASCII) of the same data can be read through CoolTerm.

There is a gap between each line, instead of producing a smooth graph.

There is a gap between each line, instead of producing a smooth graph.





Memories without a cause

On the third class at ITP Ziv was in To Remember and to Forget.

System for remembering

System for remembering


Memories are often purposeful, sometimes to confirm, to identify, to justify, to bond, to understand ourselves and others. But once in a while I have a flashback triggered by something I see or hear or smell or maybe feel at a given moment. I don’t know why I remember such events. They have no purpose. They come and go as they please without any of my conscious efforts. Usually they come as a short scene, like a clip from a movie I’ve seen long ago.

Someone in some place at some time doing something or saying something.

Can I capture these memories in a system as it happens or at least right after it happened, so that it leaves a darker mark in my subconscious. Can I add to it, by allowing others present to add details, to even alter this memory? Can I embed a memory of an event that I didn’t even notice at the time?

In this project I attempt to capture details of an event from multiple people from multiple sides and recombines details into different narratives of the same event. The categories for these details are seemingly rigid and conventional: who, what, where, when. But it is really as rigid and conventional as language and as the people involved can be. For instance “when” can be “September 26th, 2014” or it can be “when she passed slowly by my desk” (which can also be a what depending on the person). The only restriction is that there is no more than six details for each category. These details are then assembled back together by a rubix cube, fitting disparate elements into one narrative or pattern, then repeating this over and over to produce different memories of the same event.

I tried this very quickly in class when I presented the project: to remember that moment as an event to be saved in my memory. I think it was a success. I actually can recollect a lot of details from that seemingly mundane moment. I remember everyone who had wanted to be added to the “who” category, even though I had never spoken to any of them in the past, aside from Taeyoon. I remember seemingly random details from that class, like Taeyoon wondering about whether mice have an innate fear of cats. And these memories in turn altered my interaction with the people that I remember.