Communication problem between Arduino 1.5.2 and Processing 2.0b8
Hello everybody,
I have a communication problem between Arduino 1.5.2 and Processing 2.0b8. Indeed, when I want to create a new Serial in Processing, i have an error message "Error inside Serial.<init>()". I have already check communication port and everything is ok. Arduino sends the good data because I can see it in the monitoring activity in Arduino but not in Processing. My librairies Java and Native are correct. I'm working on a mac and my installation is working but when I switch with a PC, is not working anymore. Let me show you my code:
Arduino code :
- #include <DHT22.h>
- #define DHT22_PIN 7
- DHT22 myDHT22(DHT22_PIN);
- const int buttonPin = 2; //pushbutton pin
- const int ledPin = 13; //LED pin
- // variables
- int buttonState = 0; //pushbutton status
- float temperature = 0;
- float humidite = 0;
- String envoie;
- String but;
- static char temp[6];
- static char hum[6];
- void setup() {
- Serial.begin(9600);
- pinMode(ledPin, OUTPUT);
- pinMode(buttonPin, INPUT);
- //delay(100);
- }
- void loop(){
- // read the state of the pushbutton value:
- buttonState = digitalRead(buttonPin);
- // check if the pushbutton is pressed.
- // if it is, the buttonState is HIGH:
- if (buttonState == HIGH) {
- // turn LED on:
- digitalWrite(ledPin, HIGH);
- //Serial.println("ok");
- }
- else {
- // turn LED off:
- digitalWrite(ledPin, LOW);
- //Serial.println("nok");
- }
- DHT22_ERROR_t errorCode;
- errorCode = myDHT22.readData();
- temperature = myDHT22.getTemperatureC();
- humidite = myDHT22.getHumidity();
- //Serial.print(temperature);
- //Serial.print(humidite);
- but = String(buttonState);
- dtostrf(temperature, 2, 1, temp);
- dtostrf(humidite, 2, 1, hum);
- envoie = String(but+ "," +temp+ "," +hum);
- //Serial.print(buttonState+ "," +temperature+ "," +humidite);
- Serial.println(envoie);
- delay(2000);
- }
Arduino response :
0,24.9,99.9
0,24.6,99.9
0,24.6,99.9
0,24.7,99.9
0,24.8,99.9
0,24.8,99.9
0,24.9,99.9
0,24.9,99.9
0,24.8,99.9
0,24.6,99.9
- import processing.serial.*;
- Serial myPort;
- String value;
- int valeurBouton = 0;
- float temperature = 0.0;
- float humidite = 0.0;
- String[] liste;
- void setup() {
- println(Serial.list());
- String portName = Serial.list()[0];
- myPort = new Serial(this, portName, 9600);
- myPort.bufferUntil('\n');
- size(200, 200, JAVA2D);
- background(255);
- }
- void draw() {
- if (myPort.available() > 0 ) {
- value = myPort.readStringUntil('\n');
- if (value != null) {
- //println(value);
- liste = split(value, ',');
- //println(liste);
- println(liste[0]);
- println(liste[1]);
- println(liste[2]);
- if ( int(liste[0]) == 1 ) {
- background(0);
- }
- else {
- background(255);
- }
- }
- }
- }
Processing response :
Stable Library
=========================================
Native lib Version = RXTX-2.1-7
Java lib Version = RXTX-2.1-7
[0] "COM3"
gnu.io.PortInUseException: Unknown Application
at gnu.io.CommPortIdentifier.open(CommPortIdentifier.java:354)
at processing.serial.Serial.<init>(Serial.java:178)
at processing.serial.Serial.<init>(Serial.java:116)
at sketch__01P.setup(sketch__01P.java:31)
at processing.core.PApplet.handleDraw(PApplet.java:2241)
at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:243)
at processing.core.PApplet.run(PApplet.java:2140)
at java.lang.Thread.run(Thread.java:662)
Exception in thread "Animation Thread" java.lang.RuntimeException: Error inside Serial.<init>()
at processing.serial.Serial.errorMessage(Serial.java:666)
at processing.serial.Serial.<init>(Serial.java:190)
at processing.serial.Serial.<init>(Serial.java:116)
at sketch__01P.setup(sketch__01P.java:31)
at processing.core.PApplet.handleDraw(PApplet.java:2241)
at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:243)
at processing.core.PApplet.run(PApplet.java:2140)
at java.lang.Thread.run(Thread.java:662)
Hope you can help me :) Thank you for those one who have the solution !