I have a simple switch circuit on the Arduino and the following code:
int switchPin = 4; // Switch connected to pin 4
void setup() {
pinMode(switchPin, INPUT); // Set pin 4 as an input
Serial.begin(9600); // Start serial communication at 9600 bps
}
void loop() {
if (digitalRead(switchPin) == HIGH) { // If switch is ON,
Serial.println(1); // send 1 to Processing
} else { // If the switch is not ON,
Serial.println(0); // send 0 to Processing
}
delay(100); // Wait 100 milliseconds
}
On the serial monitor I see rows of 1 until I hit the switch when I get 0's.
In processing my code is:
import processing.serial.*;
import processing.serial.*;
Serial myport; // Create object from Serial class
void setup() {
println("Here is a list of serial ports:");
println(Serial.list());
println("List finished, opening port");
myport = new Serial(this, "ttyACM0", 9600);
myport.bufferUntil('\n');
}
void draw()
{
}
void serialEvent(Serial myport)
{
String inString = myport.readStringUntil( '\n' );
println(inString);
}
and what I see is:
Here is a list of serial ports:
WARNING: RXTX Version mismatch
Jar version = RXTX-2.2pre1
native lib Version = RXTX-2.2pre2
List finished, opening port
Evidently, when I invoke Serial.list() the warning is printed and it returns nothing.
Then, when I hardwire in the port as ttyACM0, I still get nothing.
What is wrong?