Hello good night, I am working on a project where I am using several sensors, but I only have to graph one of them the air sensor or “inByte [2]”, the problem is that the zero of this sensor is very down in the graph and it is not seen when graphing zero and I do not know how to raise the graph to be able to visualize when the graph is zero, in addition how it could do once the zero is achieved to limit the graph to the white rectangle and that its maximum value does not go out of that rectangle?
This is how my graph looks.
The zero is well below the visible screen.
The zero should look like a continuous line.
This is the code in processing:
import processing.serial.*;
Serial puerto; // se declara una variable para la com. serial
boolean newData = false;
int xPos = 0; // posición horizontal del gráfico
// Variables para dibujar una línea continua de la gráfica.
int lastxPos=1;
int lastheight=0;
float inByte[] = {0,0,0,0,0,0,0}; // Datos seriales entrantes
void serialEvent (Serial myPort) { //Datos de la gráfica.
// obtener la cadena ASCII:
String inString = myPort.readStringUntil('\n');
if (inString != null) {
inString = trim(inString); // recortar espacios en blanco.
inByte = float(split(inString, ','));
inByte[0] = float(inString); // convertir a un número.
inByte[0] = map(inByte[2], 0, 1023, 0, height); //mapa a la altura de la pantalla.
newData = true;
}
}
public void setup(){
size(1000, 600, JAVA2D); //Tamaño de la ventana principal
background(17,34,51);
rect(-1, 95, 1001, 330,1); // Tamaño del rectángulo blanco donde se grafican los datos
puerto = new Serial(this,Serial.list()[0], 9600); //Busca puerto serie conectado automáticamente.
puerto.clear();
puerto.bufferUntil('\n');
}
public void draw(){
println(inByte[0],inByte[1],inByte[2],inByte[3],inByte[4]);
if (newData) {
stroke(17,34,51); //Color de la línea graficadora.
strokeWeight(1); //Grosor de la línea graficadora.
line(lastxPos, lastheight, xPos, height - inByte[0]);
lastxPos= xPos;
lastheight= int(height-inByte[0]);
// Dibujando una línea desde Last inByte hasta la nueva.
// en el borde de la ventana, regrese al principio:
if (xPos >= width) {
xPos = 0;
lastxPos= 0;
saveFrame( "Pantallazos Automáticos cada 30s"+"/"+day()+"-"+month()+"-"+year()+" a las "+hour()+"_"+minute() +" con "+ second()+"s"+ ".png") ; //dar nombre de fecha a los pantallazos
// background(17,34,51); //Clear the screen.
rect(0, 95, 999, 355,1); // Tamaño del rectángulo blanco donde se grafican los datos
stroke(196,196,196); // Color de la línea del cuadriculado
}
else {
// Incrementa la posición horizontal.
xPos++;
}
newData =false;
}
}
And in Arduino the data is sent like this:
Serial.print(",");
Serial.print( t );
Serial.print(",");
Serial.print( grafAire);
Serial.print(",");
Serial.print( h );
Serial.print(",");
Serial.println(mmHg);
delay(30);
In the arduino serial plotter the data is well plotted but I need to graph it in processing.
On line 43 I modified these values and managed to visualize the zero but changing the resolution of the graph by modifying the “1023” which does not help me because I need to work with the resolution to “1020”
void serialEvent (Serial myPort) { //Datos de la gráfica.
// obtener la cadena ASCII:
String inString = myPort.readStringUntil('\n');
if (inString != null) {
inString = trim(inString); // recortar espacios en blanco.
inByte = float(split(inString, ','));
inByte[0] = float(inString); // convertir a un número.
inByte[0] = map(inByte[2], 0, 1023, 0, height); //mapa a la altura de la pantalla.
newData = true;
I appreciate all the help and any comments if I am making a basic mistake in the method of sending data, if you know a better method, I would appreciate it if you could teach it to me.