Hallo,
ich möchte gerne mit meinem Mega 2560 + 16x2 Display und zwei DS18S20 zwei Temperaturen messen. Ein DS18S20 soll die Temperatur in meinem Aquarium messen und der andere die Temperatur im Unterschrank.
Die Temperatur im Aquarium messe ich bereits mit nachfolgenden Sketch. Nun soll ein weiterer DS18S20 mit eingebunden werden und zur Anzeige gebracht werden. So wie in etwa ein Innen- und Außenthermometer.
Z.Z. habe ich den einen DS18S20 wie im Bild dargestellt angeschlossen.
#include <LiquidCrystal.h>
#include "Wire.h"
#include <OneWire.h>
#define DS1307_I2C_ADDRESS 0x68 // This is the I2C address
// Arduino version compatibility Pre-Compiler Directives
#if defined(ARDUINO) && ARDUINO >= 100 // Arduino v1.0 and newer
#define I2C_WRITE Wire.write
#define I2C_READ Wire.read
#else
#define I2C_WRITE Wire.send
#define I2C_READ Wire.receive
#endif
// Initialisierung des LCD
LiquidCrystal lcd(22, 23, 24, 25, 26, 27);
OneWire ds(28);
// Globale Variablen
byte i;
byte present = 0;
byte data[12];
byte addr[8];
float Temp;
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
int u, j, k = 0;
//float temp_in, temp_out;
byte zero;
char *Day[] = {"","So","Mo","Di","Mi","Do","Fr","Sa"};
char *Mon[] = {"","Jan.","Feb.","Mar.","Apr.","Mai.","Jun.","Jul.","Aug.","Sep.","Okt.","Nov.","Dez."};
// Wandelt BCD-Werte in Dezimalwerte um
byte bcdToDec(byte val)
{
return ( (val/16*10) + (val%16) );
}
// Daten von RTC erhalten
void getDateDs1307()
{
// Reset the register pointer
Wire.beginTransmission(DS1307_I2C_ADDRESS);
I2C_WRITE(zero);
Wire.endTransmission();
Wire.requestFrom(DS1307_I2C_ADDRESS, 7);
}
void setup()
{
// Start des IIC-Modi
Wire.begin();
};
void loop()
{
// Ausgabe von Datum und Uhrzeit inkl. Abfrageroutine der IIC-RTC
while(u <= 10)//die Zeit für der Anzeigendauer
{
Wire.beginTransmission(DS1307_I2C_ADDRESS);
I2C_WRITE(zero);
Wire.endTransmission();
Wire.requestFrom(DS1307_I2C_ADDRESS, 7);
// Maskierung der Bits vom RTC-Modul
second = bcdToDec(I2C_READ() & 0x7f);
minute = bcdToDec(I2C_READ());
hour = bcdToDec(I2C_READ() & 0x3f); // Need to change this if 12 hour am/pm
dayOfWeek = bcdToDec(I2C_READ());
dayOfMonth = bcdToDec(I2C_READ());
month = bcdToDec(I2C_READ());
year = bcdToDec(I2C_READ());
// Ausgabe des Datums im Format DD,_dd._mmm._'yy
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(Day[dayOfWeek]);
lcd.print(", ");
if (dayOfMonth < 10)
lcd.print("0");
lcd.print(dayOfMonth, DEC);
lcd.print(".");
lcd.print(" ");
lcd.print(Mon[month]);
lcd.print(" '");
lcd.println(year, DEC);
// Ausgabe der Uhrzeit im Format hh:mm:ss
lcd.setCursor(4, 1);
if (hour < 10)
lcd.print("0");
lcd.print(hour, DEC);
lcd.print(":");
if (minute < 10)
lcd.print("0");
lcd.print(minute, DEC);
lcd.print(":");
if (second < 10)
lcd.print("0");
lcd.print(second, DEC);
lcd.print(" ");
lcd.noCursor();
u++;
delay(500);
j = 0;
k = 0;
};
while(j <= 10)
{
// display Sensor data on LCD:
if ( !ds.search(addr)) {
// No more Dallas chips present:
Serial.print("No more addresses.\n");
ds.reset_search();
//delay(250);
//return;
// Check for family code which is not DS18B20:
if ( addr[0] != 0x28) {
Serial.print("Device is not a DS18B20 family device.\n");
return;
}
// The DallasTemperature library can do all this work for you!
ds.reset();
ds.select(addr);
ds.write(0x44,0); // start conversion, with parasite power off
present = ds.reset();
ds.select(addr);
ds.write(0xBE); // Read Scratchpad
// Check whether chip is present:
present = ds.reset();
ds.select(addr);
ds.write(0xBE); // Read Scratchpad
Serial.print("P="); // Present = 1
Serial.print(present,HEX);
Serial.print(" ");
for ( i = 0; i < 9; i++) { // we need 9 bytes of data
data[i] = ds.read();
Serial.print(data[i], HEX);
Serial.print(" ");
}
Serial.print(" CRC=");
Serial.print( OneWire::crc8( data, 8), HEX);
// Calculate temperature. data[1] High Byte, data[0] Low Byte.
Temp = ((data[1] << 8) + data[0] ) * 0.0625; // 12Bit = 0,0625 C per Bit
Serial.print( " T=");
Serial.print( Temp, 2);
Serial.print( " C");
Serial.println();
}
char line[17];
lcd.clear();
lcd.setCursor(0,0);
//sprintf(line, "T=%f C", Temp); funktioniert nicht, Fehler in Compiler?
dtostrf(Temp, 5, 2, line);
lcd.print("T=");
lcd.print(line);
lcd.print(" C");
j++;
delay(500);
u = 0;
};
}
Meine Frage wäre nun, wie binde ich einen zweiten DS18S20 in die Schaltung und in den Sketch ein?
Danke.
Gruß Jens
