Hallo zusammen,
ich habe aus vielen Anleitungen und Sketchen aus dem Internet eine Wetterstation gebastelt,
welche auch soweit super funktioniert. Bestehend aus:
Temperatur und Luftfeuchte aussen
Windmesser und Windrichtung
Temperatur innen und Luftdruck
(Regenmesser ist im Bau)
angezeigt wird alles mit LCD 16/4 mit diesem Sketch
#include <LiquidCrystal.h>
#define uint unsigned int
#define ulong unsigned long
#define PIN_VANE 3
#define MSECS_CALC_WIND_DIR 1000
#include <DHT.h>
#define DHTPIN 2
#define DHTTYPE DHT22
float adcvalue = 1.1;
DHT dht(DHTPIN, DHTTYPE);
volatile int numRevsAnemometer = 0; // Incremented in the interrupt
// When we next calc the wind speed
ulong nextCalcDir; // When we next calc the direction
ulong time; // Millis() at each start of loop().
// ADC readings:
#define NUMDIRS 8
ulong adc[NUMDIRS] = {26, 45, 77, 118, 161, 196, 220, 256};
// These directions match 1-for-1 with the values in adc, but
// will have to be adjusted as noted above. Modify 'dirOffset'
// to which direction is 'away' (it's West here).
char *strVals[NUMDIRS] = {"NORDOST","NORD","NORDWEST","WEST","SUEDWEST","SUED","SUEDOST","OST"};
byte dirOffset=0;
#include "Wire.h"
#include "Adafruit_BMP085.h"
Adafruit_BMP085 bmp;
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
const int windPin = 3; // anschluss des reedkontaktes
const float windFactor = 2.97; // umrechnungsfaktor von umdrehungen in geschwindigkeit
const int measureTime = 3; // messzeitraum in sekunden
// variablrn
volatile unsigned int windCounter = 0; //interner zaehler für umdrehungen
float windSpeed = 0.0;
//initialisieren der variablen fŸr messwerte und die zeitmessung
//unsigned long time = 0;
//interrupt service routine fŸr das zaehlen der umdrehungen
void countWind() {
windCounter ++;
}
// lcd anzeige
void show_values() {
float h = dht.readHumidity();
float t = dht.readTemperature();
//erste Zeile - anzahl der gezaehlten umdrehungen im messzeitraum
lcd.begin(16, 4);
lcd.setCursor(0,0);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("U:");
lcd.print(windCounter);
lcd.print(" = ");
lcd.print(windSpeed);
lcd.print(" km/h ");
//zweite zeile - ermittelte geschwindigkeit
int val;
byte x, reading;
val = analogRead(PIN_VANE);
val >>=2; // Shift to 255 range
reading = val;
// Look the reading up in directions table. Find the first value
// that's >= to what we got.
for (x=0; x<NUMDIRS; x++) {
if (adc[x] >= reading)
break;
}
//Serial.println(reading, DEC);
x = (x + dirOffset) % 8;
// Adjust for orientation
lcd.setCursor(0,1);
lcd.print("aus: ");
lcd.print(strVals[x]);
lcd.setCursor(-4,2);
// lcd.print(t,1);
lcd.print(t/12+1,1);
lcd.print('\xDF');
lcd.print("C");
lcd.print(" / ");
// lcd.print(h/1.19,0);
lcd.print(h/1.19,0);
lcd.print("%");
lcd.setCursor(-4,3);
lcd.print (bmp.readTemperature()-1);
//lcd.print(" ");
lcd.print('\xDF');
lcd.print("C");
lcd.print(" ");
lcd.print (bmp.readPressure()/91.64,1 );
lcd.print(" hPa");
}
//initialisierung
void setup()
{
nextCalcDir = millis() + MSECS_CALC_WIND_DIR;
dht.begin();
bmp.begin();
//startzeit bestimmen
}
//hauptschleife
void loop()
{
nextCalcDir = time + MSECS_CALC_WIND_DIR;
//zaehler auf 0 stellen
windCounter = 0;
time = millis();
//zaehl-interrupt aktivieren
attachInterrupt(1,countWind,RISING);
//abwarten des messzeitraums
delay(1000 * measureTime);
//zaehl-interrupt deaktivieren
detachInterrupt(1);
//zeit bestimmen
time = (millis() - time) / 1000;
//berechnen der geschwindigkeit
windSpeed = (float)windCounter / (float)measureTime * windFactor;
show_values();
}
sieht dann so aus und funktioniert einwandfrei:
Nun mein Problem und da brauch ich Hilfe, ich probiere es seit Tagen
selbst aber ohne Erfolg:
Jetzt mochte ich das mit einem Ethernet Shield verbinden, was ebenfalls bereits funktioniert
aber die Windgeschwindigkeitsanzeige bleibt immer auf null. Alles andere klappt auf der HTML-Seite
funktioniert ebenfalls alles nur im Display bleibt Umdrehungen und Wind auf 0.
Hier der Sketch mit dem Ethernet Shield:
#include <LiquidCrystal.h>
#define uint unsigned int
#define ulong unsigned long
#define PIN_VANE 3
#define MSECS_CALC_WIND_DIR 1000
#include <DHT.h>
#define DHTPIN 2
#define DHTTYPE DHT22
#include <Ethernet.h>
#include <SPI.h>
#define NUMDIRS 8
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = {
192, 168, 0, 177};
Server server = Server(80);
DHT dht(DHTPIN, DHTTYPE);
volatile int numRevsAnemometer = 0;
ulong nextCalcDir;
ulong time;
float adcvalue = 1.1;
ulong adc[NUMDIRS] = {26, 45, 77, 118, 161, 196, 220, 256};
char *strVals[NUMDIRS] = {"NORDOST","NORD","NORDWEST","WEST","SUEDWEST","SUED","SUEDOST","OST"};
byte dirOffset=0;
const int windPin = 3;
const float windFactor = 2.97;
const int measureTime = 3;
// variablrn
volatile unsigned int windCounter = 0;
float windSpeed = 0.0;
//unsigned long time = 0;
void countWind() {
windCounter ++;
}
// lcd anzeige
void show_values() {
}
#include "Wire.h"
#include "Adafruit_BMP085.h"
void setup()
{
int val;
byte x, reading;
val = analogRead(PIN_VANE);
val >>=2;
reading = val;
for (x=0; x<NUMDIRS; x++) {
if (adc[x] >= reading)
break;
}
x = (x + dirOffset) % 8;
Adafruit_BMP085 bmp;
float h = dht.readHumidity();
float t = dht.readTemperature();
dht.begin();
bmp.begin();
lcd.clear();
lcd.begin(16, 4);
lcd.setCursor(0,0);
lcd.print("U:");
lcd.print(windCounter);
lcd.print(" = ");
lcd.print(windSpeed);
lcd.print(" km/h ");
nextCalcDir = millis() + MSECS_CALC_WIND_DIR;
lcd.setCursor(0,1);
lcd.print("aus: ");
lcd.print(strVals[x]);
lcd.setCursor(-4,2);
// lcd.print(t,1);
lcd.print(t/12+1,1);
lcd.print('\xDF');
lcd.print("C");
lcd.print(" / ");
lcd.print(h/1.19,0);
lcd.print("%");
lcd.setCursor(-4,3);
lcd.print (bmp.readTemperature()-1);
//lcd.print(" ");
lcd.print('\xDF');
lcd.print("C");
lcd.print(" ");
lcd.print (bmp.readPressure()/91.64,1 );
lcd.print(" hPa");
Ethernet.begin(mac, ip);
server.begin();
}
void loop()
{
Adafruit_BMP085 bmp;
bmp.begin();
float h = dht.readHumidity();
float t = dht.readTemperature();
int val;
byte x, reading;
val = analogRead(PIN_VANE);
val >>=2;
reading = val;
for (x=0; x<NUMDIRS; x++) {
if (adc[x] >= reading)
break;
}
x = (x + dirOffset) % 8;
Client client = server.available();
if (client) {
server.print("HTTP/1.0 200 OK\r\nServer: arduino\r\nContent-Type: text/html\r\n\r\n");
server.println("-");
server.println("-");
server.println(t/12+1,1);
server.println(h/1.19,0);
server.println(bmp.readPressure()/91.64,1 );
server.println("0.0"); //Regen
server.println(windSpeed);
server.println(strVals[x]);
server.println("Zeit");
server.println("Datum");
server.println(windCounter);
delay(100);
client.stop();
}
nextCalcDir = time + MSECS_CALC_WIND_DIR;
nextCalcDir = millis() + MSECS_CALC_WIND_DIR;
//zaehler auf 0 stellen
windCounter = 0;
time = millis();
//zaehl-interrupt aktivieren
attachInterrupt(1,countWind,RISING);
//abwarten des messzeitraums
delay(1000 * measureTime);
//zaehl-interrupt deaktivieren
detachInterrupt(1);
//zeit bestimmen
time = (millis() - time) / 1000;
//berechnen der geschwindigkeit
windSpeed = (float)windCounter / (float)measureTime * windFactor;
show_values();
}
was mach ich hier falsch, bzw. wo liegt der Fehler?
Bin für jede Hilfe dankbar!
[EDIT] Code Tags eingefügt. Grüße Uwe[/EDIT]