• Witaj na Forum Arduino Polska! Zapraszamy do rejestracji!
  • Znajdziesz tutaj wiele informacji na temat hardware / software.
Witaj! Logowanie Rejestracja


Ocena wątku:
  • 0 głosów - średnia: 0
  • 1
  • 2
  • 3
  • 4
  • 5
Miernik temperatury wilgotności i ciśnienia
#9
Coś namieszałem i nie chce mi to działać
Kod wygląda teraz tak:

Kod:
#include <DS1307RTC.h>
#include <Time.h>
#include <OneWire.h>
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include <LiquidCrystal_I2C.h>
#define BACKLIGHT_PIN 3
LiquidCrystal_I2C  lcd(0x27,2,1,0,4,5,6,7);
#define BME_SCK 13
#define BME_MISO 12
#define BME_MOSI 11
#define BME_CS 10

#define SEALEVELPRESSURE_HPA (1013.25)

OneWire  ds(10);  // on pin 10 (a 4.7K resistor is necessary)
Adafruit_BME280 bme; // I2C

const char *monthName[12] = {
 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
 "Jul", "Aug", "09", "Oct", "Nov", "Dec"
};
 byte temp[8] = //ikona temperatury
{
   B00100,
   B01010,
   B01010,
   B01110,
   B01110,
   B11111,
   B11111,
   B01110
};

byte wilg[8] = //ikona wilgotnosci
{
   B00100,
   B00100,
   B01010,
   B10001,
   B10001,
   B10001,
   B01110,
};

byte stopnie[8] = //ikona stopni
{
       B01100,
       B10010,
       B10010,
       B01100,
       B00000,
       B00000,
       B00000,
       B00000
};

byte procent[8] = //ikona procentu
{
       B00000,
       B11000,
       B11010,
       B00110,
       B01100,
       B01011,
       B00011,
       B00000
};
unsigned long odczyt = 0; //forum
unsigned long czas = 0;//forum
unsigned long z = 0;//forum
byte lcd = 1;//forum
byte strona = 1; //forum

void setup(void) {
 Serial.begin(9600);
//  Serial.println(F("BME280 test"));

  lcd.begin(20, 4);
  lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
  lcd.setBacklight(HIGH);
  lcd.createChar(0, temp);
  lcd.createChar(1, wilg);
  lcd.createChar(3, stopnie);
  lcd.createChar(4, procent);
 
 if (!bme.begin()) {
//    Serial.println("Could not find a valid BME280 sensor, check wiring!");
   while (1);
 }
}

