How to write text() in processing when plotting data from serial port?












1














Recently I'm learning to use processing with my arduino UNO, I've checked arduino graph tutorial and it works like a charm, but I've been unable to refresh a simple text when you are drawing data, for example if I have a realtime source of data that comes via serial port.



I want to write a text with the value, but it seems like it gets overshadowed/overwritten somehow, and is impossible to display with the number.



Check the following image:



enter image description here



The source code to plot that data is the following :



/*
GreenLine Temperature Graph,
Modified from https://www.arduino.cc/en/Tutorial/Graph
c1b3r
*/

import processing.serial.*;
Serial myPort;
int xPos = 1;
color eggshell = color(255, 253, 248);

int temperaturaActual;
float temperaturaPreviaAltura = 0 ;
String inDataArduino;
PFont font;

void setup () {
size(600,600);
//fullScreen();
frameRate(30);
println(Serial.list());
myPort = new Serial(this, Serial.list()[0], 9600);
myPort.bufferUntil('n');
background(0);
font = createFont("Arial",32,true);

}


void draw () {
int Xmaxgraph = int(width-(width/4));
println(Xmaxgraph,width, height);
temperaturaActual = int(inDataArduino);
float alturaTemperatura = map(temperaturaActual, 0, 1023, 0, height);
stroke(255,255,255);
line(Xmaxgraph, 0, Xmaxgraph, height);
textSize(40);
fill(255, 0, 0);
textFont(font,16);
text("Temp°", width - 150, 40);
text(temperaturaActual, width - 150, 90);
fill(255,255,0);
text("Estado", width - 150, height-100);
stroke(0,255,0);
line(xPos-1, height - temperaturaPreviaAltura, xPos, height- alturaTemperatura);
temperaturaPreviaAltura = alturaTemperatura;
if (xPos >= Xmaxgraph) {
xPos = 0;
background(0);
} else {
xPos++;
}

}
void serialEvent (Serial myPort) {
inDataArduino = myPort.readStringUntil('n');
if (inDataArduino != null) {
inDataArduino = trim(inDataArduino);

}
}


Here is the syntax highlighted code.



Why is this behaviour happening? What can I do to fix this situation and see the text clearly while plotting the data?



I appreciate your help with this,
Thank you,
H.










share|improve this question
























  • I edited your post to include syntax highlighting, so you probably don't need the link anymore.
    – Kevin Workman
    Nov 21 at 17:30










  • Thank your for add this
    – c1b3r
    Nov 22 at 0:13
















1














Recently I'm learning to use processing with my arduino UNO, I've checked arduino graph tutorial and it works like a charm, but I've been unable to refresh a simple text when you are drawing data, for example if I have a realtime source of data that comes via serial port.



I want to write a text with the value, but it seems like it gets overshadowed/overwritten somehow, and is impossible to display with the number.



Check the following image:



enter image description here



The source code to plot that data is the following :



/*
GreenLine Temperature Graph,
Modified from https://www.arduino.cc/en/Tutorial/Graph
c1b3r
*/

import processing.serial.*;
Serial myPort;
int xPos = 1;
color eggshell = color(255, 253, 248);

int temperaturaActual;
float temperaturaPreviaAltura = 0 ;
String inDataArduino;
PFont font;

void setup () {
size(600,600);
//fullScreen();
frameRate(30);
println(Serial.list());
myPort = new Serial(this, Serial.list()[0], 9600);
myPort.bufferUntil('n');
background(0);
font = createFont("Arial",32,true);

}


