Weather Station Hardware > The WxTech Dream Machine
The Dream Machine - II
wxtech:
A weather station is the most appropriate application for a solar panel. Voltaic Systems is giving away 5 solar panels in a contest. http://www.voltaicsystems.com/solar-project-contest.shtml The contest runs through October 30.
Design your solar application and enter for the free power. Good luck.
fmbfla:
Your project looks good to me! :grin:
My idea: 8-)
With an added Adafruit CC3000 WiFi BOB you can have the entire unit enclosed and solar powered, outside and freed from the PC.
I 'm trying to get the uno to hold all the sketch and the uno only has 2 interrupts so currently I have to use MEGA/ADK (31,550).
once i get it to hold steady on the uploads to Wunderground I will unwire the sensors and hook up the Xbee's
WindDir
Speed (interrupt)
Temp
Humi
Rain (interrupt)
Baro
The sketch is kinda messy for now as i am still debugging the Hanging issue of periodically stopping
I get any where from zero to 50 Tx to wunderground then poof!
Any input would be appreciated
Code below;
--- Code: ---
/***************************************************
* This is an example for the Adafruit CC3000 Wifi Breakout & Shield
*
* Designed specifically to work with the Adafruit WiFi products:
* ----> https://www.adafruit.com/products/1469
*
* Adafruit invests time and resources providing this open source code,
* please support Adafruit and open-source hardware by purchasing
* products from Adafruit!
*
* Written by Limor Fried & Kevin Townsend for Adafruit Industries.
* BSD license, all text above must be included in any redistribution
****************************************************/
/*
This example does a test of the TCP client capability:
* Initialization
* Optional: SSID scan
* AP connection
* DHCP printout
* DNS lookup
* Optional: Ping
* Connect to website and print out webpage contents
* Disconnect
SmartConfig is still beta and kind of works but is not fully vetted!
It might not work on all networks!
*/
#include <Adafruit_CC3000.h>
#include <ccspi.h>
#include <SPI.h>
#include <Wire.h>
#include <DHT.h>
#include <Adafruit_BMP085.h>
#include "RTClib.h"
//Pins
#define anemometer 2 // Wind speed
//const int rainTip = 3; // Digital 3, Receive the pulse from Rain HALL EFFECT sensor on pin 3/Interupt 1
#define ADAFRUIT_CC3000_IRQ 3 // MUST be an interrupt pin!
#define ADAFRUIT_CC3000_VBAT 5
#define ADAFRUIT_CC3000_CS 10
#define DHTPIN A0 // DHT 22 (AM2302)
#define winDir A2 // Wind direction
#define WLAN_SSID "XXXXXXX" // cannot be longer than 32 characters!
#define WLAN_PASS "XXXXXXX"
#define WLAN_SECURITY WLAN_SEC_WPA2
#define IDLE_TIMEOUT_MS 3000 // Amount of time to wait (in milliseconds) with no data
#define ID "KFLFORTMXX"
#define PASSWORD "XXXXXXXX"
//#define WEBSITE "rtupdate.wunderground.com"// RapidFire Server
#define WEBSITE "weatherstation.wunderground.com"//standard server
#define WEBPAGE "GET /weatherstation/updateweatherstation.php?"
#define DHTTYPE DHT22 // DHT 22 (AM2302)
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT,
SPI_CLOCK_DIV2); // you can change this clock speed
//const char PROGMEM
//WEBSITE []= "weatherstation.wunderground.com",
//WEBPAGE []="GET /weatherstation/updateweatherstation.php?",
//ID []= "KFLFORTMXX",
//PASSWORD [] = "XXXXXX";
const float pi = 3.14159265; // pi, not apple, not pumpkin, not pizza, not even related to Raspberry Pi. http://www.raspberrypi.org/ This is the REAL PI for Wind speed calculations
int period = 5000; // Measurement period (miliseconds)
int Wait = 2500; // Amount of Time to wait till Re-connecting
const int radio = 65; // Radius from vertical anemometer axis to a cup center (mm)
DHT dht(DHTPIN, DHTTYPE); // DHT 22 (AM2302)
Adafruit_BMP085 bmp; // BMP Sensor
unsigned int counter = 0; // pulse count for wind sensor
unsigned int RPM = 0; // Revolutions per minute
unsigned int Sample = 0; // Sample number
//unsigned int timesConnected = 0; // WiFi conections
unsigned int winddir = 0; // Wind direction
float speedwind = 0 ; // Wind speed (m/s)
unsigned int maxwind = 0;
//---DEWPOINT
double dewPoint(double tempf, double Humi)
{
double A0= 373.15/(273.15 + tempf);
double SUM = -7.90298 * (A0-1);
SUM += 5.02808 * log10(A0);
SUM += -1.3816e-7 * (pow(10, (11.344*(1-1/A0)))-1) ;
SUM += 8.1328e-3 * (pow(10,(-3.49149*(A0-1)))-1) ;
SUM += log10(1013.246);
double VP = pow(10, SUM-3) * Humi;
double T = log(VP/0.61078); // temp var
return (241.88 * T) / (17.558-T);
}
//---DEWPOINT
RTC_DS1307 rtc;
uint32_t ip;
void setup(void)
{
if (!bmp.begin()) {
Serial.println("Could not find a valid BMP085 sensor, check wiring!");
while (1) {}
}
Wire.begin();
Serial.begin(115200);
pinMode(anemometer, INPUT);
digitalWrite(anemometer, HIGH);
rtc.begin();
//rtc.adjust(DateTime(__DATE__, __TIME__));
Serial.println(F("CC3000 Wunderground Test!\n"));
dht.begin();// Connect the DHT22 sensor
Serial.println(F("\nInitializing..."));
if (!cc3000.begin())
{
Serial.println(F("Couldn't begin()! Check your wiring?"));
while(1);
}
if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) {
Serial.println(F("Failed!"));
while(1);
}
Serial.println(F("Connected!"));
Serial.println(F("Request DHCP"));
while (!cc3000.checkDHCP())
ip = 0;
Serial.print(WEBSITE);
Serial.print(F(" -> "));
while (ip == 0) {
if (! cc3000.getHostByName(WEBSITE, &ip)) {
Serial.println(F("Couldn't resolve!"));
}
delay(500);
}
cc3000.printIPdotsRev(ip);
//timesConnected++;
Serial.println();
}
void loop(void)
{
Sample++;
float Dew = (dewPoint(dht.readTemperature(2), dht.readHumidity()));
windvelocity();
RPMcalc();
WindSpeed();
Heading();
if (speedwind > maxwind) {
maxwind = speedwind;
}
//Serial.println();
//Serial.println("attempting to Connect");
//Serial.print(" WiFi Connects ");
//Serial.println(timesConnected);
Adafruit_CC3000_Client client = cc3000.connectTCP(ip, 80);
//Serialprint for debuging HANGS!
if (client.connected()) {
Serial.print(" Sample # ");
Serial.println(Sample);
//Serial.println("-------------------------------------");
DateTime now = rtc.now();
// Serial.print(WEBSITE);
client.print("GET /weatherstation/updateweatherstation.php?");
Serial.println("Sending DATA ");
client.print("ID=");
// Serial.print("ID=");
client.print(ID);
//Serial.println(ID);
client.print("&PASSWORD=");
client.print(PASSWORD);
// Serial.print("&PASSWORD=");
//Serial.println(PASSWORD);
client.print("&dateutc=");
// Serial.println("dateutc");
client.print(now.year());
client.print("-");
client.print(now.month());
client.print("-");
client.print(now.day());
client.print("+");
client.print(now.hour()+ 5);
client.print("%3A");
client.print(now.minute()+ 2);
client.print("%3A");
client.print(now.second());
client.print("&winddir=");
Serial.print("winddir=");
client.print(winddir);
Serial.println(winddir);
client.print("&windspeedmph=");
Serial.print("&windspeedmph=");
client.print(speedwind/0.445);
Serial.println(speedwind/0.445);
client.print("&windgustmph=");
Serial.print("&windgustmph=");
client.print(maxwind/0.445);
Serial.println(maxwind/0.445);
client.print("&rainin=");
Serial.print("&rainin=");
client.print("0");
Serial.println("0");
client.print("&tempf=");
Serial.print("&tempf=");
client.print(dht.readTemperature(2));
Serial.println(dht.readTemperature(2));
client.print("&baromin=");
Serial.print("&baromin=");
client.print(bmp.readPressure()* 0.0002953);
Serial.println(bmp.readPressure()* 0.0002953);
client.print("&dewptf=");
Serial.print("&dewptf=");
client.print(Dew);
Serial.println(Dew);
client.print("&humidity=");
client.print(dht.readHumidity());
Serial.print("&humidity=");
Serial.println(dht.readHumidity());
client.print("&action=updateraw");
//Serial.println("&action=updateraw");
client.println();
delay(1);
}
else {
Serial.println(F("Connection failed"));
return;
}
Serial.println("UpLoad Completed!");
unsigned long lastRead = millis();
while (client.connected() && (millis() - lastRead < IDLE_TIMEOUT_MS)) {
while (client.available()) {
char c = client.read();
Serial.print(c);
lastRead = millis();
}
}
client.close();
// Serial.println("-------------------------------------");
Serial.print("Waiting ");
Serial.print(Wait/1000.0);
Serial.println(" seconds.");
delay(Wait);// 30sec
Serial.println();
//Serial.println("-------------------------------------");
}
void listSSIDResults(void)
{
uint8_t valid, rssi, sec, index;
char ssidname[33];
index = cc3000.startSSIDscan();
Serial.print(F("Networks found: "));
Serial.println(index);
Serial.println(F("================================================"));
while (index) {
index--;
valid = cc3000.getNextSSID(&rssi, &sec, ssidname);
Serial.print(F("SSID Name : "));
Serial.print(ssidname);
Serial.println();
Serial.print(F("RSSI : "));
Serial.println(rssi);
Serial.print(F("Security Mode: "));
Serial.println(sec);
Serial.println();
}
Serial.println(F("================================================"));
cc3000.stopSSIDscan();
}
bool displayConnectionDetails(void)
{
uint32_t ipAddress, netmask, gateway, dhcpserv, dnsserv;
if(!cc3000.getIPAddress(&ipAddress, &netmask, &gateway, &dhcpserv, &dnsserv))
{
Serial.println(F("Unable to retrieve the IP Address!\r\n"));
return false;
}
else
{
Serial.print(F("\nIP Addr: "));
cc3000.printIPdotsRev(ipAddress);
Serial.print(F("\nNetmask: "));
cc3000.printIPdotsRev(netmask);
Serial.print(F("\nGateway: "));
cc3000.printIPdotsRev(gateway);
Serial.print(F("\nDHCPsrv: "));
cc3000.printIPdotsRev(dhcpserv);
Serial.print(F("\nDNSserv: "));
cc3000.printIPdotsRev(dnsserv);
Serial.println();
//timesConnected++;
return true;
}
}
void windvelocity(){
speedwind = 0;
counter = 0;
attachInterrupt(0, addcount, RISING);//anemometer
unsigned long millis();
long startTime = millis();
while(millis() < startTime + Wait) {
}
detachInterrupt(0);
}
void RPMcalc(){
RPM=((counter*2)*60)/(period/1000); // Calculate revolutions per minute (RPM)
}
void WindSpeed(){
speedwind = ((2 * pi * radio * RPM)/60) / 1000;
}
void addcount(){
counter++;
}
void Heading(){
analogRead(winDir)* 5.00 / 1023.0;//Wind direction, Tweek the voltage returns below to match your resistor
if ((winDir > 4.94)||(winDir < 0.01))
(winddir = 0);
if ((winDir >= 0.02)&&(winDir < 0.30))
(winddir = 22.5);
if ((winDir >= 0.31)&&(winDir < 0.72))
(winddir = 45);
if ((winDir >= 0.72)&&(winDir < 0.99))
(winddir= 67.5);
if ((winDir >= 1.00)&&(winDir < 1.25))
(winddir = 90);
if ((winDir >= 1.26)&&(winDir < 1.52))
(winddir= 112.5);
if ((winDir >= 1.53)&&(winDir < 1.91))
(winddir= 135);
if ((winDir >= 1.92)&&(winDir < 2.40))
(winddir = 157.5);
if ((winDir >= 2.41)&&(winDir < 2.73))
(winddir = 180);
if ((winDir >= 2.74)&&(winDir < 2.96))
(winddir = 202.5);
if ((winDir >= 2.97)&&(winDir < 3.37))
(winddir = 225);
if ((winDir >= 3.38)&&(winDir < 3.55))
(winddir = 247.5);
if ((winDir >= 3.56)&&(winDir < 3.85))
(winddir = 270);
if ((winDir >= 4.13)&&(winDir < 4.06))
(winddir = 292.5);
if ((winDir >= 4.07)&&(winDir < 4.32))
(winddir = 315);
if ((winDir >= 4.33)&&(winDir < 4.93))
(winddir = 337.5);
}
--- End code ---
fmbfla:
this is the code for an ARDUINO UNO with the Ethernet Shield.
Binary sketch size: 25,866 bytes (of a 32,256 byte maximum)
This code werks flawless and sends data as expected continuously
--- Code: ---
/*
Web client
This sketch connects to a website (http://www.rtupdate.wunderground.com)
using an Arduino Wiznet Ethernet shield.
Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13
created 18 Dec 2009
by David A. Mellis
modified 9 Apr 2012
by Tom Igoe, based on work by Adrian McEwen
**
**
**modified By the drunkin programer
*/
#include <SPI.h>
#include <Ethernet.h>
#include <Wire.h>
#include <DHT.h>
#include <Adafruit_BMP085.h>
#include <RTClib.h>
#define DHTTYPE DHT22 // DHT 22 (AM2302)
//IPAddress server(38,102,137,157); // numeric IP for wunderground.com
char server[] = "rtupdate.wunderground.com"; // name address for pachube API
char WEBSITE [] = "rtupdate.wunderground.com";// RapidFire Server
//char WEBSITE [] = "weatherstation.wunderground.com";//standard server
char WEBPAGE [] = "GET /weatherstation/updateweatherstation.php?";
char ID [] = "KFLFORTM63";
char PASSWORD [] = "XXXXXXXXXXXX";
const float pi = 3.14159265; // pi, not apple, not pumpkin, not pizza, not even related to Raspberry Pi. http://www.raspberrypi.org/ This is the REAL PI for RPM/Wind speed calculations
float speedwind = 0/ 0.445 ; // Wind speed (m/s)
//Pins
int rainTip = 3; // Notification of SENDING DATA
int winDir = 2; // pin A2 Wind direction
int anemometer = 2; // D2 Wind speed
int DHTPIN = A0;
// Radius from vertical anemometer axis to a cup center (mm)
int radio = 60;
// (changing "Wait")changes the windspeed calculation "period" automaticly
const unsigned long Wait = 1500; // Amount of Time to wait till Re-connecting, Changing this also
const unsigned long period = Wait * 2; // Measurement period (miliseconds)
const unsigned long IDLE_TIMEOUT_MS = 500;
unsigned int counter = 0; // pulse count for wind sensor
unsigned int RPM = 0; // Revolutions per minute
unsigned int Sample = 0; // Sample number
unsigned int connections = 0; // number of connections
unsigned int winddir = 0; // Wind direction
unsigned int rainCount = 0; // counter for Rain
DHT dht(DHTPIN, DHTTYPE); // DHT 22 (AM2302)
Adafruit_BMP085 bmp; // BMP Sensor
RTC_DS1307 rtc;
//---DEWPOINT
double dewPoint(double tempf, double Humi)
{
double A0= 373.15/(273.15 + tempf);
double SUM = -7.90298 * (A0-1);
SUM += 5.02808 * log10(A0);
SUM += -1.3816e-7 * (pow(10, (11.344*(1-1/A0)))-1) ;
SUM += 8.1328e-3 * (pow(10,(-3.49149*(A0-1)))-1) ;
SUM += log10(1013.246);
double VP = pow(10, SUM-3) * Humi;
double T = log(VP/0.61078); // temp var
return (241.88 * T) / (17.558-T);
}//---DEWPOINT
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
// fill in an available IP address on your network here,
// for manual configuration:
IPAddress ip(192,168,1,109);
// initialize the library instance:
EthernetClient client;
void setup(void)
{
Serial.begin(115200);
attachInterrupt(1, addrain, RISING); // Read the Rain tips constantly
//Wire.begin();
rtc.begin();
rtc.adjust(DateTime(__DATE__, __TIME__));
bmp.begin();
pinMode(anemometer, INPUT);
digitalWrite(anemometer, HIGH);
pinMode(rainTip, INPUT);
digitalWrite(rainTip, HIGH);
Serial.println(F(" Wunderground Test!\n"));
dht.begin();// Connect the DHT22 sensor
Serial.println(F("\nInitializing..."));
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// DHCP failed, so use a fixed IP address:
Ethernet.begin(mac, ip);
}
Serial.println("Ready!");
}
void loop(void)
{
DateTime now = rtc.now();
Serial.print(now.year());
Serial.print('/');
Serial.print(now.month());
Serial.print('/');
Serial.print(now.day());
Serial.print(' ');
Serial.print(now.hour());
Serial.print(':');
Serial.print(now.minute());
Serial.print(':');
Serial.print(now.second());
Serial.println();
//rain();
Sample ++;
windvelocity();
RPMcalc();
WindSpeed();
Heading();
float tempf = dht.readTemperature(2); //Calc *F
float Humi = dht.readHumidity();
float baromin = bmp.readPressure()* 0.0002953;// Calc for inHg
float maxwind = 0 / 0.445; //Calc for MPH
float Dew = (dewPoint(dht.readTemperature(2), dht.readHumidity()));
if (speedwind > maxwind) {
maxwind = speedwind;
}
if (client.connect(server, 80)) {
Serial.println("Sending DATA ");
client.print("GET /weatherstation/updateweatherstation.php?");
client.print("ID=");
client.print(ID);
client.print("&PASSWORD=");
client.print(PASSWORD);
client.print("&dateutc=");
client.print(now.year());
client.print("-");
client.print(now.month());
client.print("-");
client.print(now.day());
client.print("+");
client.print(now.hour()+ 5);
client.print("%3A");
client.print(now.minute()+ 2);
client.print("%3A");
client.print(now.second());
client.print("&winddir=");
client.print(winddir);
client.print("&windspeedmph=");
client.print(speedwind);
client.print("&windgustmph=");
client.print(maxwind);
client.print("&rainin=");
client.print(rainCount / 2 / 100.0);
client.print("&tempf=");
client.print(tempf);
client.print("&baromin=");
client.print(baromin);
client.print("&dewptf=");
client.print(Dew);
client.print("&humidity=");
client.print(Humi);
//client.print("&action=updateraw");//Standard update
client.print("&action=updateraw&realtime=1&rtfreq=2.5");//Rapid Fire
client.println();
/* Serial.println();
Serial.print("Posting Sample # ");
Serial.print(Sample);
Serial.print(" TO: HTTP://");
Serial.println(WEBSITE);
Serial.print("ID=");
Serial.print(ID);
Serial.print("&PASSWORD= ");
Serial.println(PASSWORD);
Serial.print("wind dir= ");
Serial.print("wind dir= ");
Serial.println(winddir);
Serial.print("windspeed mph= ");
Serial.println(speedwind);
Serial.print("windgust mph= ");
Serial.println(maxwind);
Serial.print("rain in= ");
Serial.println(rainCount / 2 / 100.0);
Serial.print("tempf= ");
Serial.println(tempf);
Serial.print("baro= ");
Serial.println(baromin);
Serial.print("dew point= ");
Serial.println(Dew);
Serial.print("humidity= ");
Serial.println(Humi);
Serial.println();
*/
}
else {
Serial.println(F("Connection failed"));
return;
}
Serial.println("-------------------------------------");
Serial.println("Server Responce!");
unsigned long lastRead = millis();
while (client.connected() && (millis() - lastRead < IDLE_TIMEOUT_MS)) {
while (client.available()) {
char c = client.read();
Serial.print(c);
lastRead = millis();
}
}
client.stop();
Serial.println();
Serial.print("Waiting ");
Serial.print(Wait*2/1000.0);
Serial.println(" seconds.");
delay(Wait);// 30sec
Serial.println();
Serial.println("-------------------------------------");
}
void windvelocity(){
speedwind = 0;
counter = 0;
attachInterrupt(0, addcount, CHANGE);//anemometer
unsigned long millis();
long startTime = millis();
while(millis() < startTime + period) {
}
detachInterrupt(0);
}
void RPMcalc(){
RPM=((counter*4)*60)/(period/1000); // Calculate revolutions per minute (RPM)
}
void WindSpeed(){
speedwind = ((2 * pi * radio * RPM)/60) / 1000;
}
void addcount(){
counter++;
}
// save the tips and add them up
void addrain(){
rainCount++;
}
void Heading(){
analogRead(winDir)* 5.00 / 1023.0;//Wind direction, Tweek the voltage returns below to match your resistor
if ((winDir > 4.94)||(winDir < 0.01))
(winddir = 0);
if ((winDir >= 0.02)&&(winDir < 0.30))
(winddir = 22.5);
if ((winDir >= 0.31)&&(winDir < 0.72))
(winddir = 45);
if ((winDir >= 0.72)&&(winDir < 0.99))
(winddir= 67.5);
if ((winDir >= 1.00)&&(winDir < 1.25))
(winddir = 90);
if ((winDir >= 1.26)&&(winDir < 1.52))
(winddir= 112.5);
if ((winDir >= 1.53)&&(winDir < 1.91))
(winddir= 135);
if ((winDir >= 1.92)&&(winDir < 2.40))
(winddir = 157.5);
if ((winDir >= 2.41)&&(winDir < 2.73))
(winddir = 180);
if ((winDir >= 2.74)&&(winDir < 2.96))
(winddir = 202.5);
if ((winDir >= 2.97)&&(winDir < 3.37))
(winddir = 225);
if ((winDir >= 3.38)&&(winDir < 3.55))
(winddir = 247.5);
if ((winDir >= 3.56)&&(winDir < 3.85))
(winddir = 270);
if ((winDir >= 4.13)&&(winDir < 4.06))
(winddir = 292.5);
if ((winDir >= 4.07)&&(winDir < 4.32))
(winddir = 315);
if ((winDir >= 4.33)&&(winDir < 4.93))
(winddir = 337.5);
}
--- End code ---
Navigation
[0] Message Index
[*] Previous page
Go to full version