Pages: [1]   Go Down
Author Topic: Printing temperature probe data in Processing  (Read 974 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


I want to create a GUI using processing to display 3 temperature probes I have connected to my  Arduino.

 

I am able to get Processing to read the data. I have not seen anything about how to display this data in a window with text.

 

Any help I can get would be greatly appreciated.  I am a very new to this program.

 

Example of the serial data processing is getting from the println.  3 printsof it.

 

70.25
70.25
70.25
70.2570
.2570.25
70.25
70.25
70.25


 

Thanks

 

Phil

 

Processing code:

 

// Example by Tom Igoe

import processing.serial.*;

PFont f;

Serial myPort;  // The serial port

void setup() {
  // List all the available serial ports:
  size(480, 480);
  println(Serial.list());
  // Open the port you are using at the rate you want:
  myPort = new Serial(this, Serial.list()[1], 9600);
  f = createFont("Arial",16,true);
}

void draw() {
 
  background(255);
  textFont(f,16);                 
  fill(0);
  text("TEMPERATURES:",10,50); 
  text("Temp 1:",10,100);
  text("Temp 2:",10,150); 
  text("Temp 3:",10,200);

 
  while (myPort.available() > 0) {
    String inBuffer = myPort.readString();   
    if (inBuffer != null) {
      println(inBuffer);
     

    }
  }
}



 

Arduino Code:

 

#include <OneWire.h>
#include <DallasTemperature.h>

// Data wire is plugged into pin 3 on the Arduino
#define ONE_WIRE_BUS 3

// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);

// Assign the addresses of your 1-Wire temp sensors.


DeviceAddress T1 = { 0x28, 0x0E, 0xFF, 0xE9, 0x03, 0x00, 0x00, 0xFA };
DeviceAddress T2 = { 0x28, 0x0E, 0xFF, 0xE9, 0x03, 0x00, 0x00, 0xFA  };
DeviceAddress T3 = { 0x28, 0x0E, 0xFF, 0xE9, 0x03, 0x00, 0x00, 0xFA  };

 

void setup(void)
{
  // start serial port
  Serial.begin(9600);
  // Start up the library
  sensors.begin();
  // set the resolution to 10 bit (good enough?)
  sensors.setResolution(T1, 10);
  sensors.setResolution(T2, 10);
  sensors.setResolution(T3, 10);
}

 

void printTemperature(DeviceAddress deviceAddress)
{
  float tempC = sensors.getTempC(deviceAddress);
  if (tempC == -127.00) {
    Serial.print(" Error");
  } else {
    Serial.print(DallasTemperature::toFahrenheit(tempC));
  }
}

 

void loop(void)
{
  delay(2000);
  sensors.requestTemperatures();
 

  printTemperature(T1);

  printTemperature(T2);

  printTemperature(T3);
}

 

 

 
1

Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 611
Posts: 49101
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

There are several things you need to do. First, there needs to be some way for Processing to tell when one value ends and another begins. Right now, you are sending "70.2570.2570.25" to the serial port.

You need to have the Arduino use Serial.println() in printTemperature().

In Processing, handling serial data is not a task that draw() should perform. You need a serialEvent() callback that reads the serial data.

You need to add a myPort.bufferUntil() call to setup() to tell Processing to buffer data until some specific character, like a carriage return or a line feed, arrives.

Code:
  text("TEMPERATURES:",10,50);
  text("Temp 1:",10,100);
  text("Temp 2:",10,150);
  text("Temp 3:",10,200);
These are headers and titles. Nowhere do you actually create text for the data.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Understood

I was planning on using commas for delimiting between temperatures.

I understand they are headers and titles.  How to create text for the data was my main question.

Ok I have the first temperature working with serialEvent().  Getting there.
« Last Edit: January 13, 2013, 09:10:39 pm by Phil125 » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 611
Posts: 49101
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
How to create text for the data was my main question.
The serial data is coming in as text. You are collecting it in some variable in serialEvent(). Use another text() call, with that variable and the location where you want the text to appear.
Logged

Pages: [1]   Go Up
Jump to: