Show Posts
Pages: [1]
1  Using Arduino / Interfacing w/ Software on the Computer / Arduino serial output random once I start my Processing sketch on: October 16, 2012, 12:43:09 am
Hi there,

I've got some buttons hooked up to my Arduino board. Everything is absolutely fine when I'm running the Arduino, it exports three numbers, one for each button, each is either a 0 or a 1 depending on whether it's pressed or not. So the serial monitor will read
000
000
010
010
110
100
etc.

But when I start my Processing sketch - all it does is READ this serial monitor, it goes haywire (both in Arduino and in Processing).
I get
00
110
1110010100
0

001
01000
etc.
No error in Processing's side in reading it - this is exactly what is in the Arduino Serial Monitor. But this ONLY happens once I start my Processing sketch, and as soon as I close it, it goes back to normal. What's causing this?


Processing Code:
Code:
import processing.serial.*;

Serial myPort;

void setup() {
  println (Serial.list());
  myPort = new Serial(this, Serial.list()[0], 9600);
  myPort.bufferUntil('\n');
}

void serialEvent(Serial myPort) {
  String iString = myPort.readStringUntil('\n');
  print(iString);
}

void draw() {
}


Arduino Code:
Code:
const int buttonPin1 = 2;     // the number of the pushbutton pin
const int buttonPin2 = 3;
const int buttonPin3 = 4;

void setup() {
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin1, INPUT);
  pinMode(buttonPin2, INPUT);
  pinMode(buttonPin3, INPUT);
  Serial.begin(9600);
}

void loop(){
  // read the state of the pushbutton value:
  Serial.print(digitalRead(buttonPin1));
  Serial.print(digitalRead(buttonPin2));
  Serial.println(digitalRead(buttonPin3));
}
Pages: [1]