Hallo zusammen
Ich bin totaler Anfänger und versuche mich an einem Projekt dessen Ziel es ist, die Temperatur und die Luftfeuchtigkeit eines Raumes zu messen und in eine Datenbank zu speichern, sowie die werte auf einem LCD abzuzeigen.
Als Hardware benutze ich einen Arduino UNO, einen DHT 11 Sensor, den Nokia 5110 LCD und als Ethernet shield eines mit dem enc28J60 Chip das ich bei Ebay gekauft habe.
Als Vorlage habe ich diesen sketch genommen
http://www.lucadentella.it/en/2013/04/22/enc28j60-e-arduino-14/
Nun zum Problem sobald ich das Ethernet shield initiiere kann ich den LCD nicht mehr ansteuern.
Ich dache erst es könnte an der Adafruit_GFX.h library liegen habe dann versucht das LCD ohne irgend eine library anzusprechen jedoch mit dem selben Ergebnis.
Wenn ich das LCD vor... (ether.begin(sizeof Ethernet::buffer, mymac,10)
anspreche geht es aber danach nicht mehr.
Angeschlossen habe ich die Hardware wie folgt
Nokia 5510 LCD:
CE --> Pin 9
RST --> Pin 8
D/C --> Pin 7
DN --> Pin 11
CLK --> Pin 13
enc28J60:
SCK --> Pin 13
SO --> Pin 12
SI --> Pin 11
CS --> Pin 10
Hier mein sketch ich weiss er ist nicht gut geschrieben, bin für jede konstruktive kritik offen
#include <EtherCard.h>
#include "DHT.h"
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
#define DHTPIN 2 // Pin von DHT
#define DHTTYPE DHT11 // Type vom DHT
DHT dht(DHTPIN, DHTTYPE);
// D7 - Serial clock out (CLK oder SCLK)
// D6 - Serial data out (DIN)
// D5 - Data/Command select (DC oder D/C)
// D4 - LCD chip select (CE oder CS)
// D3 - LCD reset (RST)
Adafruit_PCD8544 display = Adafruit_PCD8544(13, 11, 7, 9, 8);
#define SEND_INTERVAL 30000
#define TIMEOUT 5000
#define STATUS_IDLE 0
#define STATUS_SENT 1
static byte mymac[] = {0x74,0x69,0x69,0x2D,0x30,0x31};
byte Ethernet::buffer[500];
char website[] PROGMEM = "testweb.test.local";
char password[] PROGMEM = "password";
unsigned long previousMillis = 0;
static byte session_id;
byte actual_status;
void setup () {
Serial.begin(9600);
Serial.println(F("Raummonitor Datenbank"));
Serial.println();
display.begin();
display.setContrast(30);
display.clearDisplay();
if (!ether.begin(sizeof Ethernet::buffer, mymac,10)) {
Serial.println(F( "Fehler beim erreichen des Ethernet controllers"));
while(1);
} else Serial.println(F("Ethernet controller bereit"));
if (!ether.dhcpSetup()) {
Serial.println(F("Fehler configuration DHCP"));
while(1);
} else Serial.println(F("DHCP Erfolgreich"));
if (!ether.dnsLookup(website)) {
Serial.print(F("DNS Fehler"));
while(1);
} else Serial.println(F("Website IP erfolgreich"));
}
void loop()
{
sendtodispay();
ether.packetLoop(ether.packetReceive());
unsigned long currentMillis = millis();
switch(actual_status) {
case STATUS_IDLE:
if(currentMillis - previousMillis > SEND_INTERVAL) {
previousMillis = currentMillis;
sendTemperature();
}
break;
case STATUS_SENT:
if(currentMillis - previousMillis > TIMEOUT) {
Serial.println(F("keine Antwort"));
previousMillis = currentMillis;
actual_status = STATUS_IDLE;
}
checkResponse();
}
}
void sendTemperature() {
float float_temp = dht.readTemperature();
float float_humidity = dht.readHumidity();
char string_temp[7];
dtostrf(float_temp, 4, 2, string_temp);
char string_humidity[7];
dtostrf(float_humidity, 4, 2, string_humidity);
Stash stash;
byte sd = stash.create();
stash.print(string_temp);
stash.save();
Stash stash2;
byte hd = stash.create();
stash.print(string_humidity);
stash.save();
Stash::prepare(PSTR("GET /saveTemp.php?temp=$H&humidity=$H&pwd=$F HTTP/1.0" "\r\n"
"Host: $F" "\r\n" "\r\n"),
sd, hd, password, website);
session_id = ether.tcpSend();
Serial.print(F("Temperature "));
Serial.print(string_temp);
Serial.print(F(" Luftfeuchtikeit "));
Serial.print(string_humidity);
Serial.print(F(" erfolgreich abgeschickt... "));
actual_status = STATUS_SENT;
}
void checkResponse() {
const char* reply = ether.tcpReply(session_id);
if(reply > 0) {
if(strstr(reply, "KO - ") != 0) Serial.println(strstr(reply, "KO - "));
else Serial.println(F("OK"));
actual_status = STATUS_IDLE;
}
}
void sendtodispay()
{
String Humidity = "";
String Temp = "";
int h = dht.readHumidity();
int t = dht.readTemperature();
Humidity += h;
Temp += t;
display.setTextSize(1);
set_text(0,0,"Humidity: " + Humidity + "%",BLACK);
set_text(0,10,"Temp: " + Temp + "C",BLACK);
Humidity = "";
Temp = "";
display.clearDisplay();
}
void set_text(int x,int y,String text,int color){
display.setTextColor(color); // Textfarbe setzen, also Schwarz oder Weiss
display.setCursor(x,y); // Startpunkt-Position des Textes
display.println(text); // Textzeile ausgeben
display.display(); // Display aktualisieren
}
Kann mir jemand mit meinem Problem weiter helfen ?