Weather Reporter-Temboo,Ethernet and Arduino

details

Description:

An Arduino UNO (and Ethernet Shield) queries Yahoo using a Temboo account and retrieves weather information. The data is filtered and processed, and then passed on to another Arduino UNO to be displayed on a TFT LCD module. Two Arduino UNOs are used because the Ethernet library and the UTFT library are both memory hungry, and together consume more memory than one Arduino UNO can handle.

Hardware Required:

• Arduino uno

• Ethernet Shield w5200

• TFT LCD module

• Proto shield

•Jumper wires

• Breadboard.

Step1:

Visit the Temboo website: https://www.temboo.com/ 
Create an account by entering a valid email address.
Then click on the Sign-Up button.

160

Step 2:

Verify your email address by clicking on the link provided in the email sent by Temboo.

Step 3:

You will be directed to the account setup page:
Create an Account Name, and Password for future access to your Temboo Account
Check the terms of service and if you agree, then tick the box
Press the Go! button

161

Step 4:

You will then encounter the “Welcome!” screen:

162

Step 5:

Navigate to the top right of the screen and select the LIBRARY tab 163

Step 6:

On the left-hand side, you will see a list of choreos.
Type Yahoo into the search box on the top left of the screen.
Navigate to the GetWeatherByAddress Choreo by clicking on…
Yahoo _ Weather _ GetWeatherByAddress.

164

Step 7:

Turn the IoT Mode to ON (in the top right of screen)

165

Step 8:

What’s your platform/device? : Arduino
How is it connected? : Arduino Ethernet

The following popup box will appear:

166

Step 9:

Name: EthernetShield – you can choose any name. Letters and numbers only. No spaces.
Shield Type: Arduino Ethernet
MAC Address: You can normally find the MAC address of the Ethernet shield on the underside.
Enter the MAC address without the hyphens. Then click SAVE. 167

Step 10:

Move to the INPUT section.
Enter the Address of the place you want the Temperature for.
Address = Perth, Western Australia
Expand the Optional INPUT for extra functionality
Units = c – If you want the temperature in Celcius. 168

Step 11:

This will automatically generate some Arduino CODE and a HEADER FILE.
Don’t worry about the Arduino code for now… because I will provide that for you.
However, you will need the automatically generated HEADER file. I will show you what to do with that soon.
So don’t lose it !’

169
#include <SPI.h>
#include <Dhcp.h>
#include <Dns.h>
#include <Ethernet.h>
#include <EthernetClient.h>
#include <Temboo.h>
#include "TembooAccount.h" // Contains Temboo account information - in a new tab.
#include <Wire.h>

byte ethernetMACAddress[] = ETHERNET_SHIELD_MAC;   //ETHERNET_SHIELD_MAC variable located in TembooAccount.h
EthernetClient client;

String Address = "Perth, Western Australia";     // Find temperature for Perth, Western Australia
String Units = "c";                              // Display the temperature in degrees Celcius

String ForeCastDay[7];                           //String Array to hold the day of the week              
String ForeCastTemp[7];                          //String Array to hold the temperature for that day of week.

int counter1=0;                                  //Counters used in FOR-LOOPS.
int counter2=0;

boolean downloadTemp = true;                     // A boolean variable which controls when to query Yahoo for Temperature information.



void setup() {
  Wire.begin();           // join i2c bus : Used to communicate to the Arduino SLAVE device. 
 
  // Ethernet shield must initialise properly to continue with sketch.
  if (Ethernet.begin(ethernetMACAddress) == 0) {
    while(true);
  }
  
  //Provide some time to get both Arduino's ready for Temperature Query.
    delay(2000);
}




void loop() {
  if (downloadTemp) {
    downloadTemp=false;     //Stop Arduino from Querying Temboo repeatedly
    getTemperature();       //Retrieve Temperature data from Yahoo
    transmitResults();      //Transmit the temperature results to the Slave Arduino
  }
}




/* This function will Query Yahoo for Temperature information (using a Temboo account) */

