1

Тема: bmp280

Основная статья - http://rcl-radio.ru/?p=132560

Serial port

#include <Wire.h>

#define ADDR 0b1110110

#define OSRS_T 0b101
// 000 Skipped (output set to 0x80000) –
// 001 ×1 16 bit / 0.0050 °C
// 010 ×2 17 bit / 0.0025 °C
// 011 ×4 18 bit / 0.0012 °C
// 100 ×8 19 bit / 0.0006 °C
// 101, 110, 111 ×16 20 bit / 0.0003 °C
#define OSRS_P 0b110
// 000 Skipped (output set to 0x80000) –
// 001 ×1 16 bit / 2.62 Pa
// 010 ×2 17 bit / 1.31 Pa
// 011 ×4 18 bit / 0.66 Pa
// 100 ×8 19 bit / 0.33 Pa
// 101, 110, 111 ×16 20 bit / 0.16 Pa
#define MODE 0b11
// 00 Sleep mode
// 01 and 10 Forced mode
// 11 Normal mode
#define FILTER 0b001
// 000 Filter off Full
// 001 2 0.223 × ODR
// 010 4 0.092 × ODR
// 011 8 0.042 × ODR
// 100, others 16 0.021 × ODR
#define STANDBY 0b110
// 000 0.5 ms
// 001 62.5 ms
// 010 125 ms
// 011 250 ms
// 100 500 ms
// 101 1000 ms
// 110 2000 ms
// 111 4000 ms

 uint32_t t1,p1, temp_dig,press_dig;
 int32_t t2,t3,p2,p3,p4,p5,p6,p7,p8,p9;

void setup() {
  Serial.begin(9600);
  Wire.begin();
  I2C_write(0xE0, 0xB6);// reset
  I2C_write(0xF5, (STANDBY<<5) | (FILTER<<2));
  I2C_write(0xF4, (OSRS_T<<5)|(OSRS_P<<2)|MODE); // osrs_t settings
  delay(200);
  t1 = (int32_t)I2C_read(0x89) << 8 | I2C_read(0x88);
  t2 = I2C_read(0x8B) << 8 | I2C_read(0x8A);
  t3 = I2C_read(0x8D) << 8 | I2C_read(0x8C);
  p1 = (int32_t)I2C_read(0x8F) << 8 | I2C_read(0x8E);
  p2 = I2C_read(0x91) << 8 | I2C_read(0x90);
  p3 = I2C_read(0x93) << 8 | I2C_read(0x92);
  p4 = I2C_read(0x95) << 8 | I2C_read(0x94);
  p5 = I2C_read(0x97) << 8 | I2C_read(0x96);
  p6 = I2C_read(0x99) << 8 | I2C_read(0x98);
  p7 = I2C_read(0x9B) << 8 | I2C_read(0x9A);
  p8 = I2C_read(0x9D) << 8 | I2C_read(0x9C);
  p9 = I2C_read(0x9F) << 8 | I2C_read(0x9E);
  Serial.print("ID = 0x");Serial.println(I2C_read(0xD0), HEX); // ID 58
  Serial.print("t1 = ");Serial.println(t1);
  Serial.print("t2 = ");Serial.println(t2);
  Serial.print("t3 = ");Serial.println(t3);
  Serial.print("p1 = ");Serial.println(p1);
  Serial.print("p2 = ");Serial.println(p2);
  Serial.print("p3 = ");Serial.println(p3);
  Serial.print("p4 = ");Serial.println(p4);
  Serial.print("p5 = ");Serial.println(p5);
  Serial.print("p6 = ");Serial.println(p6);
  Serial.print("p7 = ");Serial.println(p7);
  Serial.print("p8 = ");Serial.println(p8);
  Serial.print("p9 = ");Serial.println(p9);
  Serial.println();
}

void loop() {
  temp_dig = (int32_t)I2C_read(0xFA)<<12 | (int32_t)I2C_read(0xFB)<<4 | (I2C_read(0xFC) & 0xF0)>>4;

  double var1, var2, T;
  var1 = (((double)temp_dig)/16384.0 - ((double)t1)/1024.0) * ((double)t2);
  var2 = ((((double)temp_dig)/131072.0 - ((double)t1)/8192.0) *(((double)temp_dig)/131072.0 - ((double) t1)/8192.0)) * ((double)t3);
  int32_t t_fine = (int32_t)(var1 + var2);
  T = (var1 + var2) / 5120.0;

  int32_t qT;
  var1 = ((((temp_dig>>3) - ((uint32_t)t1<<1))) * ((uint32_t)t2)) >> 11;
  var2 = (((((temp_dig>>4) - ((uint32_t)t1)) * ((temp_dig>>4) - ((uint32_t)t1))) >> 12) *((int32_t)abs(t3))) >> 14;
  uint32_t qt_fine = var1 + var2;
  qT = (qt_fine * 5 + 128) >> 8;

  press_dig = (int32_t)I2C_read(0xF7)<<12 | (int32_t)I2C_read(0xF8)<<4 | (I2C_read(0xF9)&0xF0)>>4;

  double p;
  var1 = ((double)t_fine/2.0) - 64000.0;
  var2 = var1 * var1 * ((double)p6) / 32768.0;
  var2 = var2 + var1 * ((double)p5) * 2.0;
  var2 = (var2/4.0)+(((double)p4) * 65536.0);
  var1 = (((double)p3) * var1 * var1 / 524288.0 + ((double)p2) * var1) / 524288.0;
  var1 = (1.0 + var1 / 32768.0)*((double)p1);
  if (var1 == 0.0){return 0;}
  p = 1048576.0 - (double)press_dig;
  p = (p - (var2 / 4096.0)) * 6250.0 / var1;
  var1 = ((double)p9) * p * p / 2147483648.0;
  var2 = p * ((double)p8) / 32768.0;
  p = p + (var1 + var2 + ((double)p7)) / 16.0;

 
  int32_t zvar1, zvar2;
  uint32_t zp;
  zvar1 = (((int32_t)t_fine)>>1)-(int32_t)64000;
  zvar2 = (((zvar1>>2) * (zvar1>>2)) >> 11 ) * ((int32_t)p6);
  zvar2 = zvar2 + ((zvar1*((int32_t)p5))<<1);
  zvar2 = (zvar2>>2)+(((int32_t)p4)<<16);
  zvar1 = (((p3 * (((zvar1>>2) * (zvar1>>2)) >> 13 )) >> 3) + ((((int32_t)p2) * zvar1)>>1))>>18;
  zvar1 =((((32768+zvar1))*((int32_t)p1))>>15);
  if (zvar1 == 0){return 0; }
  zp = (((uint32_t)(((int32_t)1048576)-press_dig)-(zvar2>>12)))*3125;
  if (zp < 0x80000000){zp = (zp << 1) / ((uint32_t)zvar1);}
  else{zp = (zp / (uint32_t)zvar1) * 2;}
  zvar1 = (((int32_t)p9) * ((int32_t)(((zp>>3) * (zp>>3))>>13)))>>12;
  zvar2 = (((int32_t)(zp>>2)) * ((int32_t)p8))>>13;
  zp = (uint32_t)((int32_t)zp + ((zvar1 + zvar2 + p7) >> 4));

  Serial.print("T(float) = ");Serial.print(T,2);Serial.println(" °C");
  Serial.print("T(int32_t) = ");Serial.println(qT);
  Serial.print("P(float) = ");Serial.print(p,2); Serial.println(" Pa");
  Serial.print("P(int32_t) = ");Serial.print(zp); Serial.println(" Pa");
  Serial.print("P = ");Serial.print(p/133.3224,2); Serial.println(" mmHg");
  
  Serial.println();
  delay(2000);

}

byte I2C_read(byte reg){
  Wire.beginTransmission(ADDR);
  Wire.write(reg);
  Wire.endTransmission();
  Wire.requestFrom(ADDR,1);
  while(Wire.available()<1);
  byte value = Wire.read();
  return value;
  } 

void I2C_write(byte reg, byte data){  
  Wire.beginTransmission(ADDR);
  Wire.write(reg);
  Wire.write(data);
  Wire.endTransmission();
  }    

2

Re: bmp280

BMP280+ATTINY2313+7-и сегментный 4 разрядный индикатор MAX7219

#include <avr/io.h>
#include <util/delay.h>

// MAX7219
#define DIN PB2
#define CLK PB3
#define CS  PB4 
// BMP280
#define SDA  PB0
#define SCL  PB1
#define ADDR 0b11101100

#define OSRS_T 0b001
// 000 Skipped (output set to 0x80000) –
// 001 ×1 16 bit / 0.0050 °C
// 010 ×2 17 bit / 0.0025 °C
// 011 ×4 18 bit / 0.0012 °C
// 100 ×8 19 bit / 0.0006 °C
// 101, 110, 111 ×16 20 bit / 0.0003 °C
#define OSRS_P 0b001
// 000 Skipped (output set to 0x80000) –
// 001 ×1 16 bit / 2.62 Pa
// 010 ×2 17 bit / 1.31 Pa
// 011 ×4 18 bit / 0.66 Pa
// 100 ×8 19 bit / 0.33 Pa
// 101, 110, 111 ×16 20 bit / 0.16 Pa
#define MODE 0b11
// 00 Sleep mode
// 01 and 10 Forced mode
// 11 Normal mode
#define FILTER 0b001
// 000 Filter off Full
// 001 2 0.223 × ODR
// 010 4 0.092 × ODR
// 011 8 0.042 × ODR
// 100, others 16 0.021 × ODR
#define STANDBY 0b110
// 000 0.5 ms
// 001 62.5 ms
// 010 125 ms
// 011 250 ms
// 100 500 ms
// 101 1000 ms
// 110 2000 ms
// 111 4000 ms



 unsigned long t1,p1, temp_dig,press_dig;
 int tic, dat;
 byte dp;
 
int main(void)  {
    DDRB |=(1<<DIN)|(1<<CLK)|(1<<CS); 
  //  PORTB |=(1<<DIN)|(1<<CLK)|(1<<CS);
    WriteBit16(0x0F, 0);// тест выкл.
    WriteBit16(0x0C, 1);// вкл. индик.
    WriteBit16(0x0A, 2);// яркость
    WriteBit16(0x09, 0xFF);// дешифраторы вкл.
    WriteBit16(0x0B, 3);// кол-во разрядов  
 //   I2C_write(0xE0, 0xB6);// reset
    I2C_write(0xF5, (STANDBY<<5) | (FILTER<<2));
    I2C_write(0xF4, (OSRS_T<<5)|(OSRS_P<<2)|MODE); // osrs_t settings
 //  _delay_ms(200);
    t1 = (long)I2C_read(0x89) << 8 | I2C_read(0x88);
   // t2 = I2C_read(0x8B) << 8 | I2C_read(0x8A);
   // t3 = I2C_read(0x8D) << 8 | I2C_read(0x8C);
   // p1 = (long)I2C_read(0x8F) << 8 | I2C_read(0x8E);
   // p2 = I2C_read(0x91) << 8 | I2C_read(0x90);
   // p3 = I2C_read(0x93) << 8 | I2C_read(0x92);
   // p4 = I2C_read(0x95) << 8 | I2C_read(0x94);
   // p5 = I2C_read(0x97) << 8 | I2C_read(0x96);
   // p6 = I2C_read(0x99) << 8 | I2C_read(0x98);
   // p7 = I2C_read(0x9B) << 8 | I2C_read(0x9A);
   // p8 = I2C_read(0x9D) << 8 | I2C_read(0x9C);
   // p9 = I2C_read(0x9F) << 8 | I2C_read(0x9E);

while(1) { 
  temp_dig = (unsigned long)I2C_read(0xFA)<<12 | (unsigned int)I2C_read(0xFB)<<4;
  long var1, var2, qT;
  var1 = ((((temp_dig>>3) - ((unsigned long)t1<<1))) * ((unsigned long)(I2C_read(0x8B) << 8 | I2C_read(0x8A)))) >> 11;
  var2 = (((((temp_dig>>4) - ((unsigned long)t1)) * ((temp_dig>>4) - ((unsigned long)t1))) >> 12) *((long)abs(I2C_read(0x8D) << 8 | I2C_read(0x8C)))) >> 14;
  unsigned long qt_fine = var1 + var2;
  qT = (qt_fine * 5 + 128) >> 8;


  press_dig = (unsigned long)I2C_read(0xF7)<<12 | (unsigned int)I2C_read(0xF8)<<4;
  uint32_t zp;
  var1 = (((int32_t)qt_fine)>>1)-(int32_t)64000;
  var2 = (((var1>>2) * (var1>>2)) >> 11 ) * ((int32_t)(I2C_read(0x99) << 8 | I2C_read(0x98)));
  var2 = var2 + ((var1*((int32_t)(I2C_read(0x97) << 8 | I2C_read(0x96))))<<1);
  var2 = (var2>>2)+(((int32_t)(I2C_read(0x95) << 8 | I2C_read(0x94)))<<16);
  var1 = ((((I2C_read(0x93) << 8 | I2C_read(0x92)) * (((var1>>2) * (var1>>2)) >> 13 )) >> 3) + ((((int32_t)(I2C_read(0x91) << 8 | I2C_read(0x90))) * var1)>>1))>>18;
  var1 =((((32768+var1))*((int32_t)((long)I2C_read(0x8F) << 8 | I2C_read(0x8E))))>>15);
  zp = (((uint32_t)(((int32_t)1048576)-press_dig)-(var2>>12)))*3125;
  if (zp < 0x80000000){zp = (zp << 1) / ((uint32_t)var1);}
  else{zp = (zp / (uint32_t)var1) * 2;}
  var1 = (((int32_t)(I2C_read(0x9F) << 8 | I2C_read(0x9E))) * ((int32_t)(((zp>>3) * (zp>>3))>>13)))>>12;
  var2 = (((int32_t)(zp>>2)) * ((int32_t)(I2C_read(0x9D) << 8 | I2C_read(0x9C))))>>13;
  zp = (uint32_t)((int32_t)zp + ((var1 + var2 + (I2C_read(0x99) << 8 | I2C_read(0x98))) >> 4));

  if(tic<8){dat = qT;dp=0xF0;}else{dat=zp/133;dp=0;}
  
 if(dp==0){WriteBit16(1,15);}else{ WriteBit16(1, dat/1000%10);}
  WriteBit16(2, dat/100%10 + dp);// запятая
  WriteBit16(3, dat/10%10);
  WriteBit16(4, dat%10);
  
 _delay_ms(1000); 
 tic++;if(tic>10){tic=0;}


}}
 
void WriteBit16(byte reg, byte data){  
     PORTB &=~(1<<CLK);PORTB &=~(1<<CS);
     for(int i = 7; i >= 0; i--){
        if(((reg >> i) & 1) == 1){PORTB |=(1<<DIN);}
         else{PORTB &=~(1<<DIN);}
        PORTB |=(1<<CLK);PORTB &=~(1<<CLK);
        }
     for(int i = 7; i >= 0; i--){
        if(((data >> i) & 1) == 1){PORTB |=(1<<DIN);}
         else{PORTB &=~(1<<DIN);}
        PORTB |=(1<<CLK);PORTB &=~(1<<CLK);
        }
     PORTB |=(1<<CS);PORTB &=~(1<<CLK);PORTB &=~(1<<DIN);
  }   
 
bool i2c_read_bit() {
    bool i2c_bit = 1;        
    DDRB &= ~(1 << SDA);            
    _delay_us(10); 
    DDRB &= ~(1 << SCL);                
    if((PINB >> SDA) & 1) i2c_bit=0;                            
    _delay_us(10);  
    DDRB |= (1 << SCL);              
    return i2c_bit;  
}
 
byte i2c_write_byte(byte data){
    for (byte i=0; i<8; i++){i2c_write_bit((data&0x80)==0);data<<=1;}    
    return i2c_read_bit(); 
}
 
void i2c_write_bit(byte b){
    if(b){DDRB |= (1 << SDA);}else{DDRB &= ~(1 << SDA);}
    DDRB &= ~(1 << SCL);       
    _delay_us(10);
    DDRB |= (1 << SCL);
}
 
void i2c_start(){
     _delay_us(10);  
     DDRB &= ~(1 << SDA); DDRB &= ~(1 << SCL); 
     _delay_us(10); 
     DDRB |= (1 << SDA);  PORTB &= ~(1 << SDA);
     _delay_us(10); 
     DDRB |= (1 << SCL);  PORTB &= ~(1 << SCL);   
     _delay_us(10);
}
 
void i2c_stop()  {
     DDRB |= (1 << SDA);            
     DDRB &= ~(1 << SCL);               
     DDRB &= ~(1 << SDA);             
}

byte i2c_read_byte(byte a){
    byte i, data=0;                
    for(i=0; i<8; i++){if (!i2c_read_bit()) data++;if(i!=7) data<<=1;}        
    i2c_write_bit(a);return data;  
}
 

byte I2C_read(byte reg){
     byte data = 0;
     i2c_start();
     i2c_write_byte(ADDR);
     i2c_write_byte(reg);
     i2c_start(); 
     i2c_write_byte(ADDR+1); 
     data = i2c_read_byte(0);
     i2c_stop();
     return data;
  }
 
void I2C_write(byte reg, byte data){
     i2c_start();
     i2c_write_byte(ADDR);
     i2c_write_byte(reg);
     i2c_write_byte(data);
     i2c_stop();
  } 

3

Re: bmp280

BMP280+atmega88+7-и сегментный 4 разрядный индикатор MAX7219

#include  <Wire.h>

// MAX7219
#define DIN PB2
#define CLK PB3
#define CS  PB4 
// BMP280 sda scl
#define ADDR 0b1110110

#define OSRS_T 0b101
// 000 Skipped (output set to 0x80000) –
// 001 ×1 16 bit / 0.0050 °C
// 010 ×2 17 bit / 0.0025 °C
// 011 ×4 18 bit / 0.0012 °C
// 100 ×8 19 bit / 0.0006 °C
// 101, 110, 111 ×16 20 bit / 0.0003 °C
#define OSRS_P 0b101
// 000 Skipped (output set to 0x80000) –
// 001 ×1 16 bit / 2.62 Pa
// 010 ×2 17 bit / 1.31 Pa
// 011 ×4 18 bit / 0.66 Pa
// 100 ×8 19 bit / 0.33 Pa
// 101, 110, 111 ×16 20 bit / 0.16 Pa
#define MODE 0b11
// 00 Sleep mode
// 01 and 10 Forced mode
// 11 Normal mode
#define FILTER 0b001
// 000 Filter off Full
// 001 2 0.223 × ODR
// 010 4 0.092 × ODR
// 011 8 0.042 × ODR
// 100, others 16 0.021 × ODR
#define STANDBY 0b110
// 000 0.5 ms
// 001 62.5 ms
// 010 125 ms
// 011 250 ms
// 100 500 ms
// 101 1000 ms
// 110 2000 ms
// 111 4000 ms


 unsigned long t1,p1, temp_dig,press_dig;
 long t2,t3,p2,p3,p4,p5,p6,p7,p8,p9;
 int tic, dat;
 byte dp,dp0;
 
void setup(){  
    Wire.begin();
    DDRB |=(1<<DIN)|(1<<CLK)|(1<<CS); 
    PORTB |=(1<<DIN)|(1<<CLK)|(1<<CS);
    WriteBit16(0x0F, 0);// тест выкл.
    WriteBit16(0x0C, 1);// вкл. индик.
    WriteBit16(0x0A, 2);// яркость
    WriteBit16(0x09, 0xFF);// дешифраторы вкл.
    WriteBit16(0x0B, 3);// кол-во разрядов  
    I2C_write(0xE0, 0xB6);// reset
    I2C_write(0xF5, (STANDBY<<5) | (FILTER<<2));
    I2C_write(0xF4, (OSRS_T<<5)|(OSRS_P<<2)|MODE); // osrs_t settings
    delay(200);
    t1 = (long)I2C_read(0x89) << 8 | I2C_read(0x88);
    t2 = I2C_read(0x8B) << 8 | I2C_read(0x8A);
    t3 = I2C_read(0x8D) << 8 | I2C_read(0x8C);
    p1 = (long)I2C_read(0x8F) << 8 | I2C_read(0x8E);
    p2 = I2C_read(0x91) << 8 | I2C_read(0x90);
    p3 = I2C_read(0x93) << 8 | I2C_read(0x92);
    p4 = I2C_read(0x95) << 8 | I2C_read(0x94);
    p5 = I2C_read(0x97) << 8 | I2C_read(0x96);
    p6 = I2C_read(0x99) << 8 | I2C_read(0x98);
    p7 = I2C_read(0x9B) << 8 | I2C_read(0x9A);
    p8 = I2C_read(0x9D) << 8 | I2C_read(0x9C);
    p9 = I2C_read(0x9F) << 8 | I2C_read(0x9E);
}

void loop(){ 
  temp_dig = (long)I2C_read(0xFA)<<12 | (long)I2C_read(0xFB)<<4 | (I2C_read(0xFC) & 0xF0)>>4;
  double var1, var2, T;
  var1 = (((double)temp_dig)/16384.0 - ((double)t1)/1024.0) * ((double)t2);
  var2 = ((((double)temp_dig)/131072.0 - ((double)t1)/8192.0) *(((double)temp_dig)/131072.0 - ((double) t1)/8192.0)) * ((double)t3);
  long t_fine = (long)(var1 + var2);
  T = (var1 + var2) / 5120.0;


  press_dig = (long)I2C_read(0xF7)<<12 | (long)I2C_read(0xF8)<<4 | (I2C_read(0xF9)&0xF0)>>4;
  double p;
  var1 = ((double)t_fine/2.0) - 64000.0;
  var2 = var1 * var1 * ((double)p6) / 32768.0;
  var2 = var2 + var1 * ((double)p5) * 2.0;
  var2 = (var2/4.0)+(((double)p4) * 65536.0);
  var1 = (((double)p3) * var1 * var1 / 524288.0 + ((double)p2) * var1) / 524288.0;
  var1 = (1.0 + var1 / 32768.0)*((double)p1);
  if (var1 == 0.0){return 0;}
  p = 1048576.0 - (double)press_dig;
  p = (p - (var2 / 4096.0)) * 6250.0 / var1;
  var1 = ((double)p9) * p * p / 2147483648.0;
  var2 = p * ((double)p8) / 32768.0;
  p = p + (var1 + var2 + ((double)p7)) / 16.0;

  if(tic<8){dat = T*100;dp=0xF0;dp0=0;}else{dat=p/13.33224;dp=0;dp0=0xf0;}
  
  WriteBit16(1, dat/1000%10);
  WriteBit16(2, dat/100%10 + dp);
  WriteBit16(3, dat/10%10 + dp0);
  WriteBit16(4, dat%10);
  
 delay(1000); 
 tic++;if(tic>10){tic=0;}
}
 
void WriteBit16(byte reg, byte data){  
     PORTB &=~(1<<CLK);PORTB &=~(1<<CS);
     for(int i = 7; i >= 0; i--){
        if(((reg >> i) & 1) == 1){PORTB |=(1<<DIN);}
         else{PORTB &=~(1<<DIN);}
        PORTB |=(1<<CLK);PORTB &=~(1<<CLK);
        }
     for(int i = 7; i >= 0; i--){
        if(((data >> i) & 1) == 1){PORTB |=(1<<DIN);}
         else{PORTB &=~(1<<DIN);}
        PORTB |=(1<<CLK);PORTB &=~(1<<CLK);
        }
     PORTB |=(1<<CS);PORTB &=~(1<<CLK);PORTB &=~(1<<DIN);
  }   
 
byte I2C_read(byte reg){ // I2C
  Wire.beginTransmission(ADDR);
  Wire.write (reg);
  Wire.endTransmission();
  Wire.requestFrom(ADDR,1);
  while(Wire.available()<1);
  byte value = Wire.read();
  return value;
  }  
 
void I2C_write(byte reg, byte data){
  Wire.beginTransmission(ADDR);
  Wire.write (reg);
  Wire.write (data);
  Wire.endTransmission();
  } 

4

Re: bmp280

BMP280+DHT11+atmega88+7-и сегментный 4 разрядный индикатор MAX7219


#include  <Wire.h>


// MAX7219
#define DIN PB2
#define CLK PB3
#define CS  PB4 
// BMP280 sda scl
#define ADDR 0b1110110
// DHT11 out
#define DHT PC0

#define OSRS_T 0b101
// 000 Skipped (output set to 0x80000) –
// 001 ×1 16 bit / 0.0050 °C
// 010 ×2 17 bit / 0.0025 °C
// 011 ×4 18 bit / 0.0012 °C
// 100 ×8 19 bit / 0.0006 °C
// 101, 110, 111 ×16 20 bit / 0.0003 °C
#define OSRS_P 0b101
// 000 Skipped (output set to 0x80000) –
// 001 ×1 16 bit / 2.62 Pa
// 010 ×2 17 bit / 1.31 Pa
// 011 ×4 18 bit / 0.66 Pa
// 100 ×8 19 bit / 0.33 Pa
// 101, 110, 111 ×16 20 bit / 0.16 Pa
#define MODE 0b11
// 00 Sleep mode
// 01 and 10 Forced mode
// 11 Normal mode
#define FILTER 0b001
// 000 Filter off Full
// 001 2 0.223 × ODR
// 010 4 0.092 × ODR
// 011 8 0.042 × ODR
// 100, others 16 0.021 × ODR
#define STANDBY 0b110
// 000 0.5 ms
// 001 62.5 ms
// 010 125 ms
// 011 250 ms
// 100 500 ms
// 101 1000 ms
// 110 2000 ms
// 111 4000 ms


 unsigned long t1,p1, temp_dig,press_dig;
 long t2,t3,p2,p3,p4,p5,p6,p7,p8,p9;
 int tic, dat;
 byte dp,dp0;
 byte data_dht[5];
 
void setup(){  
    Wire.begin();
    DDRB |=(1<<DIN)|(1<<CLK)|(1<<CS); 
    PORTB |=(1<<DIN)|(1<<CLK)|(1<<CS);
    WriteBit16(0x0F, 0);// тест выкл.
    WriteBit16(0x0C, 1);// вкл. индик.
    WriteBit16(0x0A, 2);// яркость
    WriteBit16(0x09, 0xFF);// дешифраторы вкл.
    WriteBit16(0x0B, 3);// кол-во разрядов  
    I2C_write(0xE0, 0xB6);// reset
    I2C_write(0xF5, (STANDBY<<5) | (FILTER<<2));
    I2C_write(0xF4, (OSRS_T<<5)|(OSRS_P<<2)|MODE); // osrs_t settings
    delay(200);
    t1 = (long)I2C_read(0x89) << 8 | I2C_read(0x88);
    t2 = I2C_read(0x8B) << 8 | I2C_read(0x8A);
    t3 = I2C_read(0x8D) << 8 | I2C_read(0x8C);
    p1 = (long)I2C_read(0x8F) << 8 | I2C_read(0x8E);
    p2 = I2C_read(0x91) << 8 | I2C_read(0x90);
    p3 = I2C_read(0x93) << 8 | I2C_read(0x92);
    p4 = I2C_read(0x95) << 8 | I2C_read(0x94);
    p5 = I2C_read(0x97) << 8 | I2C_read(0x96);
    p6 = I2C_read(0x99) << 8 | I2C_read(0x98);
    p7 = I2C_read(0x9B) << 8 | I2C_read(0x9A);
    p8 = I2C_read(0x9D) << 8 | I2C_read(0x9C);
    p9 = I2C_read(0x9F) << 8 | I2C_read(0x9E);
}

void loop(){ 
  temp_dig = (long)I2C_read(0xFA)<<12 | (long)I2C_read(0xFB)<<4 | (I2C_read(0xFC) & 0xF0)>>4;
  double var1, var2, T;
  var1 = (((double)temp_dig)/16384.0 - ((double)t1)/1024.0) * ((double)t2);
  var2 = ((((double)temp_dig)/131072.0 - ((double)t1)/8192.0) *(((double)temp_dig)/131072.0 - ((double) t1)/8192.0)) * ((double)t3);
  long t_fine = (long)(var1 + var2);
  T = (var1 + var2) / 5120.0;


  press_dig = (long)I2C_read(0xF7)<<12 | (long)I2C_read(0xF8)<<4 | (I2C_read(0xF9)&0xF0)>>4;
  double p;
  var1 = ((double)t_fine/2.0) - 64000.0;
  var2 = var1 * var1 * ((double)p6) / 32768.0;
  var2 = var2 + var1 * ((double)p5) * 2.0;
  var2 = (var2/4.0)+(((double)p4) * 65536.0);
  var1 = (((double)p3) * var1 * var1 / 524288.0 + ((double)p2) * var1) / 524288.0;
  var1 = (1.0 + var1 / 32768.0)*((double)p1);
  if (var1 == 0.0){return 0;}
  p = 1048576.0 - (double)press_dig;
  p = (p - (var2 / 4096.0)) * 6250.0 / var1;
  var1 = ((double)p9) * p * p / 2147483648.0;
  var2 = p * ((double)p8) / 32768.0;
  p = p + (var1 + var2 + ((double)p7)) / 16.0;
  
  
  dht_read();
  
  delay(2000); 
  
  int h = data_dht[0];

  if(tic<3){dat = T*100;dp=0xF0;dp0=0;}
  if(tic>=3 && tic<=4){dat=p/13.33224;dp=0;dp0=0xf0;}
  
  if(tic>4){dat=h;dp=0;dp0=0;}
  
 if(tic>4){WriteBit16(1,15);}else{WriteBit16(1, dat/1000%10);}
 if(tic>4){WriteBit16(2,15);}else{WriteBit16(2, dat/100%10 + dp);}
  WriteBit16(3, dat/10%10 + dp0);
  WriteBit16(4, dat%10);
  
 tic++;if(tic>5){tic=0;}
}
 
void WriteBit16(byte reg, byte data){  
     PORTB &=~(1<<CLK);PORTB &=~(1<<CS);
     for(int i = 7; i >= 0; i--){
        if(((reg >> i) & 1) == 1){PORTB |=(1<<DIN);}
         else{PORTB &=~(1<<DIN);}
        PORTB |=(1<<CLK);PORTB &=~(1<<CLK);
        }
     for(int i = 7; i >= 0; i--){
        if(((data >> i) & 1) == 1){PORTB |=(1<<DIN);}
         else{PORTB &=~(1<<DIN);}
        PORTB |=(1<<CLK);PORTB &=~(1<<CLK);
        }
     PORTB |=(1<<CS);PORTB &=~(1<<CLK);PORTB &=~(1<<DIN);
  }   
 
byte I2C_read(byte reg){ // I2C
  Wire.beginTransmission(ADDR);
  Wire.write (reg);
  Wire.endTransmission();
  Wire.requestFrom(ADDR,1);
  while(Wire.available()<1);
  byte value = Wire.read();
  return value;
  }  
 
void I2C_write(byte reg, byte data){
  Wire.beginTransmission(ADDR);
  Wire.write (reg);
  Wire.write (data);
  Wire.endTransmission();
  } 

int dht_read(){
        byte ii = 0,i1 = 0;  
        for(ii = 0;ii < 5;ii++){data_dht[ii] = 0;}                  
        DDRC |=(1 << DHT); 
        PORTC &= ~(1 << DHT); 
        delay(18); 
        PORTC |= (1 << DHT);
        delayMicroseconds(40); 
        DDRC &= ~(1 << DHT); 
        delayMicroseconds(80); 
    while(PINC & (1 << DHT));
      for (ii = 0; ii < 5; ii++){
        data_dht[ii]=0;
      for (i1=0; i1<8; i1++){
    while(!(PINC & (1 << DHT)));  
        delayMicroseconds(30);
      if (PINC & (1 << DHT)){data_dht[ii] |= 1 << (7-i1);}
    while(PINC & (1 << DHT));  
}}return 1;}

5

Re: bmp280

bmp280 + lcd1602_i2c + lgt8f328

#include <Wire.h>

#define RS           0
#define E            2
#define LED          3
#define ADDR_LED     0x27

#define ADDR 0b1110110

#define OSRS_T 0b101
// 000 Skipped (output set to 0x80000) –
// 001 ×1 16 bit / 0.0050 °C
// 010 ×2 17 bit / 0.0025 °C
// 011 ×4 18 bit / 0.0012 °C
// 100 ×8 19 bit / 0.0006 °C
// 101, 110, 111 ×16 20 bit / 0.0003 °C
#define OSRS_P 0b110
// 000 Skipped (output set to 0x80000) –
// 001 ×1 16 bit / 2.62 Pa
// 010 ×2 17 bit / 1.31 Pa
// 011 ×4 18 bit / 0.66 Pa
// 100 ×8 19 bit / 0.33 Pa
// 101, 110, 111 ×16 20 bit / 0.16 Pa
#define MODE 0b11
// 00 Sleep mode
// 01 and 10 Forced mode
// 11 Normal mode
#define FILTER 0b001
// 000 Filter off Full
// 001 2 0.223 × ODR
// 010 4 0.092 × ODR
// 011 8 0.042 × ODR
// 100, others 16 0.021 × ODR
#define STANDBY 0b110
// 000 0.5 ms
// 001 62.5 ms
// 010 125 ms
// 011 250 ms
// 100 500 ms
// 101 1000 ms
// 110 2000 ms
// 111 4000 ms

 uint32_t t1,p1, temp_dig,press_dig;
 int32_t t2,t3,p2,p3,p4,p5,p6,p7,p8,p9;
 byte led_b;

void setup() {
  Serial.begin(9600);
  Wire.begin();
  I2C_write_bmp(0xE0, 0xB6);// reset
  I2C_write_bmp(0xF5, (STANDBY<<5) | (FILTER<<2));
  I2C_write_bmp(0xF4, (OSRS_T<<5)|(OSRS_P<<2)|MODE); // osrs_t settings
  delay(200);
  t1 = (int32_t)I2C_read(0x89) << 8 | I2C_read(0x88);
  t2 = I2C_read(0x8B) << 8 | I2C_read(0x8A);
  t3 = I2C_read(0x8D) << 8 | I2C_read(0x8C);
  p1 = (int32_t)I2C_read(0x8F) << 8 | I2C_read(0x8E);
  p2 = I2C_read(0x91) << 8 | I2C_read(0x90);
  p3 = I2C_read(0x93) << 8 | I2C_read(0x92);
  p4 = I2C_read(0x95) << 8 | I2C_read(0x94);
  p5 = I2C_read(0x97) << 8 | I2C_read(0x96);
  p6 = I2C_read(0x99) << 8 | I2C_read(0x98);
  p7 = I2C_read(0x9B) << 8 | I2C_read(0x9A);
  p8 = I2C_read(0x9D) << 8 | I2C_read(0x9C);
  p9 = I2C_read(0x9F) << 8 | I2C_read(0x9E);
  Serial.print("ID = 0x");Serial.println(I2C_read(0xD0), HEX); // ID 58
  Serial.print("t1 = ");Serial.println(t1);
  Serial.print("t2 = ");Serial.println(t2);
  Serial.print("t3 = ");Serial.println(t3);
  Serial.print("p1 = ");Serial.println(p1);
  Serial.print("p2 = ");Serial.println(p2);
  Serial.print("p3 = ");Serial.println(p3);
  Serial.print("p4 = ");Serial.println(p4);
  Serial.print("p5 = ");Serial.println(p5);
  Serial.print("p6 = ");Serial.println(p6);
  Serial.print("p7 = ");Serial.println(p7);
  Serial.print("p8 = ");Serial.println(p8);
  Serial.print("p9 = ");Serial.println(p9);
  Serial.println();
  setInit();
  Clear(); // очистка экрана
  led(1);  // включение и отключение подсветки экрана
  Curs(0,5);
  PrintString("BMP280 ");
  delay(2000);Clear();
}

void loop() {
  temp_dig = (int32_t)I2C_read(0xFA)<<12 | (int32_t)I2C_read(0xFB)<<4 | (I2C_read(0xFC) & 0xF0)>>4;

  double var1, var2, T;
  var1 = (((double)temp_dig)/16384.0 - ((double)t1)/1024.0) * ((double)t2);
  var2 = ((((double)temp_dig)/131072.0 - ((double)t1)/8192.0) *(((double)temp_dig)/131072.0 - ((double) t1)/8192.0)) * ((double)t3);
  int32_t t_fine = (int32_t)(var1 + var2);
  T = (var1 + var2) / 5120.0;

  int32_t qT;
  var1 = ((((temp_dig>>3) - ((uint32_t)t1<<1))) * ((uint32_t)t2)) >> 11;
  var2 = (((((temp_dig>>4) - ((uint32_t)t1)) * ((temp_dig>>4) - ((uint32_t)t1))) >> 12) *((int32_t)abs(t3))) >> 14;
  uint32_t qt_fine = var1 + var2;
  qT = (qt_fine * 5 + 128) >> 8;

  press_dig = (int32_t)I2C_read(0xF7)<<12 | (int32_t)I2C_read(0xF8)<<4 | (I2C_read(0xF9)&0xF0)>>4;

  double p;
  var1 = ((double)t_fine/2.0) - 64000.0;
  var2 = var1 * var1 * ((double)p6) / 32768.0;
  var2 = var2 + var1 * ((double)p5) * 2.0;
  var2 = (var2/4.0)+(((double)p4) * 65536.0);
  var1 = (((double)p3) * var1 * var1 / 524288.0 + ((double)p2) * var1) / 524288.0;
  var1 = (1.0 + var1 / 32768.0)*((double)p1);
  if (var1 == 0.0){return 0;}
  p = 1048576.0 - (double)press_dig;
  p = (p - (var2 / 4096.0)) * 6250.0 / var1;
  var1 = ((double)p9) * p * p / 2147483648.0;
  var2 = p * ((double)p8) / 32768.0;
  p = p + (var1 + var2 + ((double)p7)) / 16.0;

 
  int32_t zvar1, zvar2;
  uint32_t zp;
  zvar1 = (((int32_t)t_fine)>>1)-(int32_t)64000;
  zvar2 = (((zvar1>>2) * (zvar1>>2)) >> 11 ) * ((int32_t)p6);
  zvar2 = zvar2 + ((zvar1*((int32_t)p5))<<1);
  zvar2 = (zvar2>>2)+(((int32_t)p4)<<16);
  zvar1 = (((p3 * (((zvar1>>2) * (zvar1>>2)) >> 13 )) >> 3) + ((((int32_t)p2) * zvar1)>>1))>>18;
  zvar1 =((((32768+zvar1))*((int32_t)p1))>>15);
  if (zvar1 == 0){return 0; }
  zp = (((uint32_t)(((int32_t)1048576)-press_dig)-(zvar2>>12)))*3125;
  if (zp < 0x80000000){zp = (zp << 1) / ((uint32_t)zvar1);}
  else{zp = (zp / (uint32_t)zvar1) * 2;}
  zvar1 = (((int32_t)p9) * ((int32_t)(((zp>>3) * (zp>>3))>>13)))>>12;
  zvar2 = (((int32_t)(zp>>2)) * ((int32_t)p8))>>13;
  zp = (uint32_t)((int32_t)zp + ((zvar1 + zvar2 + p7) >> 4));

  Serial.print("T(float) = ");Serial.print(T,2);Serial.println(" °C");
  Serial.print("T(int32_t) = ");Serial.println(qT);
  Serial.print("P(float) = ");Serial.print(p,2); Serial.println(" Pa");
  Serial.print("P(int32_t) = ");Serial.print(zp); Serial.println(" Pa");
  Serial.print("P = ");Serial.print(p/133.3224,2); Serial.println(" mmHg");
  
  Serial.println();

  Curs(0,0);
  PrintString("T = ");PrintFloat(T,5,2);PrintString(" ");PrintChar(223);PrintString("C  ");
  Curs(1,0);
  PrintString("P = ");PrintFloat(p/133.3224,5,1);PrintString(" mmHg  ");
  
  delay(2000);
}

void led(bool led_on_off){
    if(led_on_off==1){I2C_write_lcd(led_b |= (1<<LED));}
    if(led_on_off==0){I2C_write_lcd(led_b &=~ (1<<LED));}
}
 
void Write(byte addr_w, byte wr1,byte wr2,byte wr3,byte wr4,byte wr5,byte wr6,byte wr7,byte wr8){
     lcd(0b01000000|addr_w*8);PrintChar(wr1);PrintChar(wr2);PrintChar(wr3);PrintChar(wr4);PrintChar(wr5);PrintChar(wr6);PrintChar(wr7);PrintChar(wr8);}
 
void PrintInt(int data_int){char str[6];PrintString(itoa(data_int, str, 10));} 
 
void PrintFloat(float data_float, int len , byte dp){
    char str_data[len];
    PrintString(dtostrf(data_float, len, dp, str_data));
} 
 
void setInit(){ 
    lcd(0x03);delayMicroseconds(4500);
    lcd(0x03);delayMicroseconds(4500);
    lcd(0x03);delayMicroseconds(200);
    lcd(0b00000010);delay(5);
    lcd(0b00001100);delay(5);
    lcd(0b00000001);
} 
 
void Clear(){lcd(0b00000001);} 
 
void Curs(byte str, byte mesto){
  if(str==0){lcd(0b10000000+mesto);}
  if(str==1){lcd(0b11000000+mesto);}
  } 
 
void PrintString(const char* str) {while(*str != '\0') {delayMicroseconds(200);PrintChar(*str);str++;}}
 
void PrintChar(const char chr) {lcdSend(false, (uint8_t)chr);}
 
void e_pin(){
    I2C_write_lcd(led_b |= (1<<E));
    delayMicroseconds(200);
    I2C_write_lcd(led_b &= ~(1<<E));
}
 
void lcd(uint8_t sett) {lcdSend(true, sett);}
 
void lcdSend(bool rs, byte data) {
    if(rs==0){led_b |= (1<<RS);} else {led_b &= ~(1<<RS);}//RS
    delayMicroseconds(200);
    if(((data >> 7) & 1) ==1){I2C_write_lcd(led_b |= (1<<7));} else {I2C_write_lcd(led_b &= ~(1<<7));}
    if(((data >> 6) & 1) ==1){I2C_write_lcd(led_b |= (1<<6));} else {I2C_write_lcd(led_b &= ~(1<<6));}
    if(((data >> 5) & 1) ==1){I2C_write_lcd(led_b |= (1<<5));} else {I2C_write_lcd(led_b &= ~(1<<5));}
    if(((data >> 4) & 1) ==1){I2C_write_lcd(led_b |= (1<<4));} else {I2C_write_lcd(led_b &= ~(1<<4));}
    e_pin();
    if(((data >> 3) & 1) ==1){I2C_write_lcd(led_b |= (1<<7));} else {I2C_write_lcd(led_b &= ~(1<<7));}
    if(((data >> 2) & 1) ==1){I2C_write_lcd(led_b |= (1<<6));} else {I2C_write_lcd(led_b &= ~(1<<6));}
    if(((data >> 1) & 1) ==1){I2C_write_lcd(led_b |= (1<<5));} else {I2C_write_lcd(led_b &= ~(1<<5));}
    if(((data >> 0) & 1) ==1){I2C_write_lcd(led_b |= (1<<4));} else {I2C_write_lcd(led_b &= ~(1<<4));}
    e_pin();
}

byte I2C_read(byte reg){
  Wire.beginTransmission(ADDR);
  Wire.write(reg);
  Wire.endTransmission();
  Wire.requestFrom(ADDR,1);
  while(Wire.available()<1);
  byte value = Wire.read();
  return value;
  } 

void I2C_write_bmp(byte reg, byte data){  
  Wire.beginTransmission(ADDR);
  Wire.write(reg);
  Wire.write(data);
  Wire.endTransmission();
  }   

void I2C_write_lcd(byte data){  
  Wire.beginTransmission(ADDR_LED);
  Wire.write(data);
  Wire.endTransmission();
  }    

6

Re: bmp280

http://forum.rcl-radio.ru/uploads/images/2024/09/af482a7f05a230df1d1f6d088a21d690.png

7

Re: bmp280

bmp280 + dht11 + lcd1602_i2c + lgt8f328

#include <Wire.h>

#define RS           0
#define E            2
#define LED          3
#define ADDR_LED     0x27

#define ADDR 0b1110110

#define OSRS_T 0b101
// 000 Skipped (output set to 0x80000) –
// 001 ×1 16 bit / 0.0050 °C
// 010 ×2 17 bit / 0.0025 °C
// 011 ×4 18 bit / 0.0012 °C
// 100 ×8 19 bit / 0.0006 °C
// 101, 110, 111 ×16 20 bit / 0.0003 °C
#define OSRS_P 0b110
// 000 Skipped (output set to 0x80000) –
// 001 ×1 16 bit / 2.62 Pa
// 010 ×2 17 bit / 1.31 Pa
// 011 ×4 18 bit / 0.66 Pa
// 100 ×8 19 bit / 0.33 Pa
// 101, 110, 111 ×16 20 bit / 0.16 Pa
#define MODE 0b11
// 00 Sleep mode
// 01 and 10 Forced mode
// 11 Normal mode
#define FILTER 0b001
// 000 Filter off Full
// 001 2 0.223 × ODR
// 010 4 0.092 × ODR
// 011 8 0.042 × ODR
// 100, others 16 0.021 × ODR
#define STANDBY 0b110
// 000 0.5 ms
// 001 62.5 ms
// 010 125 ms
// 011 250 ms
// 100 500 ms
// 101 1000 ms
// 110 2000 ms
// 111 4000 ms

// DHT11 out
#define DHT PC0 // A0

 uint32_t t1,p1, temp_dig,press_dig;
 int32_t t2,t3,p2,p3,p4,p5,p6,p7,p8,p9;
 byte led_b;
 byte data_dht[5];

void setup() {
  Serial.begin(9600);
  Wire.begin();
  I2C_write_bmp(0xE0, 0xB6);// reset
  I2C_write_bmp(0xF5, (STANDBY<<5) | (FILTER<<2));
  I2C_write_bmp(0xF4, (OSRS_T<<5)|(OSRS_P<<2)|MODE); // osrs_t settings
  delay(200);
  t1 = (int32_t)I2C_read(0x89) << 8 | I2C_read(0x88);
  t2 = I2C_read(0x8B) << 8 | I2C_read(0x8A);
  t3 = I2C_read(0x8D) << 8 | I2C_read(0x8C);
  p1 = (int32_t)I2C_read(0x8F) << 8 | I2C_read(0x8E);
  p2 = I2C_read(0x91) << 8 | I2C_read(0x90);
  p3 = I2C_read(0x93) << 8 | I2C_read(0x92);
  p4 = I2C_read(0x95) << 8 | I2C_read(0x94);
  p5 = I2C_read(0x97) << 8 | I2C_read(0x96);
  p6 = I2C_read(0x99) << 8 | I2C_read(0x98);
  p7 = I2C_read(0x9B) << 8 | I2C_read(0x9A);
  p8 = I2C_read(0x9D) << 8 | I2C_read(0x9C);
  p9 = I2C_read(0x9F) << 8 | I2C_read(0x9E);
  Serial.print("ID = 0x");Serial.println(I2C_read(0xD0), HEX); // ID 58
  Serial.print("t1 = ");Serial.println(t1);
  Serial.print("t2 = ");Serial.println(t2);
  Serial.print("t3 = ");Serial.println(t3);
  Serial.print("p1 = ");Serial.println(p1);
  Serial.print("p2 = ");Serial.println(p2);
  Serial.print("p3 = ");Serial.println(p3);
  Serial.print("p4 = ");Serial.println(p4);
  Serial.print("p5 = ");Serial.println(p5);
  Serial.print("p6 = ");Serial.println(p6);
  Serial.print("p7 = ");Serial.println(p7);
  Serial.print("p8 = ");Serial.println(p8);
  Serial.print("p9 = ");Serial.println(p9);
  Serial.println();
  setInit();
  Clear(); // очистка экрана
  led(1);  // включение и отключение подсветки экрана
  Curs(0,5);
  PrintString("BMP280 ");
  delay(2000);Clear();
}

