We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, I am very new to programming. The script is not writing a character from input serial. Writes 14 numbers. How can I convert to the right value of the input? How to convert to char
import processing.serial.*;
Serial myPort; // The serial port:
int temperatuur = 0;
void setup() {
size(400, 300);
//println(Serial.list());
myPort = new Serial(this, "COM3", 9600);
textSize(50);
fill(10, 27, 217);
}
void draw() {
background(200);
while (myPort.available () > 0) {
temperatuur = myPort.read();
print (temperatuur);
text ((temperatuur), width/2, height/2);
}
}
Comments
What do you mean by "right value"? What kinds of values are you getting as ints? What do you want them to be when you convert them to char?
You'd have better luck if you posted an MCVE without any of the serial stuff. Just hardcode some int values and convert them to char values, and show us what you're getting vs what you're expecting.
Ok, What I mean is this. Now with the code below the temperature is printed to the screen. In arduino it is for example 24.20 . In processing it is printing in screen but all chacraters printed at the same location on top of each other. Just want to print to pc screen same as arduino like 24.20. Hope someone can help me with that.
The arduino code:
Processing code:
You can either build a String by appending each char to a String, or you can position the chars on the screen instead of always displaying them in the center.
Which approach you take depends entirely on what effect you're going for.
Sorry I am really new to this. Can you give ma an example
Here's an example that creates a String out of chars. You would have to do something similar in your while loop.
That's working thanks
Yea, let me know if you have questions. I didn't help you learn by posting that code chunk. It would be helpful for you to learn about the String class.
I am glad you recognize this.
how do I keep the output at the same location, not scrolling?
What do you mean? Can you post your updated code? What have you tried?
Now the temperature is displayed correctly. The next value after delay(1000) underneath. The next again below the last one etc. Want them displayed at the same location on the screen. Thanks
What String are you reading in? It looks like you only ever read in to a single String. What are some examples of what that String contains?
It sounds like you want to parse the input and determine when a new value is being read in, then display the new value on a new line. Have you tried that?
this is the output of the temperature
25.40 25.40 25.40 25.40
Etc
I just want one value at the same location on the screen which can change if input is changed
Okay, and what char do you receive when you've got a new value? Is it a space?
Can you detect that char and reset the String instead of constantly appending to it?
I changed the variable to int. Need 2 values to be on PC screen at 2 different location on the screen. variable t1 at for example 100,200 and t2 at 100,300. They need to stay on that exact location and refresh every xxx second as set in arduino
int t1 = dht1.readTemperature(); int t2 = dht2.readTemperature();
Serial.print(t1); Serial.print(t2);
thanks
Sorry, but do you still have a question?
If so, please post your updated code, along with what specifically in that code you're confused about. What have you tried? What happened when you tried that?
It's hard to answer general "how do I do this" type questions, other than by simply doing your work for you (which does not help you learn). You'll have much better luck if you try something out and ask specific technical questions about the code you've tried.
I tried to split the sting on t element. not working I added a delimiter in the 2 values from arduino in arduino. I changed 2 values of arduino into integer and added comma delimiter. I am very new to this but cannot get it to work. Hope for a solution from which I can continue. Thanks
}
String display = ""; void draw() { background(225); while (myPort.available () > 0) { char temperatuur = myPort.readChar(); display = display + temperatuur;
}
}
@Camperos, thanks, that's exactly what I mean
@Camperos , how to get only 2 decimals?
try
https://www.processing.org/reference/nf_.html
thanks, was looking at that but no time to change that already. I will post the complete code soon