void loop() {
 unsigned long sek = millis()/1000 ;
 if ( (millis()-czas) >= 5000 ){czas = millis();
 if (strona == 2){strona = 1;}
 else if(strona == 1){strona = 2;}}
 
 if ( (millis()-odczyt) >= 2000 ){ //forum
 byte i;
 byte present = 0;
 byte type_s;
 byte data[12];
 byte addr[8];
 float celsius, fahrenheit;
 
 if ( !ds.search(addr)) {
//    Serial.println("No more addresses.");
//    Serial.println();
   ds.reset_search();
//  delay(1000);
   return;
 }
 
//  Serial.print("ROM =");
 for( i = 0; i < 8; i++) {
//    Serial.write(' ');
//    Serial.print(addr[i], HEX);
 }

 if (OneWire::crc8(addr, 7) != addr[7]) {
//      Serial.println("CRC is not valid!");
     return;
 }
//  Serial.println();
 
 // the first ROM byte indicates which chip
 switch (addr[0]) {
   case 0x10:
//      Serial.println("  Chip = DS18S20");  // or old DS1820
     type_s = 1;
     break;
   case 0x28:
//      Serial.println("  Chip = DS18B20");
     type_s = 0;
     break;
   case 0x22:
//     Serial.println("  Chip = DS1822");
     type_s = 0;
     break;
   default:
//      Serial.println("Device is not a DS18x20 family device.");
     return;
 }

 ds.reset();
 ds.select(addr);
 ds.write(0x44, 1);      
 
// delay(1000);    
 
 present = ds.reset();
 ds.select(addr);    
 ds.write(0xBE);      

//  Serial.print("  Data = ");
//  Serial.print(present, HEX);
//  Serial.print(" ");
 for ( i = 0; i < 9; i++) {          
   data[i] = ds.read();
//    Serial.print(data[i], HEX);
//    Serial.print(" ");
 }
//  Serial.print(" CRC=");
//  Serial.print(OneWire::crc8(data, 8), HEX);
//  Serial.println();

 
 int16_t raw = (data[1] << 8) | data[0];
 if (type_s) {
   raw = raw << 3; // 9 bit resolution default
   if (data[7] == 0x10) {
     // "count remain" gives full 12 bit resolution
     raw = (raw & 0xFFF0) + 12 - data[6];
   }
 } else {
   byte cfg = (data[4] & 0x60);
   // at lower res, the low bits are undefined, so let's zero them
   if (cfg == 0x00) raw = raw & ~7;  // 9 bit resolution, 93.75 ms
   else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
   else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
   //// default is 12 bit resolution, 750 ms conversion time
 }
 celsius = (float)raw / 16.0;
 fahrenheit = celsius * 1.8 + 32.0;
//  Serial.print("  Temperature = ");
//  Serial.print(celsius);
//  Serial.print(" Celsius, ");
//  Serial.print(fahrenheit);
//  Serial.println(" Fahrenheit");
case 1:

if (lcd != 1){srlcd.clear();lcd = 1;} //czyszczenie ekranu 1
   lcd.setCursor (0, 2);
   lcd.write(byte(0));
   lcd.print("=");
   lcd.print(bme.readTemperature(), 1);
   lcd.write(byte(3));
   lcd.print("C");

   lcd.setCursor (9, 2);
   lcd.print("P=");
   lcd.print(bme.readPressure() / 100.0F, 1);
   lcd.print("hPa");

   lcd.setCursor (0, 3);
   lcd.write(byte(0));
   lcd.print("=");
   lcd.print(celsius, 1);
   lcd.write(byte(3));
   lcd.print("C");

   lcd.setCursor (9, 3);
   lcd.write(byte(1));
   lcd.write("=");
   lcd.print(bme.readHumidity(), 1);
   lcd.print("%");
odczyt = millis(); //forum
break;
}//forum
//zegar
tmElements_t tm;

 if (RTC.read(tm)) {
   case 2:

if (lcd != 2){srlcd.clear();lcd = 2;} //czyszczenie ekranu 2
 }

//    lcd.setCursor (0, 0);
//    lcd.print("Godzina");
   lcd.setCursor (6, 0);
   LCDprint2digits(tm.Hour);
   lcd.print(':');
   LCDprint2digits(tm.Minute);
   lcd.print(':');
   LCDprint2digits(tm.Second);
//    lcd.setCursor (0, 1);
//    lcd.print("Data");
   lcd.setCursor (5, 1);
   lcd.print(tm.Day);
   lcd.print('/');
   lcd.print(monthName[tm.Month-1]);
   lcd.print('/');
   lcd.print(tmYearToCalendar(tm.Year));
      //wyswietlacz

   
 } else {
   if (RTC.chipPresent()) {
     lcd.println("DS1307 stoi. Uruchom Zegar");
     }
      else {
     lcd.println("DS1307 blad oczczytu!");
     lcd.println("sprawdz polaczenie");
   }
//    delay(9000);
 }
//  delay(1000);
}

//void print2digits(int number) {
//  if (number >= 0 && number < 10) {
//    Serial.write('0');
//  }
//  Serial.print(number);
//}
 
void LCDprint2digits(int number) {
 if (number >= 0 && number < 10) {
   lcd.write('0');
 }
 lcd.print(number);

break;
     //bme280
//    Serial.print("Temperature = ");
//    Serial.print(bme.readTemperature());
//    Serial.println(" *C");

//    Serial.print("Pressure = ");

//    Serial.print(bme.readPressure() / 100.0F);
//    Serial.println(" hPa");

//    Serial.print("Approx. Altitude = ");
//    Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
//    Serial.println(" m");

//    Serial.print("Humidity = ");
//    Serial.print(bme.readHumidity());
//    Serial.println(" %");

//    Serial.println();
//    delay(500);
switch (strona) {
}

I nie chce mi to działać.
Pomocy, co zrobiłem źle?
 
Odpowiedź
  


Wiadomości w tym wątku
RE: Miernik temperatury wilgotności i ciśnienia - przez zbyszek78 - 28-09-2015, 18:19

Skocz do:


Przeglądający: 1 gości