Mbed Weather Station With Twitter
Georgia Tech ECE 4180 Project. By Moses Isang and Kevin Moore
This mini design project implemented a weather station using the Sparkfun Weather Meters. The Weather meter includes a wind vane, an anemometer and a rain gauge and is interfaced to the mbed using 2 RJ-11 breakout boards. Also for temperature and humidity readings, a SHT-15 Temperature and Humidity breakout board is used. The weather parameters are read to the mbed and posted to Tweeter periodically.
Hardware
- Sparkfun Weather Meters
- 2 RJ-11 breakout boards
- SHT-15 Temperature and Humidity Sensor breakout board
- Ethernet RJ-45 breakout module
Wiring
- Rain gauge output to p10 on mbed (pulled up with 10k resistor)
- Wind vane output to p15 on mbed (pulled up with 10k resistor)
- Anemometer output to p8 on mbed (pulled up with 10k resistor)
- Temp/Humidity sensor to pins 27/28 on mbed
- Ethernet p8 to RD-, p7 to RD+, p1 to TD+, p2 to TD-
Software
Libraries Used include:
#include "mbed.h" #include "sht15.hpp" #include "WeatherMeters.h" #include "EthernetNetIf.h" #include "SuperTweetV1XML.h" #define YOUR_ACCOUNT "USERNAME" /*SuperTweet username*/ #define YOUR_PASSWORD "PASSWORD" /*SuperTweet password*/ Serial pc(USBTX, USBRX); /*tx, rx*/ WeatherMeters station(p8, p15, p10, Weather_auto);/*Weather meter init*/ SHTx::SHT15 sensor(p28, p27); /*Temp & Humidity Init*/ /*Twitter Code*/ extern "C" void mbed_reset(); EthernetNetIf net; SuperTweetV1XML st(YOUR_ACCOUNT, YOUR_PASSWORD); //SuperTweet Object Ticker twitter; /*Weather Globals*/ float w_speed = 0.0; float w_direction = 0.0; float w_raingauge = 0.0; float temperature = 0.0; float humidity = 0.0; /*Tweeter Globals*/ char text[BUFSIZ]; int cnt = 0; int count = 0; /** * Callback function for postStatusesUpdate. * * @param buf A pointer to a buffer. * @param siz A size of the buffer. */ void func(char *buf, size_t siz) { #if 0 /* * This is for checking a response. */ for (int i = 0; i < siz; i++) { printf("%c", buf[i]); } #endif } /*Method called periodically to post weather to Twitter*/ void twitterPost() { snprintf(text, sizeof(text), "Current Weather in the ECE 4180 lab!\n\nWind Speed : %f m/s\nWind Direction : %f degrees\nRain Gauge : %f mm/hr\nTemperature : %3.2f degrees F\nHumidity : %3.2f %%", w_speed, w_direction, w_raingauge, temperature, humidity); HTTPResult r = st.postStatusesUpdate(std::string(text), func); printf("r=%d\n", (int)r); /* * Note: * I don't know why sometime it get a error. * I think it a bug in a mbed library */ if (r != 0) { printf("Resetting...\n"); mbed_reset(); } wait(5); } int main() { sensor.setOTPReload(false);/*set to false for faster readings from temp & humidity sensor*/ sensor.setResolution(true); /*More Twitter Code*/ EthernetErr err = net.setup(); if (err) { pc.printf("Network setup failed.\n"); } pc.printf("Setup OK\n"); /*Attach twitterPost to twitter ticker to be called periodically*/ twitter.attach(&twitterPost, 90); while(1) { /* Get weather readings from sensors*/ w_speed = station.get_windspeed(); w_direction = station.get_windvane(); w_raingauge = station.get_raingauge(); temperature = sensor.getTemperature(); humidity = sensor.getHumidity(); sensor.update(); /*Print to COM Port for debugging*/ pc.printf("Wind speed: %f\r\n",w_speed); pc.printf("Wind direction: %f\r\n",w_direction); pc.printf("Rain Gauge: %f\r\n",w_raingauge); /*Temperature in fahrenheit*/ sensor.setScale(true); pc.printf("Temperature: [ %3.2f F ]\r\n", temperature); /*Relative Humidity*/ pc.printf("Humdity: [ %3.2f %% ]\r\n\n", humidity); wait(1); } }
Twitter Output
1 comment on Mbed Weather Station With Twitter:
Please log in to post comments.
Dear Sir /Madam
Will this code work with a sparkfun Weather shield which will interface with a Nucleo F446RE MCU , thanks