Recitation Week 8: Serial Communication
Documentation
This recitation was a bit more chaotic than the past few. After plugging the Arduino into my laptop and tried connecting it to my port, I realized that I kept getting error messages on my Arduino program. This was similar to an issue I was having with my Arduino in class, but I thought I had fixed the issue by just continually taking out and re-plugging in my Arduino. After receiving help from multiple people during recitation in an attempt to solve the issue, it took about 40 minutes for us to figure out what was wrong, which was that my adapter is malfunctioning and only occasionally works with my Arduino and laptop (I have since ordered a new adapter, though it sadly has not arrived yet). While I was trying to figure out the issue with my Arduino, I was obviously unable to connect my Arduino to Processing, and thus started my code for the Etch-a-Sketch by coding an Etch-a-Sketch that did not require an Arduino, meaning a line would be drawn (made of ellipses) following the movement of the mouse. A video of this code in action is below:
Though I was able to figure out the issue with my Arduino connection, I sadly could not solve this, as my adapter was not working and I didn’t have one to use to complete the exercises. I did, however, finish wiring the Arduino and have pictures of my connections below:
Schematic
The interactions involved in the Etch-a-Sketch are composed of data being sent to each potentiometer and that then being sent to processing to draw lines. One potentiometer controls the x-value of the line being drawn, while the other controls the y-value.
My code for the Arduino + Processing Etch-a-Sketch is below:
import processing.serial.*;
import cc.arduino.*;
int varX;
int varY;
int xPin= 0;
int yPin= 1;
void setup() {
//println(h);
arduino = new Arduino(this, Arduino.list()[3], 57600);
colorMode(HSB);
size(1280,720);
varX= arduino.analogRead(xPin);
varY= arduino.analogRead(yPin);
}
void draw(){varX= arduino.analogRead(xPin);
varY= arduino.analogRead(yPin);
drawLine();
}