Go Down

Topic: slode me into the gist (Read 697 times) previous topic - next topic

AdrNob

Greetings everyone!...im trying to take my project a step further but have now reached a dead end!What i want to do is read a float number from serial communication that is coming from arduino into processing and graph the changes in that value.The number i want to read represents temperature(y axis) and i have to graph it along with time(x axis).What i have done so far is customized the gwortics example ''rolling graph'' together with the ''simple read'' example in processing.My question is first of all if its possible to graph the temperature along with time by combining these two examples and making some changes...One problem i am facing is how to implement the ILine2DEquation in order to get my serial incoming valye returned on y axis.I recon i can have  time on x axis by giving  RollingLine2DTrace a 1000ms argument..        r2 = new RollingLine2DTrace(new eq2(),1000,0.5);Secondly i m having problem getting the value from serial as a float so im at a dillema whether to send the final temperature from arduino(will be a float) or to send the 8 binary adc outputs(will be integers) from the adc converter to processing and then estimate the final temperature each time.[i am getting the tempetature using a circuit(lm35 adc0804) connected to arduino.

dxw00d

Processing has a forum of its own - http://forum.processing.org/.

PaulS

Quote
My question is first of all if its possible to graph the temperature along with time by combining these two examples and making some changes.

Of course. Presuming that you make the right changes.

Quote
One problem i am facing is how to implement the ILine2DEquation in order to get my serial incoming valye returned on y axis.

Can't see your code. Can't help.

Quote
Secondly i m having problem getting the value from serial as a float so im at a dillema whether to send the final temperature from arduino(will be a float) or to send the 8 binary adc outputs(will be integers) from the adc converter to processing and then estimate the final temperature each time.

Can't see your code. Can't help.

AdrNob

i was in a hurry before i had to leave i''ll tag my code and send it.ps my post was suppose to be a reply to a topic with subject "slide me into the gist"  that started a month ago..maybe someone can rellocate it to the wright place  or do you think i should seek assistance in the processing forum

AdrNob

ok i'll only adress my arduino side problems here!!Could someone please explain what goes on when printing a variable to serial...
ex int pushButton = 2; .....    int buttonState = digitalRead(pushButton); .....  Serial.print(buttonState);
i tried experimenting with different data types but didnt come to a conclusion.
Using these code lines to send a value to serial i im able to read  the value from processing with the following code

import processing.serial.*;

Serial myPort;  // Create object from Serial class
int val;      // Data received from the serial port

void setup()
{
 
  // I know that the first port in the serial list on my mac
  // is always my  FTDI adaptor, so I open Serial.list()[0].
  // On Windows machines, this generally opens COM1.
  // Open whatever port is the one you're using.
  String portName = Serial.list()[2];
  myPort = new Serial(this, portName, 9600);
}

void draw()
{
  if ( myPort.available() > 0) {  // If data is available,
    val = myPort.read();         // read it and store it in val
  }

  println(val);
}
Now why can i only get my wright results by using these codes.I mean why should the value variable in arduino sketch be an int.And if it can be a float how do i do it?do we always declare the pin number with an int?When i use a float either for declaring only the variable or both the variable and the pin i continue getting the wright result on the arduino screen but cant read the right values in processing.I tried using float and double for the value in processing scetch but it still doesnt work.Does it even matter in what kind of variable i store the port.read in the processing sketch since the serial values always get to processing in ascii format??I havent found documentation for these queries..
What i want to finally do when i no enough is graph the temperature that is estimated by a circuit connected to my arduino and which ends up in an 8bit value(the temperature comming out of an adc0804).So i have 8 inputs on 8digital pins on the arduino and have to make an equation according to my external circuit and send the final value to processing in order to graph nicelly with gwoptics library.The value will always be a float(maybe i'll have to make it an int to work!!)
Is there any other documentation about the gwoptics library apart from what there is on the site?I need info about implementing the ILine2DEquation.Probably that is my most serious problem.The rolling graph in processing examples graphs either the xmouse or the ymouse coordinate on the y axis..i need to send the temperature to the yaxis

PaulS

Quote
Now why can i only get my wright results by using these codes.

You only showed one end. We can't see what you are doing on the other end.

Quote
I mean why should the value variable in arduino sketch be an int.

Because that is what the digitalRead() function returns. The variable can be a different type, it circumstances warrant it.

Quote
And if it can be a float how do i do it?

Code: [Select]
float someCrap = 3.14159;
Serial.print(someCrap);


Quote
do we always declare the pin number with an int?

Until you can figure out how to use pin 3.7, yes.

Quote
When i use a float either for declaring only the variable or both the variable and the pin i continue getting the wright result on the arduino screen but cant read the right values in processing.

No proof anywhere.

Quote
Does it even matter in what kind of variable i store the port.read in the processing sketch since the serial values always get to processing in ascii format?

Well, of course it does. What you are reading from the serial port is text. Nothing else. The characters are transmitted using ASCII codes, so they are numeric values, but you need to make Processing aware that the stuff you are reading is text, first, and then convert the text to int, float, whatever.

That statement you have works ONLY because the int being sent is a single digit.  If you try sending an analogRead() value that way, it will not work.

Your Processing code is assuming that the '0' or '1' being sent is really an int. While it is, the int value is not 0 or 1. It is is 48 or 49.

Quote
I havent found documentation for these queries..

You aren't looking in the right places, then.

Quote
What i want to finally do when i no enough is graph the temperature that is estimated by a circuit connected to my arduino and which ends up in an 8bit value(the temperature comming out of an adc0804).So i have 8 inputs on 8digital pins on the arduino and have to make an equation according to my external circuit and send the final value to processing in order to graph nicelly with gwoptics library.The value will always be a float(maybe i'll have to make it an int to work!!)

Because Processing runs on a far more powerful device, sending a single byte, using Serial.write(), makes more sense than converting the byte to a float, then converting the float to a string, then sending the string, then reading the string, then converting the string to a float, then using the float.



AdrNob

Hi Pauls nice to hear from you again here are the codes, yes the results are 48 or 49 you kinda mixed me up though im googling for info right now

DigitalReadSerial
Reads a digital input on pin 2, prints the result to the serial monitor

*/

// digital pin 2 has a pushbutton attached to it. Give it a name:
int pushButton = 2;

// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
  // make the pushbutton's pin an input:
  pinMode(pushButton, INPUT);

// the loop routine runs over and over again forever:
void loop() {
  // read the input pin:
  int buttonState = digitalRead(pushButton);
  // print out the state of the button:
  Serial.print(buttonState);
  delay(1000);        // delay in between reads for stability
}






import processing.serial.*;

Serial myPort;  // Create object from Serial class
int val;      // Data received from the serial port

void setup()
{
  size(200, 200);
 
  // Open whatever port is the one you're using.
  String portName = Serial.list()[2];
  myPort = new Serial(this, portName, 9600);
}

void draw()
{
  if ( myPort.available() > 0) {  // If data is available,
    val = myPort.read();         // read it and store it in val
  }
println(val);               // print val
 

}




Go Up