ok.. the problem is in the program i am using the sensor for.. in the testprogram it worked... but it does not work in this sketch...
//Temperatursensor
#include <OneWire.h>
#include <DallasTemperature.h>
OneWire ds(17); //pin für ds1820
int Temp1;
int Temp2;
int Temp3;
int Temp4;
int Temp5;
//DeviceAdressen der einzelnen ds1820 Temperatursensoren angeben. (loop anpassen)
DeviceAddress sensor1 = { 0x28, 0x70, 0x42, 0x8, 0x0, 0x0, 0x80, 0x7C };
DeviceAddress sensor2 = { 0x28, 0xFF, 0xC2, 0xA7, 0x74, 0x16, 0x4, 0x90 }; //Knoten
DeviceAddress sensor3 = { 0x28, 0xFF, 0xD, 0xF7, 0x74, 0x16, 0x4, 0x65 };
DeviceAddress sensor4 = { 0x28, 0xFF, 0x35, 0xA1, 0x73, 0x16, 0x05, 0x4A };
DeviceAddress sensor5 = { 0x28, 0xFF, 0x44, 0xB8, 0x74, 0x16, 0x4, 0x65 };
char sensorFName[] = "Wasserfluss: ";
char sensor1Name[] = "CPU: ";
char sensor2Name[] = "Wasser: ";
char sensor3Name[] = "nix:3 ";
char sensor4Name[] = "nix:4 ";
char sensor5Name[] = "nix:5 ";
//ende TEMP
//Durchflusssensor
volatile int NbTopsFan; //measuring the rising edges of the signal
int Calc;
int hallsensor = 19; //The pin location of the sensor
void rpm () //This is the function that the interupt calls
{
NbTopsFan++; //This function measures the rising and falling edge of the hall effect sensors signal
}
//ende Flow
// IMPORTANT: Adafruit_TFTLCD LIBRARY MUST BE SPECIFICALLY
// CONFIGURED FOR EITHER THE TFT SHIELD OR THE BREAKOUT BOARD.
// SEE RELEVANT COMMENTS IN Adafruit_TFTLCD.h FOR SETUP.
// Modified for SPFD5408 Library by Joao Lopes
// Version 0.9.2 - Rotation for Mega and screen initial
// *** SPFD5408 change -- Begin
#include <SPFD5408_Adafruit_GFX.h> // Core graphics library
#include <SPFD5408_Adafruit_TFTLCD.h> // Hardware-specific library
#include <SPFD5408_TouchScreen.h>
// *** SPFD5408 change -- End
// The control pins for the LCD can be assigned to any digital or
// analog pins...but we'll use the analog pins as this allows us to
// double up the pins with the touch screen (see the TFT paint example).
#define LCD_CS A3 // Chip Select goes to Analog 3
#define LCD_CD A2 // Command/Data goes to Analog 2
#define LCD_WR A1 // LCD Write goes to Analog 1
#define LCD_RD A0 // LCD Read goes to Analog 0
#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin
// Assign human-readable names to some common 16-bit color values:
#define BLACK 0xFFFF
#define BLUE 0xFFE0
#define RED 0x07FF
#define GREEN 0xF81F
#define CYAN 0x07E0
#define MAGENTA 0xF800
#define YELLOW 0x001F
#define WHITE 0x0000
Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
// If using the shield, all control and data lines are fixed, and
// a simpler declaration can optionally be used:
// Adafruit_TFTLCD tft;
// -- Setup
void setup(void) {
Serial.begin(9600);
#ifdef USE_ADAFRUIT_SHIELD_PINOUT
progmemPrintln(PSTR("Using Adafruit 2.8\" TFT Arduino Shield Pinout"));
#else
#endif
tft.reset();
tft.begin(0x9341); // SDFP5408
tft.setRotation(0); // Need for the Mega, please changed for your choice or rotation initial
//Temp anfang
}
void writeTimeToScratchpad(byte* address)
{
//reset the bus
ds.reset();
//select our sensor
ds.select(address);
//CONVERT T function call (44h) which puts the temperature into the scratchpad
ds.write(0x44,1);
//sleep a second for the write to take place
delay(1000);
}
void readTimeFromScratchpad(byte* address, byte* data)
{
//reset the bus
ds.reset();
//select our sensor
ds.select(address);
//read the scratchpad (BEh)
ds.write(0xBE);
for (byte i=0;i<9;i++){
data[i] = ds.read();
}
}
float getTemperature(byte* address)
{
int tr;
byte data[12];
writeTimeToScratchpad(address);
readTimeFromScratchpad(address,data);
//put in temp all the 8 bits of LSB (least significant byte)
tr = data[0];
if (address[0] == 0x10) // DS18S20
{
//check for negative temperature
if (data[1] > 0x80)
{
tr = !tr + 1; //two’s complement adjustment
tr = tr * -1; //flip value negative.
}
//drop bit 0
tr = tr >> 1;
//COUNT PER Celsius degree (10h)
int cpc = data[7];
//COUNT REMAIN (0Ch)
int cr = data[6];
return tr - (float)0.25 + (cpc - cr)/(float)cpc;
}
else // DS18B20
{
return ((data[1] << 8) + tr) * (float)0.0625;
}
//COUNT PER Celsius degree (10h)
int cpc = data[7];
//COUNT REMAIN (0Ch)
int cr = data[6];
//drop bit 0
tr = tr >> 1;
return tr - (float)0.25 + (cpc - cr)/(float)cpc;
// temp ende
//flow beginn
{
pinMode(hallsensor, INPUT); //initializes digital pin 2 as an input
Serial.begin(9600); //This is the setup function where the serial port is initialised,
attachInterrupt(4, rpm, RISING); //and the interrupt is attached
}
//flow ende
}
void loop(void) {
//Temp beginn
{
float temp1 = getTemperature(sensor1);
float temp2 = getTemperature(sensor2);
float temp3 = getTemperature(sensor3);
float temp4 = getTemperature(sensor4);
float temp5 = getTemperature(sensor5);
Temp1 = temp1;
Temp2 = temp2;
Temp3 = temp3;
Temp4 = temp4;
Temp5 = temp5;
Serial.print(sensor1Name);
Serial.print(temp1);
Serial.println(" Celsius");
Serial.print(sensor2Name);
Serial.print(temp2);
Serial.println(" Celsius");
Serial.print(sensor3Name);
Serial.print(temp3);
Serial.println(" Celsius");
Serial.print(sensor4Name);
Serial.print(temp4);
Serial.println(" Celsius");
Serial.print(sensor5Name);
Serial.print(temp5);
Serial.println(" Celsius");
Serial.println();
delay(500);
}
//Temp Ende
//Flow Beginn
NbTopsFan = 0; //Set NbTops to 0 ready for calculations
delay (500); //Wait 0,5 second
Calc = (NbTopsFan * 8); //(Pulse frequency x 60) / 7.5Q, = flow rate in L/hour
Serial.print (Calc, DEC); //Prints the number calculated above
Serial.print (" L/hour\r\n"); //Prints "L/hour" and returns a new line
//flow ende
for(uint8_t rotation=3; rotation<4; rotation++) {
tft.setRotation(rotation);
testText();
delay(500);
}
}
unsigned long testFillScreen() {
unsigned long start = micros();
tft.fillScreen(BLACK);
tft.fillScreen(RED);
tft.fillScreen(GREEN);
tft.fillScreen(BLUE);
tft.fillScreen(BLACK);
return micros() - start;
}
unsigned long testText()
{
tft.fillScreen(BLACK);
unsigned long start = micros();
tft.setCursor(0, 0);
tft.setTextColor(WHITE); tft.setTextSize(3);
tft.print(sensor1Name);
tft.setTextColor(YELLOW); tft.setTextSize(3);
tft.println(Temp1);
tft.setTextColor(RED); tft.setTextSize(3);
tft.print(sensor2Name);
tft.println(Temp2);
tft.setTextColor (BLUE);
tft.print(sensor3Name);
tft.println(Temp3);
tft.setTextColor (GREEN);
tft.print(sensor4Name);
tft.println(Temp4);
tft.setTextColor (CYAN);
tft.print(sensor5Name);
tft.println(Temp5);
tft.setTextColor (MAGENTA);
tft.print(sensorFName);
tft.setTextColor(GREEN);
tft.setTextSize(3);
tft.println(Calc, DEC);
tft.setTextSize(2);
tft.println();
tft.setTextSize(2);
tft.println();
return micros() - start;
}