Data from Processing to Arduino to Max. Bug communication from Processing to Max.
Hello,
I manage to send data from Processing to Arduino. I manage to send data from Arduino to Max.
Also, If I change datas manually in Max and I reboot (by pushing the reset button of the Arduino Uno), datas of the setup (of the Arduino program) go well in their channel.
Then when I start Processing, datas are exactly send at good places in Max. At the beginning nevertheless.
A few second after, I read theses bugs in a Max console.
In this exemple when I stopped Processing, you can see datas routed with A, B, C, D, E not match with Max
There is an ''offset'' in the reception of data which should all happen in their channel A, B, C, D, E. The datas arrives randomly in A, B, C, D, whereas if I send 'only't datas from Arduino to Max, datas arrive in their matched channel.
Thank you, I wish I'm just momentany blind and you'll see the light to make this stuff works ;)
I give the patch made Max 7 and the two code made with Arduino IDE and Processing.
Here my program in Arduino to receive datas from Processing and sending datas to Max.
//*********** Variable de Processing
int w0, w1, w2, w3, w4; // vitesse à recevoir en nombre de pas /seconde
#define NBMOTEURS 5
#define ANALOG_IN A0
int analog_in;
int positionX;
int positionX0, positionX1, positionX2, positionX3, positionX4; // positionX1 actuelle
void setup()
{
Serial.begin (115000);
for(uint8_t i = 0; i < NBMOTEURS; i++) {
// w4=i; w3=i+2; w2=i+3; w1=i+4; w0=i+5;
Serial.print ("A "); Serial.println (i);
Serial.print ("B "); Serial.println (i+2);
Serial.print ("C "); Serial.println (-i+3);
Serial.print ("D "); Serial.println (i+4);
Serial.print ("E "); Serial.println (i*4);
Serial.print ("F "); Serial.println (i-2);
}
}
void loop()
{
SendDataToMax ();
}
void SendDataToMax () {
// Arduino--Max--Processing
for(uint8_t i = 0; i < NBMOTEURS; i++) {
// WORK VERY WEELL.
/*
w4=i; w3=i+2; w2=i+3; w1=i+4; w0=i+5;
Serial.print ("A "); Serial.println (w0);
Serial.print ("B "); Serial.println (-w1);
Serial.print ("C "); Serial.println (100);
Serial.print ("D "); Serial.println (w3);
Serial.print ("E "); Serial.println (w4);
Serial.println (i-2);
delay (1000);
*/
if (Serial.available() > 0) { // Ne pas redeclarer w1
w0 = Serial.parseInt(); //
w1 = Serial.parseInt();
w2 = Serial.parseInt();
w3 = Serial.parseInt();
w4 = Serial.parseInt(); // La dernière donné qui figure sur le serial de Processing arrive en premier sur Arduino
Serial.read();
// for(uint8_t i = 0; i < NBMOTEURS; i++) {
Serial.print ("A "); Serial.println (w0);
Serial.print ("B "); Serial.println (w1);
Serial.print ("C "); Serial.println (w2);
Serial.print ("D "); Serial.println (w3);
Serial.print ("E "); Serial.println (w4);
Serial.print ("F "); Serial.println (i-2);
// int i = random (1, 5);
// Serial.println (i);
delay(0);
}
}
}
Below my program made with Processing 3
import java.util.Arrays;
import sync.*;
// MANAGE ARDUINO
import processing.serial.*;
Serial arduinoport;
void setup() {
frameRate(80);
//perspective setting
size(1000, 800, P3D);
//********to send value to Arduino
String[] ports = Serial.list();
// printArray(ports);
printArray(Serial.list());
arduinoport = new Serial(this,ports[6],115200);//Carefull: chosse the port matching to the serial list
}
void draw() {
arduinoPos ( );
}
void arduinoPos () {
for (int i = 0; i < 5; i++) {
String pos = (-232) +"*"+(4232) +"*"+(1111)+"*"+(56232)+"*"+(-222)+"*";
// String pos = (int (i*2))+"*"+ (int (10))+"*"+ (int (-i))+"*"+ (int (12))+"*"+ (int (314))+"*";//
print (" pos ");println (pos);
arduinoport.write(pos); // Send data to Arduino.
}
}