i am using 2 way communication between arduino and processing, the arduino is constantly sending data to processing, and serialevent is called when the line feed character is found. it then stores the parts of the string received in arrays.
when i try to send data to the arduino, i get the error
this is the serialevent code
and this is the code that sends serial to the arduino
it sends 2 values corresponding with where the mouse was clicked
when i send those exact commands through terminal, while the arduino is sending data, it works fine.
what am i doing wrong?
when the error comes up, processing stops reading data in but the serial write will keep working and the arduino will still recieve the data...
when i try to send data to the arduino, i get the error
- error, disabling serialEvent() for //./COM4
- java.lang.reflect.InvocationTargetException
- at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
- at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
- at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
- at java.lang.reflect.Method.invoke(Method.java:597)
- at processing.serial.Serial.serialEvent(Unknown Source)
- at gnu.io.RXTXPort.sendEvent(RXTXPort.java:732)
- at gnu.io.RXTXPort.eventLoop(Native Method)
- at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1575)
- Caused by: java.lang.ArrayIndexOutOfBoundsException: 1
- at the_GUI_bro_addbuttons_22_8.serialEvent(the_GUI_bro_addbuttons_22_8.java:286)
- ... 8 more
this is the serialevent code
- void serialEvent(Serial p) {
- inString = (p.readString());
- if (inString!= null){
- float sensorValues[] = float(split(inString, ','));
- pitch_comp = sensorValues[0];
- roll_comp = sensorValues[1];
- pitch_d = sensorValues[2];
- roll_d = sensorValues[3];
- theta_d = sensorValues[4];
- rrate = sensorValues[5];
- prate = sensorValues[6];
- boardTime = sensorValues[7];
- dt = sensorValues[8];
- alphaa = sensorValues[9];
- }
- rrateInt+=rrate*(dt/1000);
- prateInt+=prate*(dt/1000);
- updateInputArrays ();
- }
and this is the code that sends serial to the arduino
- void mouseClicked(){
- //dragging set point
- if (mouseX<(plotX+plotSize)&&mouseX>plotX&&mouseY<(plotY+plotSize)&&mouseY>plotY){
- rollSet=(mouseX-(plotX+plotSize/2))*.3;//((mouseX-150)/300)*45;
- pitchSet=(mouseY-(plotY+plotSize/2))*.3;//((mouseY-100)/300)*45;
- println(rollSet + " "+pitchSet + " sending setpos");
- myPort.write("p" + pitchSet +"#");
- myPort.write("r" + rollSet +"#");
- }
it sends 2 values corresponding with where the mouse was clicked
when i send those exact commands through terminal, while the arduino is sending data, it works fine.
what am i doing wrong?
when the error comes up, processing stops reading data in but the serial write will keep working and the arduino will still recieve the data...
1