IA02 Arduino Graph

Due: Wednesday, February 12 (before classtime)

All assignments in this class will be emphasizing the theme of tangible interactive computing. With IA01, you will get a taste of the Arduino platform--the current de facto open hardware platform for rapid prototyping. According to the Arduino webpage:

"Arduino is an open-source electronics prototyping platform based on flexible, easy-to-use hardware and software. It's intended for artists, designers, hobbyists, and anyone interested in creating interactive objects or environments."

Arduino makes working with sensors and actuators significantly easier than before it existed. This is largely due to the enormous support and ample code examples from the online Arduino community. There are many examples of Arduino projects on blogs, forums, and YouTube that can help get you started on your own projects. Before starting this assignment, I encourage you to search for "cool Arduino projects" to get a sense, first, of the enormous variety of inventions that have been built by hobbyists, hackers, and professionals with the Arduino and, second, to gain an appreciation for the variety of types of people working on these projects from professional digital media artists building interactive art installations to musicians building experimental instruments to engineers prototyping electronics projects.

Assignment Overview

The Arduino is a powerful platform because it enables a wider range of people to build computational artifacts that enable new interactive experiences in the physical world relatively simply and quickly. Perhaps because of this simplicity, however, the development environment is rather impoverished compared to other development tools. The Arduino programming environment lacks basic debugging functionality like stack tracing, breakpoints, memory inspectors, etc. Thus, you have to return to the "old school" way of debugging your program, namely println()! Specifically, Serial.println(). For example, the code below is from our first Sandbox Day (the potentiometer example). Here, I am reading from A0, which is hooked up to the potentiometer, and writing out to D9, which is connected to the LED. The only way to investigate what these values are is via a Serial.println() function call.
int ledPin = 9;    // LED connected to digital pin 9
 
void setup()  {
  // nothing happens in setup
  Serial.begin(9600);
  analogWrite(ledPin, 255);
}
 
void loop()  {
  //read in from Analog0 (which is connected to the potentiometer)
  int sensorValue = analogRead(0);
 
  //remember that our analogWrite has a min value of 0 and a max value of 255,
  //so we should map our input range to our output range
  int analogOut = map(sensorValue, 0, 1023, 0, 255);
  analogWrite(ledPin, analogOut);
 
  //print out the data!
  String printOut = "sensorValue=" + String(sensorValue) + ", analogOut=" + String(analogOut);
  Serial.println(printOut);
}

See the println at the end of the loop function? (quick tip: remember to initialize the serial port in your setup() function with Serial.begin(baudRate)). The Arduino prints the formatted string (the variable printOut) to the serial port, which your computer reads off of USB. You can then open the Serial Monitor in the Arduino IDE to view the incoming serial port data. It will look something like this:
SerialMonitorPotentiometer.png

So, while this can be very useful, it doesn't scale with program complexity and it certainly pales in sophistication and usefulness compared to normal IDEs. This lack of feedback from the Arduino IDE is frustrating (we are spoiled!). Plus, it can obfuscate what is actually happening with your prototype during execution and, I think, can negatively impact learning (e.g., it's not easy to answer some of the "what is going wrong with my circuit?" questions).

Assignment Goal(s)

To help us with improving Arduino's runtime transparency and to help answer those "what is happening?" questions, we will build an Arduino visualizer that can graph data off the serial port in real time. While Arduino connects to the PC using an USB port, that USB connection is actually used like an old serial (RS232) connection. Your job will be to simply grab data of the serial port, and graph it.

This assignment should serve as a nice introduction to Arduino, the Arduino IDE, some simple I/O functionality, and some basic sensors. Moreover, you will be creating a useful debugging tool for yourselves that you can use the rest of the semester! Note: we will also learn other strategies for debugging our hardware designs, but this is a good start.

What to Do

There are a few steps to this assignment:
  1. You have to decide on a programming language to read data off the serial port and graph it. You can use whatever language you are comfortable with including Java, C#, Python, etc. If you are up to learning a new language, I suggest Processing.

  2. Your Arduino Visualizer (or oscilliscope or grapher or whatever you want to call it) must visualize a temporal representation of Analog In, Analog Out, Digital In, and Digital Out. The y-axis should be the value of the Analog or Digital I/O and the x-axis should be temporality (either clock time or just sequence). The axes should be labeled.

  3. The visualizer should distinguish between analog vs. digital and input vs. output. It's up to you how you want to do this. For example, you could use color, multiple simultaneous graphs, etc.

  4. Because only one computer program can read from the Serial port at a time, your visualizer must also support "Serial Monitor" functionality that simply prints the raw data off the serial port.

  5. In order for your visualizer to understand the data off of the serial port, you will need to define some sort of standardized communication protocol. For example, you might program your visualizer to ignore any data off the serial port except for lines prefixed by a certain character and then these prefixed lines have a certain structure. As another example, maybe you decide that your communication protocol is a simple comma separated format like: A0I=X, A1I=Y, .... A5I=Z (for analog in), D0I=X, D1I=Y,....D13I=Z (for digital in), D0O=X, D1O=Y,....D13O=Z (for digital out), etc.

  6. Your program should support graphing all I/O off of the Arduino Uno or Leonardo simultaneously.

Advanced Functionality

If you finish with the above, and still want to add features, how about exploring the following:
  • Can you perform some simple signal processing on the incoming waveforms such as threshold detection, peak detection?
  • Can you apply some simple signal processing techniques to transform and visualize the incoming waveform into a different type of waveform (e.g., bandpass filter, sliding window averaging filter)? Try visualizing this new waveform in a window directly below or overlaid on the original signal.
  • Can you add support for specific kinds of sensors and render custom visualizations for those sensors? For example, to do this, you could add in sensor type into your communication protocol (e.g., D0I=X|SensorType=Accel|Name='X'|Label='X-Axis', D1I=Y|SensorType=Accel|Name='Y'|Label='Y-Axis', D2I=Z|SensorType=Accel|Name='Z'|Label='Z-Axis') and, in the case of an accelerometer, you could draw a 3D-representation of its state depicting roll, yaw, and pitch (see Project 21 from Tom Igoe's Making Things Talk book).
  • Semi-super advanced: can you print out a scrolling spectrogram of the incoming data?

Related Links

Here are some potentially useful links. Disclaimer: I have not looked into these very deeply, so read at your own risk. :) Feel free to post other examples to Piazza or critiques of the links below. While you can use libraries in this assignment (galry for Python), the visualization system as a whole must be your own.


Deliverables

Please email me your deliverable or a link to a Github page or Dropbox by 3:30PM on Wed, Feb 12th. If you email me, please include in the subject "CMSC838f IA02 Arduino Graph." In your email, describe your communication protocol between Arduino and your visualizer and provide a brief description of your visualization system.

As discussed in class, the primary deliverable for this assignment will be a "show and tell" session on Wed, Feb 12th. With 20+ students, there is not enough classtime for everyone to present their work to the front of the class. So, instead, we will break up into five teams of four and share within the group. Each person should demo their application and explain their implementation (both on the Arduino side and visualizer side) and design choices. Listeners should provide feedback on new ideas and areas for improvement. We will rotate groups if there is time. Towards the end of class, some of the more interesting, fun, or otherwise creative solutions may be presented to the whole group.