void draw () {
int Xmaxgraph = int(width-(width/4));
println(Xmaxgraph,width, height);
temperaturaActual = int(inDataArduino);
float alturaTemperatura = map(temperaturaActual, 0, 1023, 0, height);
stroke(255,255,255);
line(Xmaxgraph, 0, Xmaxgraph, height);
textSize(40);
fill(255, 0, 0);
textFont(font,16);
text("Temp°", width - 150, 40);
text(temperaturaActual, width - 150, 90);
fill(255,255,0);
text("Estado", width - 150, height-100);
stroke(0,255,0);
line(xPos-1, height - temperaturaPreviaAltura, xPos, height- alturaTemperatura);
temperaturaPreviaAltura = alturaTemperatura;
if (xPos >= Xmaxgraph) {
xPos = 0;
background(0);
} else {
xPos++;
}

}
void serialEvent (Serial myPort) {
inDataArduino = myPort.readStringUntil('n');
if (inDataArduino != null) {
inDataArduino = trim(inDataArduino);

}
}


Here is the syntax highlighted code.



Why is this behaviour happening? What can I do to fix this situation and see the text clearly while plotting the data?



I appreciate your help with this,
Thank you,
H.










share|improve this question
























  • I edited your post to include syntax highlighting, so you probably don't need the link anymore.
    – Kevin Workman
    Nov 21 at 17:30










  • Thank your for add this
    – c1b3r
    Nov 22 at 0:13














1












1








1







Recently I'm learning to use processing with my arduino UNO, I've checked arduino graph tutorial and it works like a charm, but I've been unable to refresh a simple text when you are drawing data, for example if I have a realtime source of data that comes via serial port.



I want to write a text with the value, but it seems like it gets overshadowed/overwritten somehow, and is impossible to display with the number.



Check the following image:



enter image description here



The source code to plot that data is the following :



/*
GreenLine Temperature Graph,
Modified from https://www.arduino.cc/en/Tutorial/Graph
c1b3r
*/

import processing.serial.*;
Serial myPort;
int xPos = 1;
color eggshell = color(255, 253, 248);

int temperaturaActual;
float temperaturaPreviaAltura = 0 ;
String inDataArduino;
PFont font;

void setup () {
size(600,600);
//fullScreen();
frameRate(30);
println(Serial.list());
myPort = new Serial(this, Serial.list()[0], 9600);
myPort.bufferUntil('n');
background(0);
font = createFont("Arial",32,true);

}


void draw () {
int Xmaxgraph = int(width-(width/4));
println(Xmaxgraph,width, height);
temperaturaActual = int(inDataArduino);
float alturaTemperatura = map(temperaturaActual, 0, 1023, 0, height);
stroke(255,255,255);
line(Xmaxgraph, 0, Xmaxgraph, height);
textSize(40);
fill(255, 0, 0);
textFont(font,16);
text("Temp°", width - 150, 40);
text(temperaturaActual, width - 150, 90);
fill(255,255,0);
text("Estado", width - 150, height-100);
stroke(0,255,0);
line(xPos-1, height - temperaturaPreviaAltura, xPos, height- alturaTemperatura);
temperaturaPreviaAltura = alturaTemperatura;
if (xPos >= Xmaxgraph) {
xPos = 0;
background(0);
} else {
xPos++;
}

}
void serialEvent (Serial myPort) {
inDataArduino = myPort.readStringUntil('n');
if (inDataArduino != null) {
inDataArduino = trim(inDataArduino);

}
}


Here is the syntax highlighted code.



Why is this behaviour happening? What can I do to fix this situation and see the text clearly while plotting the data?



I appreciate your help with this,
Thank you,
H.










share|improve this question















Recently I'm learning to use processing with my arduino UNO, I've checked arduino graph tutorial and it works like a charm, but I've been unable to refresh a simple text when you are drawing data, for example if I have a realtime source of data that comes via serial port.



I want to write a text with the value, but it seems like it gets overshadowed/overwritten somehow, and is impossible to display with the number.



Check the following image:



enter image description here



The source code to plot that data is the following :



/*
GreenLine Temperature Graph,
Modified from https://www.arduino.cc/en/Tutorial/Graph
c1b3r
*/

import processing.serial.*;
Serial myPort;
int xPos = 1;
color eggshell = color(255, 253, 248);

