How to send temperature data from Processing to Arduino?


i'm building weather station uses modified xml yahoo weather example on processing. have setup when specific weather condition met send's particular byte match example if sunny, send byte 'a' , on arduino if receives 'a' prints "sunny" screen.

this method seems work ok, , display weather condition outside, how can send temperature data on condition data @ same time?
for sending data processing, tried (or along lines of)

serial.write(temperature);

i have feeling it's sending temperature data arduino, how access data , code use on arduino print temperature data onto lcd screen? i've been using arduino 3 months, maybe i'm way on head on project.

(anywhere see n/a f temperature data supposed go)

arduino code:


int ledg = 13; //led green (good weather)
int ledy = 10; //led yellow (mild weather, rain, etc)
int ledr = 9; // led red (severe weather alert)
//int temp = serial.read, temperature;

//include library code:
#include<liquidcrystal.h>

// initialize library numbers of interface pins
liquidcrystal lcd(12, 11, 5, 4, 3, 2);

void setup()
{
  lcd.begin(16,2); //columns , rows of screen

  pinmode(ledg, output); //setup leds
  pinmode(ledy, output);
  pinmode(ledr, output);

  serial.begin(9600);

}

void loop()
{

  while(serial.available())
  {
    char getdata = serial.read(); //is there read?
    serial.write(getdata); // if yes, read it

    if(getdata == 'a')
    {


      lcd.setcursor(0,0);
      lcd.print("today's weather:");
      lcd.setcursor(0,2);
      lcd.print("fair, n/a f"); 
      digitalwrite(ledg, high);
      digitalwrite(ledy, low);
      digitalwrite(ledr, low);

      delay(5000);
      lcd.clear();
      lcd.setcursor(0,0);
      lcd.print("wooster, oh:");
      lcd.setcursor(0,2);
      lcd.print("fair, n/a f"); 
      digitalwrite(ledg, high);
      digitalwrite(ledy, low);
      digitalwrite(ledr, low);
      delay(5000);
    } 

    else if(getdata == 'b')
    {
      digitalwrite(13,high);

      lcd.setcursor(0,0);
      lcd.print("today's weather:");
      lcd.setcursor(0,2);
      lcd.print("rain, n/a f"); 
      digitalwrite(ledg, low);
      digitalwrite(ledy, high);
      digitalwrite(ledr, low);
      delay(5000);
      lcd.clear();
      lcd.setcursor(0,0);
      lcd.print("wooster, oh:");
      lcd.setcursor(0,2);
      lcd.print("rain, n/a f"); 
      digitalwrite(ledg, low);
      digitalwrite(ledy, high);
      digitalwrite(ledr, low);
      delay(5000);

    }
  }
}

processing:


/**
* loading xml data
* daniel shiffman. 
*
* example demonstrates how use loadxml()
* retrieve data xml document via url
*/

pimage cf;
// we're going store temperature
int temperature = 0;
// we're going store text weather
string weather = "";
//int fair = 'a';
// zip code we'll check for
string zip = "44691";

pfont font;

import processing.serial.*;
serial port;


void setup() {
  size(600, 360);

  font = createfont("merriweather-light.ttf", 28);
  fill(#000000);
  textfont(font);
  println(serial.list());
  port = new serial(this, serial.list()[0], 9600); //serial communication

  // url xml document
  /*string url = "http://xml.weather.yahoo.com/forecastrss?p=" + zip;
   
   // load xml document
   xml xml = loadxml(url);
   
   // grab element want
   xml forecast = xml.getchild("channel/item/yweather:condition");
   */
  // attributes want
  //temperature = forecast.getint("temp");
  //weather = forecast.getstring("text");

  cf= loadimage("clouds.jpg");
}
void draw()
{
  // url xml document
  string url = "http://xml.weather.yahoo.com/forecastrss?p=" + zip;

  // load xml document
  xml xml = loadxml(url);

  // grab element want
  xml forecast = xml.getchild("channel/item/yweather:condition");
  temperature = forecast.getint("temp");
  weather = forecast.getstring("text");
  weather = weather.tolowercase();
  image(cf, 0, 0, 600, 360);


  // display stuff want display
  text("wooster oh: ", width*0.15, height*0.33);
  text("current temperature: " + temperature, width*0.15, height*0.5);
  text("forecast: " + weather, width*0.15, height*0.66);
 
  port.write(temperature);



  if ( weather.contains("fair"))
  {
    port.write('a');
    println("fair");
  }

  else if (weather.contains("rain"))
  {
    port.write('b');
    println("rain");
  }

  else if (weather.contains("cloud"))
  {
    port.write('c');
    println("cloudy");
  }
  else if (weather.contains("sun"))
  {
    port.write('d');
    println("sunny");
  }
  else if (weather.contains("clear"))
  {
    port.write('e');
    println("clear");
  }
  else if( weather.contains("storm"))
  {
    port.write('f');
    println("t-storms");
  }
  else
  {
    port.write('x');
    println("no data avalaiable");
  }
 
(here tried something, seemed promising @ first did not give me results.)

  /* delay(4000);
   
   
   port.write(temperature);
   
   delay(4000);
   
   port.write('w');
   
   delay(40000);
   */
}

quote
i've been using arduino 3 months

when have time read how use forum sticky posting code correctly , have modified first post @ it.

in meantime else might.


Arduino Forum > Using Arduino > Programming Questions > How to send temperature data from Processing to Arduino?


arduino

Comments

Popular posts from this blog

opencv3, tbb and rasp pi 2 - Raspberry Pi Forums

small ethernet problem - Raspberry Pi Forums

Multithumb configuration params not working? - Joomla! Forum - community, help and support