Etch-a-Sketch assignment

From Knowledge Kitchen
Jump to: navigation, search

Create an Etch-a-Sketch-type application using two variable resistors that can be used to draw on the screen.

The challenge

In this lab, we will be sending two values to the desktop computer from two different variable resistors connected to the Arduino. The Processing program on the desktop computer will have to be able to differentiate between the value that represents the first variable resistor's reading versus the value for the second variable resistor.

In a prior lab, we saw how to send a single byte value at a time from the Arduino to a destop computer using the Arduino serial library's write() method. This was ok for sending a single byte at a time, but not so great for sending a more complex message between computers.

Potential solutions

Using a separator

One solution is not to send the raw binary data, but rather to send ASCII encoded characters using Arduno serial library's print() or println() methods. This way, you can insert a separator between the two values, and a terminator at the end of the two values. For example, consider this stream of information about two potentiometer readings:

201, 128
202, 127
203, 126

The values for each reading are separated by commas, and the set of values is terminated by a line break. As long as Processing can parse data in this format (which is easy using the Processing serial library's readStringUntil() method and the [splitting the string by comma]), then you can easily differentiate between the value from one potentiometer versus the value for the other.

Using a handshake protocol

Another solution that is more robust, but also more complicated, is to use handshaking protocol between the Arduino and the desktop computer. A custom handshake protocol for this might look like the following:

An Initial handshake

  • Arduino sends a greeting message to the desktop awaits a response
  • The desktop sends a confirmation response

And then an ongoing series of handshakes repeated for each batch of data

  • Arduino sends the first batch of data and awaits a response
  • The desktop sends a confirmation that it received the data

Concluded by a final handshake

  • Arduino says goodbye and awaits a response
  • The desktop confirms goodbye
  • Both close the connection on their serial ports

What links here