We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › 2 temps from same commPort MixUp
Pages: 1 2 
2 temps from same commPort MixUp (Read 2383 times)
2 temps from same commPort MixUp
Dec 30th, 2009, 12:38pm
 
I've been working on my coffee roasting profile sketch for quite some time.  I'm using an Arduino with 2 thermocouples(TC) sending temperature data to my PC, and use Processing to graph and display the temp.

Unfortunately when one TC is exposed to the high heat and one is not, they seem to be effecting one another.  When heat is applied to one TC the other temp begins to increase as well, which in turn seems to be subtracting from the heated TC temp reading.  Does that make sense?  Basically, if I know the non heated TC should read 55*F, it might read 75*F.  While the heated TC should read 390*F but instead reads 370*F.  So obviously its getting mixed messages.

Here is the code for my commPort read.

Code:
if ((currentPoint < numberOfGraphPoints)
   && (millis() - previousGrabTime >= timeStep)
   && (commPort.available() > 2)
   && (commPort.read() == 255)){
   // if it's time to grab, the array is not full, AND the commport is available...
   
   tempC = commPort.read();
   tempB = commPort.read();
   tempF = ((tempC * 9) / 5) + 32;
   // converts tempC to Fahrenheit
   tempEnvF = ((tempB*9)/5) + 32;


I'm thinking this may be my error, with both tempC and tempB equaling commPort.read() .  The arduino sends the data as tempC and tempB.  While the sketch displays tempF and tempEnvF .
Is there a way to code the commPort.read 's  in a way where processing wont confuse the two, if this is in fact my problem?
Re: 2 temps from same commPort MixUp
Reply #1 - Dec 30th, 2009, 3:13pm
 
I would send an extra byte before each temperature byte, indicating from which sensor the temperature byte has been read (which will be sent after the "identifier" byte)
Re: 2 temps from same commPort MixUp
Reply #2 - Dec 30th, 2009, 4:27pm
 
thanks for the response.  How does one send a byte?
Re: 2 temps from same commPort MixUp
Reply #3 - Dec 31st, 2009, 9:53am
 
well, I found this and it looks like what I might need.
http://processing.org/learning/libraries/serialcallresponse.html
Im in the process of trying to figure out how to incorporate it into my code.  Any tips?
Re: 2 temps from same commPort MixUp
Reply #4 - Jan 1st, 2010, 12:18am
 
I think the key is how you are sending messages from the Arduino.

The piece of code you gave us appears to wait until more than 2 bytes are waiting to be picked up, but only 2 bytes are being read:
Quote:
tempC = commPort.read();
tempB = commPort.read();


(read() picks up only 1 byte)
http://processing.org/reference/libraries/serial/Serial_read_.html
Re: 2 temps from same commPort MixUp
Reply #5 - Jan 2nd, 2010, 12:51pm
 
well, I had a problem before where when it was more than 0, the second temp kept flashing back to 30*F sporadically.  It was suggested here to make it 2, which I did, and solved that problem, however, it apparently moved the problem.  I'm thinking that the solution would be to send bytes between each read.
Re: 2 temps from same commPort MixUp
Reply #6 - Jan 2nd, 2010, 9:37pm
 
Could you post the Arduino code that sends your temp. values?
Re: 2 temps from same commPort MixUp
Reply #7 - Jan 4th, 2010, 9:26am
 
NoahBuddy wrote on Jan 2nd, 2010, 9:37pm:
Could you post the Arduino code that sends your temp. values

do I need to put a delay between the 2 bytes  

Code:
//declare variables
float tempC;
float tempB;
int beanPin = 0;
int envPin = 1;

void setup()
{
Serial.begin(9600); //opens serial port, sets data rate to 9600 bps
}

void loop()
{
tempC = analogRead(beanPin);           //read the value from bean sensor
tempB = analogRead(envPin);           //read value from environment sensor
tempC = (5.0 * tempC * 100.0)/1024.0;  //convert bean analog data to temperature
tempB = (5.0 * tempB * 100.0)/1024.0;  //convert env analog data to temp
Serial.print((byte)255);
Serial.print((byte)tempC);             //send the data to the computer
Serial.print((byte)tempB);
delay(1000);                           //wait one second before sending new data
}

Re: 2 temps from same commPort MixUp
Reply #8 - Jan 4th, 2010, 10:42pm
 
Sorry for misunderstanding; I have re-read your code above and see that you are reading 3 bytes with the first comparing to 255. Embarrassed
Curse you order-of-operations!

What range do your temp. sensors have?
From the calculations of temperature, the analog values are divided by about half (500/1024) then cast to bytes before sent.
Re: 2 temps from same commPort MixUp
Reply #9 - Jan 5th, 2010, 9:41am
 
NoahBuddy wrote on Jan 4th, 2010, 10:42pm:
Sorry for misunderstanding; I have re-read your code above and see that you are reading 3 bytes with the first comparing to 255. Embarrassed
Curse you order-of-operations!

What range do your temp. sensors have
From the calculations of temperature, the analog values are divided by about half (500/1024) then cast to bytes before sent.

Off the top of my head, I couldnt tell you.  They are standard K-type thermocouples.  This was the code that was given to me by the person who I bought the TC reading microchips.  Make sense
Would it be better to do the calculation with processing rather than Arduino
Re: 2 temps from same commPort MixUp
Reply #10 - Jan 5th, 2010, 10:01am
 
I've started to blog about it, if anyone wants to see images of what I've been doing.

http://homeroastprofiler.blogspot.com/
Re: 2 temps from same commPort MixUp
Reply #11 - Jan 5th, 2010, 11:55pm
 
I find it easier to troubleshoot if I have the raw data coming in from the Arduino. To each their own, I guess.  Undecided

If you are interested, I have a meter example that sends fixed length hex values to the PC.
Re: 2 temps from same commPort MixUp
Reply #12 - Jan 6th, 2010, 10:10am
 
dthomas wrote on Jan 4th, 2010, 9:26am:
Code:
//declare variables
float tempC;
float tempB;
int beanPin = 0;
int envPin = 1;

void setup()
{
Serial.begin(9600); //opens serial port, sets data rate to 9600 bps
}

void loop()
{
tempC = analogRead(beanPin);           //read the value from bean sensor
tempB = analogRead(envPin);           //read value from environment sensor
tempC = (5.0 * tempC * 100.0)/1024.0;  //convert bean analog data to temperature
tempB = (5.0 * tempB * 100.0)/1024.0;  //convert env analog data to temp
Serial.print((byte)255);
Serial.print((byte)tempC);             //send the data to the computer
Serial.print((byte)tempB);
delay(1000);                           //wait one second before sending new data
}



could it be a problem that I have tempC = analogRead(beanPin), then tempC = (5.0 * tempC * 100.0)/1024.0 ? and likewise for tempB?

Should I float another temp, say tempD, then
tempD = (5.0*tempC*100.0)/1024.0? then send tempD to processing?
Re: 2 temps from same commPort MixUp
Reply #13 - Jan 7th, 2010, 10:50pm
 
No, you shouldn't need another variable; the compiler understands that you want to use the value, then put the result back into the variable.
Re: 2 temps from same commPort MixUp
Reply #14 - Jan 8th, 2010, 10:02am
 
NoahBuddy wrote on Jan 7th, 2010, 10:50pm:
No, you shouldn't need another variable; the compiler understands that you want to use the value, then put the result back into the variable.

Yeah I just tried it last night and it was quite confused.  I kept it the same, and it works fine.  Is there a better way to code, in processing, the following
Code:

   tempC = commPort.read();
   tempB = commPort.read();


Is it possible there is a mix up there?
I added a delay(10) to the Arduino code between the 2 bytes and it seemed to help a lot.
Pages: 1 2