void loop() {
  temp_dig = (int32_t)I2C_read(0xFA)<<12 | (int32_t)I2C_read(0xFB)<<4 | (I2C_read(0xFC) & 0xF0)>>4;

  double var1, var2, T;
  var1 = (((double)temp_dig)/16384.0 - ((double)t1)/1024.0) * ((double)t2);
  var2 = ((((double)temp_dig)/131072.0 - ((double)t1)/8192.0) *(((double)temp_dig)/131072.0 - ((double) t1)/8192.0)) * ((double)t3);
  int32_t t_fine = (int32_t)(var1 + var2);
  T = (var1 + var2) / 5120.0;

  int32_t qT;
  var1 = ((((temp_dig>>3) - ((uint32_t)t1<<1))) * ((uint32_t)t2)) >> 11;
  var2 = (((((temp_dig>>4) - ((uint32_t)t1)) * ((temp_dig>>4) - ((uint32_t)t1))) >> 12) *((int32_t)abs(t3))) >> 14;
  uint32_t qt_fine = var1 + var2;
  qT = (qt_fine * 5 + 128) >> 8;

  press_dig = (int32_t)I2C_read(0xF7)<<12 | (int32_t)I2C_read(0xF8)<<4 | (I2C_read(0xF9)&0xF0)>>4;

  double p;
  var1 = ((double)t_fine/2.0) - 64000.0;
  var2 = var1 * var1 * ((double)p6) / 32768.0;
  var2 = var2 + var1 * ((double)p5) * 2.0;
  var2 = (var2/4.0)+(((double)p4) * 65536.0);
  var1 = (((double)p3) * var1 * var1 / 524288.0 + ((double)p2) * var1) / 524288.0;
  var1 = (1.0 + var1 / 32768.0)*((double)p1);
  if (var1 == 0.0){return 0;}
  p = 1048576.0 - (double)press_dig;
  p = (p - (var2 / 4096.0)) * 6250.0 / var1;
  var1 = ((double)p9) * p * p / 2147483648.0;
  var2 = p * ((double)p8) / 32768.0;
  p = p + (var1 + var2 + ((double)p7)) / 16.0;

 
  int32_t zvar1, zvar2;
  uint32_t zp;
  zvar1 = (((int32_t)t_fine)>>1)-(int32_t)64000;
  zvar2 = (((zvar1>>2) * (zvar1>>2)) >> 11 ) * ((int32_t)p6);
  zvar2 = zvar2 + ((zvar1*((int32_t)p5))<<1);
  zvar2 = (zvar2>>2)+(((int32_t)p4)<<16);
  zvar1 = (((p3 * (((zvar1>>2) * (zvar1>>2)) >> 13 )) >> 3) + ((((int32_t)p2) * zvar1)>>1))>>18;
  zvar1 =((((32768+zvar1))*((int32_t)p1))>>15);
  if (zvar1 == 0){return 0; }
  zp = (((uint32_t)(((int32_t)1048576)-press_dig)-(zvar2>>12)))*3125;
  if (zp < 0x80000000){zp = (zp << 1) / ((uint32_t)zvar1);}
  else{zp = (zp / (uint32_t)zvar1) * 2;}
  zvar1 = (((int32_t)p9) * ((int32_t)(((zp>>3) * (zp>>3))>>13)))>>12;
  zvar2 = (((int32_t)(zp>>2)) * ((int32_t)p8))>>13;
  zp = (uint32_t)((int32_t)zp + ((zvar1 + zvar2 + p7) >> 4));

  Serial.print("T(float) = ");Serial.print(T,2);Serial.println(" °C");
  Serial.print("T(int32_t) = ");Serial.println(qT);
  Serial.print("P(float) = ");Serial.print(p,2); Serial.println(" Pa");
  Serial.print("P(int32_t) = ");Serial.print(zp); Serial.println(" Pa");
  Serial.print("P = ");Serial.print(p/133.3224,2); Serial.println(" mmHg");
  
  Serial.println();

  dht_read();
  
  delay(2000);
  int h = data_dht[0];
  
  Curs(0,0);
  PrintString("T = ");PrintFloat(T,5,2);PrintString(" ");PrintChar(223);PrintString("C  ");
  Curs(0,13);PrintInt(h);PrintString("% ");
  Curs(1,0);
  PrintString("P = ");PrintFloat(p/133.3224,5,1);PrintString(" mmHg  ");
}

void led(bool led_on_off){
    if(led_on_off==1){I2C_write_lcd(led_b |= (1<<LED));}
    if(led_on_off==0){I2C_write_lcd(led_b &=~ (1<<LED));}
}
 
void Write(byte addr_w, byte wr1,byte wr2,byte wr3,byte wr4,byte wr5,byte wr6,byte wr7,byte wr8){
     lcd(0b01000000|addr_w*8);PrintChar(wr1);PrintChar(wr2);PrintChar(wr3);PrintChar(wr4);PrintChar(wr5);PrintChar(wr6);PrintChar(wr7);PrintChar(wr8);}
 
void PrintInt(int data_int){char str[6];PrintString(itoa(data_int, str, 10));} 
 
void PrintFloat(float data_float, int len , byte dp){
    char str_data[len];
    PrintString(dtostrf(data_float, len, dp, str_data));
} 
 
void setInit(){ 
    lcd(0x03);delayMicroseconds(4500);
    lcd(0x03);delayMicroseconds(4500);
    lcd(0x03);delayMicroseconds(200);
    lcd(0b00000010);delay(5);
    lcd(0b00001100);delay(5);
    lcd(0b00000001);
} 
 
void Clear(){lcd(0b00000001);} 
 
void Curs(byte str, byte mesto){
  if(str==0){lcd(0b10000000+mesto);}
  if(str==1){lcd(0b11000000+mesto);}
  } 
 
void PrintString(const char* str) {while(*str != '\0') {delayMicroseconds(200);PrintChar(*str);str++;}}
 
void PrintChar(const char chr) {lcdSend(false, (uint8_t)chr);}
 
void e_pin(){
    I2C_write_lcd(led_b |= (1<<E));
    delayMicroseconds(200);
    I2C_write_lcd(led_b &= ~(1<<E));
}
 
void lcd(uint8_t sett) {lcdSend(true, sett);}
 
void lcdSend(bool rs, byte data) {
    if(rs==0){led_b |= (1<<RS);} else {led_b &= ~(1<<RS);}//RS
    delayMicroseconds(200);
    if(((data >> 7) & 1) ==1){I2C_write_lcd(led_b |= (1<<7));} else {I2C_write_lcd(led_b &= ~(1<<7));}
    if(((data >> 6) & 1) ==1){I2C_write_lcd(led_b |= (1<<6));} else {I2C_write_lcd(led_b &= ~(1<<6));}
    if(((data >> 5) & 1) ==1){I2C_write_lcd(led_b |= (1<<5));} else {I2C_write_lcd(led_b &= ~(1<<5));}
    if(((data >> 4) & 1) ==1){I2C_write_lcd(led_b |= (1<<4));} else {I2C_write_lcd(led_b &= ~(1<<4));}
    e_pin();
    if(((data >> 3) & 1) ==1){I2C_write_lcd(led_b |= (1<<7));} else {I2C_write_lcd(led_b &= ~(1<<7));}
    if(((data >> 2) & 1) ==1){I2C_write_lcd(led_b |= (1<<6));} else {I2C_write_lcd(led_b &= ~(1<<6));}
    if(((data >> 1) & 1) ==1){I2C_write_lcd(led_b |= (1<<5));} else {I2C_write_lcd(led_b &= ~(1<<5));}
    if(((data >> 0) & 1) ==1){I2C_write_lcd(led_b |= (1<<4));} else {I2C_write_lcd(led_b &= ~(1<<4));}
    e_pin();
}

byte I2C_read(byte reg){
  Wire.beginTransmission(ADDR);
  Wire.write(reg);
  Wire.endTransmission();
  Wire.requestFrom(ADDR,1);
  while(Wire.available()<1);
  byte value = Wire.read();
  return value;
  } 

void I2C_write_bmp(byte reg, byte data){  
  Wire.beginTransmission(ADDR);
  Wire.write(reg);
  Wire.write(data);
  Wire.endTransmission();
  }   

void I2C_write_lcd(byte data){  
  Wire.beginTransmission(ADDR_LED);
  Wire.write(data);
  Wire.endTransmission();
  }  

int dht_read(){
        byte ii = 0,i1 = 0;  
        for(ii = 0;ii < 5;ii++){data_dht[ii] = 0;}                  
        DDRC |=(1 << DHT); 
        PORTC &= ~(1 << DHT); 
        delay(18); 
        PORTC |= (1 << DHT);
        delayMicroseconds(40); 
        DDRC &= ~(1 << DHT); 
        delayMicroseconds(80); 
    while(PINC & (1 << DHT));
      for (ii = 0; ii < 5; ii++){
        data_dht[ii]=0;
      for (i1=0; i1<8; i1++){
    while(!(PINC & (1 << DHT)));  
        delayMicroseconds(30);
      if (PINC & (1 << DHT)){data_dht[ii] |= 1 << (7-i1);}
    while(PINC & (1 << DHT));  
}}return 1;}