Bienvenido a los foros de FT81x Manía. Te invitamos a regístrate totalmente gratis. Disfruta de tu experiencia con un grandes amigos y Staff.

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5

Thread Contributor: lightcalamarCode without library for SI7021

#1
0
This code without libray for shield SI7021.

This shield is reader temperature and humidity. To be code;

#include <Wire.h>

// SI7021 I2C address is 0x40(64)
#define si7021Addr 0x40

void setup()
{
 Wire.begin();
 Serial.begin(9600);
 Wire.beginTransmission(si7021Addr);
 Wire.endTransmission();
 delay(300);
}

void loop()
{
 unsigned int data[2];

 Wire.beginTransmission(si7021Addr);
 //Send humidity measurement command
 Wire.write(0xF5);
 Wire.endTransmission();
 delay(500);

 // Request 2 bytes of data
 Wire.requestFrom(si7021Addr, 2);
 // Read 2 bytes of data to get humidity
 if(Wire.available() == 2)
 {
   data[0] = Wire.read();
   data[1] = Wire.read();
 }

 // Convert the data
 float humidity  = ((data[0] * 256.0) + data[1]);
 humidity = ((125 * humidity) / 65536.0) - 6;

 Wire.beginTransmission(si7021Addr);
 // Send temperature measurement command
 Wire.write(0xF3);
 Wire.endTransmission();
 delay(500);

 // Request 2 bytes of data
 Wire.requestFrom(si7021Addr, 2);

 // Read 2 bytes of data for temperature
 if(Wire.available() == 2)
 {
   data[0] = Wire.read();
   data[1] = Wire.read();
 }

 // Convert the data
 float temp  = ((data[0] * 256.0) + data[1]);
 float celsTemp = ((175.72 * temp) / 65536.0) - 46.85;
 float fahrTemp = celsTemp * 1.8 + 32;

 // Output data to serial monitor
 Serial.print("Humidity : ");
 Serial.print(humidity);
 Serial.println(" % RH");
 Serial.print("Celsius : ");
 Serial.print(celsTemp);
 Serial.println(" C");
//  Serial.print("Fahrenheit : ");
//  Serial.print(fahrTemp);
//  Serial.println(" F");
 delay(1000);
}

Source from; Learming ESP8266

Work fine 100%.  Angry

Attasment DataSheet. Please learming page 18 form file. Commend I2C

Code for screen FT81x with library GD2xx;

void meteo() {

 do {
 
 GD.get_inputs();  
 GD.ClearColorRGB(0x000025);
 GD.Clear();
 
 GD.Tag(1);
 GD.cmd_fgcolor(0xff0000);
//  GD.cmd_romfont(1, 32);
 GD.cmd_button(30, 35, 100, 65, 30, OPT_FLAT, "Salir"); GD.Tag(255);
    if (GD.inputs.tag == 1) { delay(175); menu(); }
   
//  char buffer[10];
//  GD.ColorRGB(CYAN);
//  sprintf(buffer,"%02d:%02d:%02d", hour, minute, second );
//  GD.cmd_text(720, 40, 30, OPT_CENTER, buffer );  
//  GD.ColorRGB(WHITE);    

//  GD.SaveContext();
//  lineas();                
//  GD.RestoreContext();

// CODIGO DEL SI7021 SIN LIBRERIA
 unsigned int data[2];

 Wire.beginTransmission(SI7021_ADDR);
 //Send humidity measurement command
 Wire.write(0xF5);
 Wire.endTransmission();
 delay(500);

 // Request 2 bytes of data
 Wire.requestFrom(SI7021_ADDR, 2);
 // Read 2 bytes of data to get humidity
 if(Wire.available() == 2) {
   data[0] = Wire.read();
   data[1] = Wire.read();
 }

 // Convert the data
 float humidity  = ((data[0] * 256.0) + data[1]);
 humidity = ((125 * humidity) / 65536.0) - 6;

 Wire.beginTransmission(SI7021_ADDR);
 // Send temperature measurement command
 Wire.write(0xF3);
 Wire.endTransmission();
 delay(500);

 // Request 2 bytes of data
 Wire.requestFrom(SI7021_ADDR, 2);

 // Read 2 bytes of data for temperature
 if(Wire.available() == 2) {
   data[0] = Wire.read();
   data[1] = Wire.read();
 }

 // Convert the data
 float temp  = ((data[0] * 256.0) + data[1]);
 float celsTemp = ((175.72 * temp) / 65536.0) - 46.85;
 float fahrTemp = celsTemp * 1.8 + 32;

 // Output data to serial monitor
 Serial.print("Humedad : ");
 Serial.print(humidity);
 Serial.println(" % RH");
 Serial.print("temperatura : ");
 Serial.print(celsTemp);
 Serial.println(" C");

 Serial.print("Fahrenheit : ");
 Serial.print(fahrTemp);
 Serial.println(" F");  

 GD.ColorRGB(0xffffff);

// Humidity  
char humedad[15];
char mi_humedad[50];
 dtostrf(humidity, 10, 2, humedad);
 sprintf (mi_humedad,"%s", humedad);

 GD.cmd_text(200, 350, 30, 0, "Humedad  = ");
 GD.cmd_text(410, 350, 30, 0, mi_humedad);
 GD.cmd_text(541, 350, 30, 0, "%");  

// Temperature C    
char grados[15];
char mis_grados[50];
 dtostrf(celsTemp, 10, 2, grados);
 sprintf (mis_grados,"%s", grados);

 GD.cmd_text(200, 415, 30, 0, "Temperatura  = ");
 GD.cmd_text(410, 415, 30, 0, mis_grados);
 GD.cmd_text(531, 415, 22, 0, "o");
 GD.cmd_text(541, 415, 30, 0, "C");  

// Temperature F
char gradosF[15];
char mis_gradosF[50];
 dtostrf(fahrTemp, 10, 2, gradosF);
 sprintf (mis_gradosF,"%s", gradosF);

 GD.cmd_text(200, 285, 30, 0, "Farenheind  = ");
 GD.cmd_text(410, 285, 30, 0, mis_gradosF);
//  GD.cmd_text(531, 415, 22, 0, "o");
 GD.cmd_text(541, 285, 30, 0, "F");  
 
 delay(1000);
// --------------------------------------------------->    
   
  GD.swap();
 } while(1);
}


Attached Files
.pdf   Si7021-A20.pdf (Size: 1.56 MB / Downloads: 0)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)