Lex,
THanks for the reply,
To clarify, the arduino is sending data to the Processing via Serial4. So I can look in the serial monitor in the same time. No? It is a Teensy 3.5 by the way.
What is the problem with the gliph and the Serial event being disabled?
Here is the main code.
//import apsync.*;
import processing.serial.*;
import g4p_controls.*;
import java.awt.Font;
boolean running = false;
//Serial myPort;
PFont f;
PFont font;
PFont BauHousefont;
//f = createFont("Arial",16,true);
//AP_Sync streamer;
char c1; // first character in the incoming string.
char CharFromKbd; //charater from keyboard
String BeforeSending = "";
//public String streamer;
/////////////////////Arm Depiction section
float segLength = 250;
////////////////////////////////
String inBuffer;
float BaseEncGlobal;
float ShoEncGlobal;
float ElbowEncGlobal;
float VertRotEnc;
float HorRotEnc;
float GripEncGlobal;
float X_axis;
float Y_axis;
float Z_axis;
int GripOrientationRead;
float ArmOpeningMM;
float HorAngRad;
float VerAngRad;
float Mode;
float GripCommand;
float TheStepNo;
float CommandSent;
float CommandCompleted;
float X_Err;
float Y_Err;
float Z_Err;
float T_Err;
float BaseAngRad;
float ShoAngRad;
float ElbowAngRad;
/// outgoing
String customKey;
String Message;
///// color definitions White Yellow green Blue magenta Orange indigo
//int w, y, g, b, m, o;
int w= #FFFFFF; // white
int y= #FCF442; //yellow
int g= #A0FFA3; //green
int b= #64E1FF; // blue
int m= #CC15D3; // Magenta
int o= #FF6C67; // orange
int i= #B767FF; // indigo
int r= #FC0B03; // red
int bk = (#212121);
GButton btn;
PImage RedButtonCalib;
Serial BTPort;
int lf = 10; // Linefeed in ASCII
String myString = null;
public void setup(){ ////////////////////////////////////////////////////////////////////////////////////////////////////////
size(1790,1100, JAVA2D);
createGUI();
customGUI();
RedButtonCalib = loadImage("RedButtonCalib.png");
//surface.setResizable(true);
printArray(Serial.list());
// streamer = new AP_Sync(this,"/dev/cu.usbserial-A50285BI", 57600); // FTDI ON SERIAL1
// streamer = new AP_Sync(this,"/dev/cu.usbserial-A50285BI", 115200); // FTDI ON SERIAL1
// streamer = new AP_Sync(this,"COM3", 57600); // HC06 bluetooth
BTPort = new Serial(this, "COM3", 57600);
BTPort.clear();
// Throw out the first reading, in case we started reading
// in the middle of a string from the sender.
myString = BTPort.readStringUntil(lf);
myString = null;
// BTPort.bufferUntil('\n');
//streamer = new AP_Sync(this,"/dev/cu.usbmodem2574541", 38400); // Teensy 3.5 built in usb port
// myPort = new Serial(this,"/dev/cu.usbmodem2574541", 115200); // Teensy 3.5 built in usb port
font = loadFont("AgencyFB-Bold-200.vlw");
BauHousefont = loadFont("Bauhaus93-100.vlw");
//font = createFont("AgencyFB-Bold-200",16,true);
//f = createFont("Arial",16,true);
BeforeSending = "s"; // s for stream . Checking that the Processing to Arduino works.
//streamer.send(BeforeSending.toString());
BeforeSending = "";
//////////////////////Button creation
BTPort.write('s');
// frameRate(5);
}
public void draw(){
background(bk);
textAlign(LEFT);
int FontBig= 90;
int FontMed= 50;
int FontSml= 40;
int spaceDown = 75;
// /*
///*
//GripEncGlobal = nums[5] ;
/*
float ArmOpeningMM;
float HorAngRad;
float VerAngRad;
float Mode;
float GripCommand;
float TheStepNo;
float CommandSent;
float CommandCompleted;
// ElbowEncGlobal = list [2];
*/
// image(RedButtonCalib, 220, 0);
textFont(font, FontSml);
fill(255, 255, 205); //White
text("Encoders Pulses:", 20, spaceDown );
textFont(font, FontMed);
fill(o); // Green
text("G:", 20, spaceDown *2);
text( (nf(GripEncGlobal, 1,0)), 80, spaceDown*2);
fill( i);
text("H:", 20, spaceDown *3);
text((nf(HorRotEnc,1,0)), 80, spaceDown*3);
fill(b); //Blue dark
text("V:", 20, spaceDown *4);
text((nf(VertRotEnc,1,0)),80, spaceDown*4);
fill(y); // Yellow
text("E:", 20, spaceDown *5);
text((nf(ElbowEncGlobal,1,0)), 80, spaceDown*5);
// /////////progress bar
noStroke();
fill (#817703);
rect(20, 384, 200, 20, 5);
fill(y);
rect(20, 384, ((200*(ElbowEncGlobal-ShoEncGlobal))/105500), 20, 5);
///////////end rectangles
fill(m); // magenta
text("S:", 20, spaceDown *6);
text((nf(ShoEncGlobal,1,0)), 80, spaceDown*6);
////////////bar
fill (#43013F);
rect(20, 460, 200, 20, 5);
fill(m);
rect(20, 461, ((200*ShoEncGlobal)/91700), 20, 5);
/////////end bar
fill(g); // Green
text("B:", 20, spaceDown *7);
text((nf(BaseEncGlobal,1,0)), 80, spaceDown *7);
/////////////////////////////////////////////////////////
int LS = 300; // left spacing
fill(w); //White
textFont(font, FontSml);
text("XYZ mm:", LS, spaceDown );
textFont(font, FontMed);
fill(g);
text("X:", LS, spaceDown*2 );
text( (nf(X_axis,1,1)), LS+40, spaceDown*2);
fill(m); // magenta
text("Y:", LS, spaceDown*3 );
text( (nf(Y_axis,1,1)), LS+FontMed, spaceDown*3);
fill(238,242, 0); // Yellow
text("Z:", LS, spaceDown*4 );
text( (nf(Z_axis,1,1)), LS+40, spaceDown*4);
textFont(font, FontSml);
fill(o);
text("HGrAng:", LS, spaceDown*4.8 );
text(nf(HorAngRad, 0, 1)+"°" , LS+120, spaceDown*4.8);
fill(b);
text("VGrAng:", LS, spaceDown*5.6 );
text (nf(VerAngRad , 0, 1)+"°", LS+120, spaceDown*5.6);
int LS3 = 560; // left spacing
fill(255, 255, 255); //White
textFont(font, FontSml);
text("MODE:", LS3, spaceDown );
if (Mode ==0)
{text("WAYPOINTS", LS3+100, spaceDown );
}
else if (Mode ==1)
{fill (o);
text("PAUSE", LS3+100, spaceDown );
}
else if (Mode ==2)
{ fill (r);
text("RUN MOTION", LS3+100, spaceDown );
}
////////active step
fill(g);
textFont(font, FontMed);
text("ACTIVE ST:", LS3, 150 );
text( (nf(TheStepNo, 1,0)), LS3+200, 150);
/// Message
fill(g);
textFont(font, 40);
//text("ACTIVE ST:", LS3, 150 );
text( Message, LS3, 220);
// GripCommand
fill(r);
textFont(font, FontMed);
text("GripCo:", LS3, 280 );
text( (nf( GripCommand,1,0)), LS3+140, 280);
fill(b);
textFont(font, FontMed);
text("CSent:", LS3, 340 );
text( (nf(CommandSent,1,0)), LS3+140, 340);
text("CCmpte:", LS3, 400 );
text( (nf(CommandCompleted,1,0)), LS3+150, 400);
text("Err XYZ T:", LS, 490 );
text( (nf(X_Err,1,0))+" "+(nf(Y_Err,1,0))+" "+(nf(Z_Err,1,0))+" "+(nf(T_Err,1,0))+"°", LS+199, 490);
////////////SHOW BEFORE SENDING
fill(o);
textFont(font, 150);
text("STEP: ", 970, 150);
text( BeforeSending, 1280, 150);
////// MENU LIST
fill(g);
textFont(font, 30);
text("111-DICE, 200-BLOCKS, 300-DRAW, 400-LASER", 970, 1070 );
/////////BOTTOM SWITCH
// fill(g);
// textFont(font, FontMed);
// text("SHOW COORDINATES", 1030, 1065 );
///////////////HOME
///////end of home
// println( TheStepNo);
GripDepiction();
ArmDepiction();
/*
print ("mouseX:") ;
println (mouseX) ;
print ("mouseY:") ;
println (mouseY) ;
*/
}// end of draw
void serialEvent(Serial BTPort) {
inBuffer = BTPort.readStringUntil(lf);
if (inBuffer != null)
{println(inBuffer);
c1 = inBuffer.charAt(0);
DataSplit();
inBuffer = null;
}
}
void keyPressed() { // I made this just to be displayed on the processing screen
// if ((key >= 'A' && key <= 'z') || key == ' ')
// println("pressed " + int(key) + " " + keyCode);
if(keyCode != ENTER &&
keyCode != DELETE &&
keyCode != ESC &&
keyCode != UP &&
keyCode != DOWN &&
keyCode != BACKSPACE &&
keyCode != TAB &&
keyCode != ALT &&
keyCode != CONTROL &&
keyCode != RETURN )
{
CharFromKbd = key;
BeforeSending = BeforeSending + key;
}
if (keyCode == ENTER)
{
println(BeforeSending + " sent");
// streamer.send(BeforeSending.toString());
BeforeSending = "";
}
if (keyCode == DELETE || keyCode == BACKSPACE)
{
if(BeforeSending.length() > 0)
BeforeSending=BeforeSending.substring(0, BeforeSending.length() - 1);
}
}
// Use this method to add additional statements
// to customise the GUI controls
public void customGUI(){
HOME.setFont(new Font("AgencyFB-Bold-200", Font.BOLD, 70));
Send.setFont(new Font("", Font.BOLD, 70));
int KeypadFontSize=160;
button1.setFont(new Font("", Font.BOLD, KeypadFontSize));
button2.setFont(new Font("", Font.BOLD, KeypadFontSize));
button3.setFont(new Font("", Font.BOLD, KeypadFontSize));
button4.setFont(new Font("", Font.BOLD, KeypadFontSize));
button5.setFont(new Font("", Font.BOLD, KeypadFontSize));
button6.setFont(new Font("", Font.BOLD, KeypadFontSize));
button7.setFont(new Font("", Font.BOLD, KeypadFontSize));
button8.setFont(new Font("", Font.BOLD, KeypadFontSize));
button9.setFont(new Font("", Font.BOLD, KeypadFontSize));
button0.setFont(new Font("", Font.BOLD, KeypadFontSize));
NEXT.setFont(new Font("", Font.BOLD, 80));
PREV.setFont(new Font("", Font.BOLD, 80));
DEL.setFont(new Font("", Font.BOLD, 50));
CALIBLOW.setFont(new Font("", Font.BOLD, 30));
CALIBARROWS.setFont(new Font("", Font.BOLD, 30));
SHOW.setFont(new Font("", Font.BOLD, 18));
buttonM.setFont(new Font("", Font.BOLD, 30));
buttonP.setFont(new Font("", Font.BOLD, 30));
buttonR.setFont(new Font("", Font.BOLD, 30));
}
/* depository
HOME.setFont(new Font("Arial", Font.BOLD, 70));
HOME.setFont(new Font("Bauhaus93-100.vlw", Font.BOLD, 70));
*/
There is more code, as I have the Data Split function and the GUI, but I dont think they are related to serial dropping out.
Any ideas?
Thanks