int temperaturaActual;
float temperaturaPreviaAltura = 0 ;
String inDataArduino;
PFont font;

void setup () {
size(600,600);
//fullScreen();
frameRate(30);
println(Serial.list());
myPort = new Serial(this, Serial.list()[0], 9600);
myPort.bufferUntil('n');
background(0);
font = createFont("Arial",32,true);

}


void draw () {
int Xmaxgraph = int(width-(width/4));
println(Xmaxgraph,width, height);
temperaturaActual = int(inDataArduino);
float alturaTemperatura = map(temperaturaActual, 0, 1023, 0, height);
stroke(255,255,255);
line(Xmaxgraph, 0, Xmaxgraph, height);
textSize(40);
fill(255, 0, 0);
textFont(font,16);
text("Temp°", width - 150, 40);
text(temperaturaActual, width - 150, 90);
fill(255,255,0);
text("Estado", width - 150, height-100);
stroke(0,255,0);
line(xPos-1, height - temperaturaPreviaAltura, xPos, height- alturaTemperatura);
temperaturaPreviaAltura = alturaTemperatura;
if (xPos >= Xmaxgraph) {
xPos = 0;
background(0);
} else {
xPos++;
}

}
void serialEvent (Serial myPort) {
inDataArduino = myPort.readStringUntil('n');
if (inDataArduino != null) {
inDataArduino = trim(inDataArduino);

}
}


Here is the syntax highlighted code.



Why is this behaviour happening? What can I do to fix this situation and see the text clearly while plotting the data?



I appreciate your help with this,
Thank you,
H.







plot serial-port processing






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 at 17:29









Kevin Workman

33.4k53969




33.4k53969










asked Nov 21 at 4:41









c1b3r

83




83












  • I edited your post to include syntax highlighting, so you probably don't need the link anymore.
    – Kevin Workman
    Nov 21 at 17:30










  • Thank your for add this
    – c1b3r
    Nov 22 at 0:13


















  • I edited your post to include syntax highlighting, so you probably don't need the link anymore.
    – Kevin Workman
    Nov 21 at 17:30










  • Thank your for add this
    – c1b3r
    Nov 22 at 0:13
















I edited your post to include syntax highlighting, so you probably don't need the link anymore.
– Kevin Workman
Nov 21 at 17:30




I edited your post to include syntax highlighting, so you probably don't need the link anymore.
– Kevin Workman
Nov 21 at 17:30












Thank your for add this
– c1b3r
Nov 22 at 0:13




Thank your for add this
– c1b3r
Nov 22 at 0:13












1 Answer
1






active

oldest

votes


















1














Most Processing sketches will call the background() function at the top of every call to draw() to clear out old frames. You're only calling the background() function when the graph goes off the right edge of the screen. So for most frames, you're drawing directly on top of previous frames. This is why you see your text stack on top of itself.



To fix this, you either need to call the background() function every frame (this would require refactoring your code to redraw the whole graph every time), or you could probably get away with just drawing a rectangle over the previous text.






share|improve this answer





















  • I'm wondering how should I refactor my code, but if I call the background() method you will be cleaning the lines of the graph
    – c1b3r
    Nov 22 at 0:08












  • @c1b3r You would need to add a data structure (such as an array or ArrayList) that holds your graph values, and then redraw your graph every time. For our purposes, it might just be easier to draw the rectangle over the previous text.
    – Kevin Workman
    Nov 22 at 0:09











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53405375%2fhow-to-write-text-in-processing-when-plotting-data-from-serial-port%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














Most Processing sketches will call the background() function at the top of every call to draw() to clear out old frames. You're only calling the background() function when the graph goes off the right edge of the screen. So for most frames, you're drawing directly on top of previous frames. This is why you see your text stack on top of itself.



To fix this, you either need to call the background() function every frame (this would require refactoring your code to redraw the whole graph every time), or you could probably get away with just drawing a rectangle over the previous text.






