Home |
Weekly assignments |
Final project
week12:Interface and Application Programming
*assignment
-individual assignment:
write an application that interfaces with an input &/or output device that you made
-group assignment:
compare as many tool options as possible
1.Learning what interface is and which one I would use for this week
In computing, an interface is a shared boundary across which two or more separate components of a computer system exchange information.
The exchange can be between software, computer hardware, peripheral devices, humans and combinations of these(wikipedia definition).
I chose to use CapacitiveSensor that I had made for Inputdevice.(Here go to week10:Input device)
I already made and used it before.
So I just had to decide which processing I would be using for.
CapacitiveSensor is Input device so that I can present the Input values and see them.
Processing
For programming Input device, I had to use Processing.
First I had to learn processing and connecting arduino to processing.
So I learned two lectures on website.
These two:
Processing website's electronics tutorial
How to serial communication with Arduino(Korean)
(You can also learn from searching which processing you want to use.)
CapacitiveSensor sends only one value that is different from whether being touched or not.
So I wanted to make graph with this.
2.Programming Input device with Processing
First I tried programming Input device with the same code as Input device week.
How Processing to serial communication with Arduino
I should install 'Serial' library to connect Arduino code.
This is inside Processing.
You don't have to download but just add.
And on processing code I should put the comport number I'm using in Arduino.
So I wrote "COM4".
And Serial communication succeeded.
But something happened.
Because to make graph I need only the number of value.
But I got "millis - numbers" with my arduino code.
How to solve?
I deleted 'mySerial.print("millis() - start");' and 'mySerial.print("");' lines.
And then I got only the number value.
Everything was ready to make graph.
My codes
Arduino code
#include SoftwareSerial.h
#include SendOnlySoftwareSerial.h
#include CapacitiveSensor.h
CapacitiveSensor cs_4_2 = CapacitiveSensor(A3,A2);
SoftwareSerial mySerial(3,2); // RX, TX
void setup()
{
cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF); //
mySerial.begin(9600);
}
void loop()
{
long start = millis();
long total1 = cs_4_2.capacitiveSensor(30);
mySerial.println(total1); //
delay(1000);
Processing code
import processing.serial.*;
Serial myPort;
int xPos =1;
float inByte=0;
String myString = null;
int value;
int no;
void setup(){
myPort = new Serial(this, "COM4", 9600);
size(1500,800);
background(0);
smooth();
}
void draw(){
stroke(127, 34, 255);
line(xPos,height,xPos,height-inByte);
if(xPos>=width){
xPos = 0;
background(0);
}
else{
xPos++;
}
if(myPort.available() > 0){
myString = myPort.readString();
if(myString !=null){
println(myString);
}
}
}
void serialEvent (Serial myPort) {
String inString = myPort.readStringUntil('\n');
if (inString != null) {
inString = trim(inString);
inByte = float(inString);
println(inByte);
inByte = map(inByte, 0, 1023, 0, height);
}
}
Result
It shows graph according to the value from capacitivesensor.
It was not that good because it's my first time.
So next time I'll try other visual fuction with Processing and Arduino.