void getTemperature(){
    TembooChoreo GetWeatherByAddressChoreo(client);

    // Invoke the Temboo client
    GetWeatherByAddressChoreo.begin();

    // Set Temboo account credentials
    GetWeatherByAddressChoreo.setAccountName(TEMBOO_ACCOUNT);        //TEMBOO_ACCOUNT variable can be found in TembooAccount.h file or tab
    GetWeatherByAddressChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);    //TEMBOO_APP_KEY_NAME variable can be found in TembooAccount.h file or tab
    GetWeatherByAddressChoreo.setAppKey(TEMBOO_APP_KEY);             //TEMBOO_APP_KEY variable can be found in TembooAccount.h file or tab

    // Set Choreo inputs
    GetWeatherByAddressChoreo.addInput("Units", Units);              // Set the Units to Celcius
    GetWeatherByAddressChoreo.addInput("Address", Address);          // Set the Weather Location to Perth, Western Australia

    // Identify the Choreo to run
    GetWeatherByAddressChoreo.setChoreo("/Library/Yahoo/Weather/GetWeatherByAddress");

    // This output filter will extract the expected temperature for today
    GetWeatherByAddressChoreo.addOutputFilter("Temperature", "/rss/channel/item/yweather:condition/@temp", "Response");
    
    // These output filters will extract the forecasted temperatures (we need to know the day and temperature for that day)
    GetWeatherByAddressChoreo.addOutputFilter("ForeCastDay", "/rss/channel/item/yweather:forecast/@day", "Response");
    GetWeatherByAddressChoreo.addOutputFilter("ForeCastHigh", "/rss/channel/item/yweather:forecast/@high", "Response");

    // Run the Choreo; 
    GetWeatherByAddressChoreo.run();

    //Reset our counters before proceeding
    counter1 = 0;
    counter2 = 0;
    
    while(GetWeatherByAddressChoreo.available()) {
      // This will get the first part of the output
      String name = GetWeatherByAddressChoreo.readStringUntil('\x1F');
      name.trim(); // get rid of newlines

      // This will get the second part of the output
      String data = GetWeatherByAddressChoreo.readStringUntil('\x1E');
      data.trim(); // get rid of newlines

      //Fill the String Arrays with the Temperature/Weather data
      if (name == "Temperature") {
        ForeCastDay[counter1] = "Today";
        ForeCastTemp[counter2] = data;
        counter1++;
        counter2++;
      }
      
      if(name=="ForeCastDay"){
        ForeCastDay[counter1] = data;
        counter1++;
      }
      
      if(name=="ForeCastHigh"){
        ForeCastTemp[counter2] = data;
        counter2++;
      }
    }
  
    //Close the connection to Temboo website
    GetWeatherByAddressChoreo.close();
  }
  
  
  
  
  /* This function is used to transmit the temperature data to the Slave Arduino */
  
  void transmitResults(){
    char tempData[10];
    int tempStringLength = 0;
    
    //Modify the current temp to "Now"
    ForeCastDay[0] = "Now";
    
    //Send * to Slave Arduino to prepare for Temperature Transmission
    Wire.beginTransmission(4);  // Transmit to device #4  (Slave Arduino)
    Wire.write("*");
    delay(500);
    Wire.endTransmission();
    delay(500);
    
    //Send the temperatures on the Slave Arduino to be displayed on the TFT module.
    for (int j=0; j<20; j++){
      for (int i=0; i<6; i++){
        memset(tempData,0,sizeof(tempData));   //Clear the character array
        String tempString = String(ForeCastDay[i] + "," + ForeCastTemp[i] + ".");
        tempStringLength = tempString.length();
        tempString.toCharArray(tempData, tempStringLength+1);
        Wire.beginTransmission(4);  // Transmit to device #4  (Slave Arduino)
        Wire.write(tempData);
        delay(1000);
        Wire.endTransmission();
        delay(4000);
      }
    }
    
    /* ----------------------------------------------------------------------
    // You can use this to send temperature results to the Serial Monitor.
    // However, you will need a Serial.begin(9600); statement in setup().
    
    Serial.println("The Current Temperature is " + ForeCastTemp[5] + " C");
    Serial.println();
    Serial.println("The Expected Temperature for");
    for (int i=0; i<5; i++){
      Serial.println(ForeCastDay[i] + " : " + ForeCastTemp[i] + " C");
    }
    ---------------------------------------------------------- */
  }

Arduino code (Slave)

#include <UTFT.h>
#include <Wire.h>

//Declare all of the fonts
extern uint8_t SmallFont[];
extern uint8_t BigFont[];
extern uint8_t SevenSegNumFont[];

// Usage: UTFT myGLCD(<model code>, SDA, SCL, CS, RST, RS);
UTFT myGLCD(ITDB18SP,7,8,9,5,6);

boolean tempDisplay = false;  //Helps with processing the data from the Arduino MASTER
boolean readTemp = false;      //Helps to differentiate the day from the temperature values
String dayOfWeek="";          //Variable used to hold the Day of the Week
String tempReading="";        //Variable used to hold the Temperature for that day

