Go Down

Topic: Arduino serial output random once I start my Processing sketch (Read 689 times) previous topic - next topic

morgoe

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: [Select]
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: [Select]
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));
}

eried

Code: [Select]
Serial.list()

Probably asks every serial port for "open" to check if there is something there or no, much like arduino, and that may produce a reset or something in the arduino. Check if you can replace the rxtx dll from arduino and processing with the one I modded: http://servicios.ried.cl/arduino/ (RXTX fixed library) but first backup your original dlls.
My website: http://ried.cl

PaulS

Quote
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?

Do you want the Arduino talking to the Serial Monitor OR to Processing? It can't do both.

Processing has an output area. You can use print() or println() to show data there. Close the serial monitor.

Go Up