I'm building this weather station that uses a modified XML Yahoo Weather example on Processing. I have it setup so when a specific weather condition is met it send's a particular Byte to match it for example: (I know I'm not using the proper programming language)
If (weather.contains("sun"))
{
Serial.write('a');
}
and on the Arduino side:
if (Serial.read == 'a')
{
lcd.print("Sunny");
}
This method seems to work ok, but how can I send temperature data over with the condition data?
I tried this on processing (or something along the lines of)
serial.write(temperature);
I have a feeling it's sending the temperature data to the Arduino, but how do I see if it is? and what code do I use on the Arduino to print the temperature data onto the LCD screen? I've only been using Arduino for 3 months, maybe I'm way over my head on this project. I just now uploaded the code here because I was using a different computer earlier.
Arduino:
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 the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup()
{
lcd.begin(16,2); //Columns and 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 anything to read?
Serial.write(getData); // if yes, then 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
- by Daniel Shiffman.
- This example demonstrates how to use loadXML()
- to retrieve data from an XML document via a URL
*/
PImage cf;
// We're going to store the temperature
int temperature = 0;
// We're going to store text about the weather
String weather = "";
//int fair = 'a';
// The 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
// The URL for the XML document
/*String url = "http://xml.weather.yahoo.com/forecastrss?p=" + zip;
// Load the XML document
XML xml = loadXML(url);
// Grab the element we want
XML forecast = xml.getChild("channel/item/yweather:condition");
*/
// Get the attributes we want
//temperature = forecast.getInt("temp");
//weather = forecast.getString("text");
cf= loadImage("clouds.jpg");
}
void draw()
{
// The URL for the XML document
String url = "http://xml.weather.yahoo.com/forecastrss?p=" + zip;
// Load the XML document
XML xml = loadXML(url);
// Grab the element we 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 all the stuff we want to display
text("Wooster OH: ", width0.15, height0.33);
text("Current Temperature: " + temperature, width0.15, height0.5);
text("Forecast: " + weather, width0.15, height0.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");
}
/* delay(4000);
port.write(temperature);
delay(4000);
port.write('w');
delay(40000);
*/
}