share|improve this answer





















  • I'm wondering how should I refactor my code, but if I call the background() method you will be cleaning the lines of the graph
    – c1b3r
    Nov 22 at 0:08












  • @c1b3r You would need to add a data structure (such as an array or ArrayList) that holds your graph values, and then redraw your graph every time. For our purposes, it might just be easier to draw the rectangle over the previous text.
    – Kevin Workman
    Nov 22 at 0:09
















1














Most Processing sketches will call the background() function at the top of every call to draw() to clear out old frames. You're only calling the background() function when the graph goes off the right edge of the screen. So for most frames, you're drawing directly on top of previous frames. This is why you see your text stack on top of itself.



To fix this, you either need to call the background() function every frame (this would require refactoring your code to redraw the whole graph every time), or you could probably get away with just drawing a rectangle over the previous text.






share|improve this answer





















  • I'm wondering how should I refactor my code, but if I call the background() method you will be cleaning the lines of the graph
    – c1b3r
    Nov 22 at 0:08












  • @c1b3r You would need to add a data structure (such as an array or ArrayList) that holds your graph values, and then redraw your graph every time. For our purposes, it might just be easier to draw the rectangle over the previous text.
    – Kevin Workman
    Nov 22 at 0:09














1












1








1






Most Processing sketches will call the background() function at the top of every call to draw() to clear out old frames. You're only calling the background() function when the graph goes off the right edge of the screen. So for most frames, you're drawing directly on top of previous frames. This is why you see your text stack on top of itself.



To fix this, you either need to call the background() function every frame (this would require refactoring your code to redraw the whole graph every time), or you could probably get away with just drawing a rectangle over the previous text.






share|improve this answer












Most Processing sketches will call the background() function at the top of every call to draw() to clear out old frames. You're only calling the background() function when the graph goes off the right edge of the screen. So for most frames, you're drawing directly on top of previous frames. This is why you see your text stack on top of itself.



To fix this, you either need to call the background() function every frame (this would require refactoring your code to redraw the whole graph every time), or you could probably get away with just drawing a rectangle over the previous text.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 21 at 17:29









Kevin Workman

33.4k53969




33.4k53969












  • I'm wondering how should I refactor my code, but if I call the background() method you will be cleaning the lines of the graph
    – c1b3r
    Nov 22 at 0:08












  • @c1b3r You would need to add a data structure (such as an array or ArrayList) that holds your graph values, and then redraw your graph every time. For our purposes, it might just be easier to draw the rectangle over the previous text.
    – Kevin Workman
    Nov 22 at 0:09


















  • I'm wondering how should I refactor my code, but if I call the background() method you will be cleaning the lines of the graph
    – c1b3r
    Nov 22 at 0:08












  • @c1b3r You would need to add a data structure (such as an array or ArrayList) that holds your graph values, and then redraw your graph every time. For our purposes, it might just be easier to draw the rectangle over the previous text.
    – Kevin Workman
    Nov 22 at 0:09
















I'm wondering how should I refactor my code, but if I call the background() method you will be cleaning the lines of the graph
– c1b3r
Nov 22 at 0:08






I'm wondering how should I refactor my code, but if I call the background() method you will be cleaning the lines of the graph
– c1b3r
Nov 22 at 0:08














@c1b3r You would need to add a data structure (such as an array or ArrayList) that holds your graph values, and then redraw your graph every time. For our purposes, it might just be easier to draw the rectangle over the previous text.
– Kevin Workman
Nov 22 at 0:09




@c1b3r You would need to add a data structure (such as an array or ArrayList) that holds your graph values, and then redraw your graph every time. For our purposes, it might just be easier to draw the rectangle over the previous text.
– Kevin Workman
Nov 22 at 0:09


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53405375%2fhow-to-write-text-in-processing-when-plotting-data-from-serial-port%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

To store a contact into the json file from server.js file using a class in NodeJS

Redirect URL with Chrome Remote Debugging Android Devices

Dieringhausen