I am using Processing for first time so let me apologize for asking such a basic question.
I have build a simple capacitive sensor using the following code adapted from the arduino forums which works fine (I've commented the code section for multiple arrays for now)
____________________________________________________________________________________________________
#include <CapacitiveSensor.h>
/*
* CapitiveSense Library Sketch
* Uses a high value resistor e.g. 10M between send pin and receive pin
* Resistor effects sensitivity, experiment with values, 50K - 50M. Larger resistor values yield larger sensor values.
* Receive pin is the sensor pin - try different amounts of foil/metal on this pin
*/
CapacitiveSensor cs_4_2 = CapacitiveSensor(4,2); // 10M resistor between pins 4 & 2, pin 2 is sensor pin, add a wire and or foil if desired
/*
CapacitiveSensor cs_4_6 = CapacitiveSensor(4,6); // 10M resistor between pins 4 & 6, pin 6 is sensor pin, add a wire and or foil
CapacitiveSensor cs_4_8 = CapacitiveSensor(4,8); // 10M resistor between pins 4 & 8, pin 8 is sensor pin, add a wire and or foil
CapacitiveSensor cs_4_7 = CapacitiveSensor(4,7); // 10M resistor between pins 4 & 7, pin 7 is sensor pin, add a wire and or foil
*/
void setup()
{
cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF); // turn off autocalibrate on channel 1 - just as an example
Serial.begin(9600);
}
void loop()
{
long start = millis();
long total1 = cs_4_2.capacitiveSensor(30);
/*
long total2 = cs_4_6.capacitiveSensor(30);
long total3 = cs_4_8.capacitiveSensor(30);
long total4 = cs_4_7.capacitiveSensor(30);
*/
Serial.print(millis() - start); // check on performance in milliseconds
Serial.print("\t");
Serial.println(total1); // print sensor output 1
Serial.print("\t");
/*
Serial.print(total2); // print sensor output 2
Serial.print("\t");
Serial.print(total3); // print sensor output 3
Serial.print("\t");
Serial.println(total4);
*/
delay(1000); // arbitrary delay to limit data to serial port
}
________________________________________________________________________________________________
I found this processing code which says it should work for plotting a graph :
import processing.serial.*;
Serial myPort; // The serial port
int xPos = 1; // horizontal position of the graph
void setup () {
// set the window size:
size(400, 300);
// List all the available serial ports
println(Serial.list());
// I know that the first port in the serial list on my mac
// is always my Arduino, so I open Serial.list()[0].
// Open whatever port is the one you're using.
myPort = new Serial(this, Serial.list()[0], 9600);
// don't generate a serialEvent() unless you get a newline character:
myPort.bufferUntil('\n');
// set inital background:
background(0);
}
void draw () {
// everything happens in the serialEvent()
}
void serialEvent (Serial myPort) {
// get the ASCII string:
String inString = myPort.readStringUntil('\n');
if (inString != null) {
// trim off any whitespace:
inString = trim(inString);
// convert to an int and map to the screen height:
float inByte = float(inString);
inByte = map(inByte, 0, 1023, 0, height);
// draw the line:
stroke(127,34,255);
line(xPos, height, xPos, height - inByte);
// at the edge of the screen, go back to the beginning:
if (xPos >= width) {
xPos = 0;
background(0);
}
else {
// increment the horizontal position:
xPos++;
}
}
}
However, it is not working. My COM port is 3 so I tried putting [1] instead of [0] but it doesn't work.I am using an Arduino Uno. Please help.