String Units = "'C ";         //Display Temperature in Celcius
String Address = "Perth, WA"; //Address to show at top of Display


void setup(){
  // Initialise the TFT LCD
  myGLCD.InitLCD();
  initialiseLCD();
  delay(5000);
  
  //Setup the Serial communication between the Arduino MASTER and SLAVE
  Wire.begin(4);                // join i2c bus with address #4
  Wire.onReceive(receiveEvent); // register event
}



void loop(){
  delay(50);
}


/*
  This function initialises the TFT LCD, and draws the initial screen.
*/
void initialiseLCD(){
  //Clear the screen
  myGLCD.clrScr();
  
  //Draw the borders (top and bottom)
  myGLCD.setColor(25, 35, 4);
  myGLCD.fillRect(0, 0, 159, 13);
  myGLCD.fillRect(0, 114, 159, 127);
  myGLCD.drawLine(0,18,159,18);
  myGLCD.drawLine(0,109,159,109);
  
  //Header and Footer Writing
  myGLCD.setColor(255, 255, 255);
  myGLCD.setBackColor(25, 35, 4);
  myGLCD.setFont(SmallFont);
  myGLCD.print("arduinobasics", CENTER, 1);
  myGLCD.print("blogspot.com", CENTER, 114);
}




/* This function executes whenever data is received from Arduino master
   It will ignore all data from the Master until it receives a '*' character.
   Once this character is received, it will call the receiveTemp() function
   in order to receive Temperature data from the Arduino Master.
*/
void receiveEvent(int howMany){
  if(tempDisplay){
    receiveTemp();
  }else{
    while(0 < Wire.available()){
      char c = Wire.read();       // receive byte as a character
      if(c=='*'){                 // Searching for a '*' character
        tempDisplay=true;         // If '*' received, then call receiveTemp() function
      }
    }
  }
}



/* This function is used to receive and process the Temperature data 
   from the Arduino Master and pass it on to the  displayTemp() funtion.
*/
void receiveTemp(){
  tempReading="";
  dayOfWeek = "";
  
  while(0 < Wire.available()){
    char c = Wire.read(); // receive byte as a character
    if(readTemp){
      if(c=='.'){         // If a . is detected. It is the end of the line.
        readTemp=false;
      }else{
        tempReading=tempReading+c;
      }
    }else{
      if(c==','){
      } else {
        dayOfWeek=dayOfWeek+c;
      }
    }
    if(c==','){
      readTemp=true;
    }
  }
  displayTemp();
}



/*
  Display the Temperature readings on the TFT LCD screen.
*/
void displayTemp(){
  //Clear the writing on top and bottom of screen
  myGLCD.setColor(25, 35, 4);
  myGLCD.fillRect(0, 0, 159, 13);
  myGLCD.fillRect(0, 114, 159, 127);
  
  //Small writing on top and bottom of screen
  myGLCD.setColor(255, 255, 255);
  myGLCD.setBackColor(25, 35, 4);
  myGLCD.setFont(SmallFont);
  myGLCD.print(Address, CENTER, 1);
  myGLCD.print(dayOfWeek, CENTER, 114);
  
  //Write the big temperature reading in middle of screen
  myGLCD.setBackColor(0, 0, 0);
  myGLCD.setFont(SevenSegNumFont);
  myGLCD.print(tempReading, CENTER, 40);
  
  //Write the Units next to the temperature reading
  myGLCD.setFont(BigFont);
  myGLCD.print(Units, RIGHT, 40);
}

Step 1: Ethernet Shield

Place the Ethernet shield onto the Arduino MASTER.
Connect an Ethernet cable (RJ45) to the Ethernet shield. The other end will connect to your internet router.

170

Step 2: Arduino SLAVE and TFT LCD module

You can either wire up the TFT LCD module on a breadboard, or you can use a ProtoShield with mini-breadboard. It doesn’t really matter how you hook it up, but make sure you double check the connections and the TFT specifications before you power it up. I have powered the Arduino Slave by connecting it to the Arduino Master (see fritzing sketch below).

There is no reason why you couldn’t just power the slave separately. In fact, this is probably the safer option. But I read that this power-sharing setup was ok, so I wanted to give it a go. I have no idea whether it would be suitable for a long-term power project… so use it at your own risk. I tried using 4 x AA batteries to power this circuit but found that the LCD screen would flicker. So then I tried a 9V battery and noticed that the 5V voltage regulator was heating up more than I felt comfortable with. In the end, I settled with the USB option and had no further issues.

171

172

173

 

 

 

 

COMMENTS

Please Login to comment
  Subscribe  
Notify of