Frontier Nerds: An ITP Blog

Bargaining Chip

Eric Mika

On the back of a Max Sonar Ultrasonic Range Finder:

Max Sonar Jesus Fish

Lab: Serial Duplex

Eric Mika

Another serial lab, this time about duplex: handling multiple inputs at once.

I don’t have an accelerometer handy, and my ultrasonic sensor is giving weird values, so I went with two potentiometers as analog input. Uninspired, but workable.

An Arduino connected to a breadboard with two potentiometers and a button

The multi-format serial print program seems very handy. Shows a number of potential interpretations of the same serial data. Cornflake lets you toggle between different representations of byte data… but I couldn’t find a way to get everything side by side at once… maybe I overestimate how useful this is.

A screenshot of data streaming in from a serial connection

I’m keeping the code here for reference:

int analogPin = 0;
int analogValue = 0; // integer to print

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

void loop() {
// read the analog input, divide by 4:
analogValue = analogRead(analogPin) /4;

// print in many formats:

// Print the raw binary value analogValue
Serial.print(analogValue, BYTE);
Serial.print('\t');

// print the ASCII encoded binary analogValue
Serial.print(analogValue, BIN);
Serial.print('\t');

// print the ASCII encoded decimal analogValue
Serial.print(analogValue, DEC);
Serial.print('\t');

// print the ASCII encoded hexadecimal analogValue
Serial.print(analogValue, HEX);
Serial.print('\t');

// print the ASCII encoded octal analogValue
Serial.print(analogValue, OCT);
Serial.println();

delay(10);
}

Back to the lab… how can we distinguish between multiple sensors sending back serial?

There are several techniques to choose from:

Punctuation

Put a character between each value, and then send a newline to terminate the “packet” of info. We always know that the first item in the sequence is sensor 0, the second is sensor 1, and so on.

Demo code worked fine, just had to set bgcolor and change the sensor mapping to work well with the pots instead of the accelerometer for which the code was intended. Also made a few aesthetic tweaks: noStroke() and smooth() keeps the ellipse looking nice, and moving background() out of the draw loop gives an etch-a-sketch effect well suited to the potentiometers.

(Worth noting: In Processing, setting myPort.bufferUntil('\n'); handily prevents serialEvent() from firing until a newline character is read.)

Call and Response (Handshaking)

Similar idea, but the Arduino waits for a message from processing before it sends data. More hassle than just sending the data perpetually, but maybe this makes sense when bandwidth is limited (wireless?) or your device has several different modes (e.g. send one byte from processing to request data from one sensor, then a different byte to get data from another sensor.).

Update:

The lab explains it… Call-and-response works well when you need to push around binary data. With punctuation only, you risk a collision between your punctuation values and the binary data. Also, if we’re reading data slower than it’s coming in, the buffer of unread serial data can get too long, which means there will be lag before the most recent data is read. (Investigate this further to figure out why, exactly, the draw() loop is a rotten place to write serial handling code.)

Lab: Serial Output

Eric Mika

Now for the serial output lab:

An Arduino with a potentiometer in front of a monitor displaying its output

Worked great, no issues. I got lazy and skipped the breadboard since the pot can plug right in to power / ground / analog without any additional components. I tweaked the Processing code to print a longer (wider) history of the output, and to draw the signal in a nostalgic shade of oscilloscope-green.

This is going to be very handy… it already went to good use when Arturo and I wanted to see what the output from some FSRs would look like in the context of our media controller project.

Capirinha

Eric Mika

Julio Terra and I put together a stop-motion video.

Sequential Story

Eric Mika

Poram and I undertook the illustration of an October 8th exchange on the ITP student email list, involving the theft and retrieval of a student’s mug.

Update: Get the backstory and ongoing drama surrounding Clay Shirky’s mug thievery at Sarah Dahnke official blog on the topic.

Sequential Story Part 1Sequential Story Part 2Sequential Story Part 3Sequential Story Part 4Sequential Story Part 5Sequential Story Part 6Sequential Story Part 7Sequential Story Part 8

Here’s the PSD File (~5 MB).

Many of the images used in the even frames were under a Creative Commons license.

Clay Shirky’s head: Pop!Tech T-Shirt Body: Lee-Sean Here Comes Everybody book cover: Serdal Masking tape: Bixentro Beer taps: Digiart2001 Arturo photo: Unknown