/******************************************* Sample sketch that configures an HMC5883L 3 axis magnetometer to continuous mode and reads back the three axis of data. Code compiles to a size of 1500 bytes Equivalent Wire Library code compiles to 2032 bytes *******************************************/ #include "I2C.h" #define Si7005 0x40 void setup() { I2c.begin(); } void loop() { uint16_t DATA = 1; uint16_t Temperatura = 0; uint16_t Humedad = 0; I2c.write(Si7005,0x03,0x11); //configura el dispositivo para medir temperatura delay(15); while (DATA&0x0001 == 0x0001) { I2c.read(Si7005,0x00,1); //read 1 byte DATA = I2c.receive(); } I2c.read(Si7005,0x01,2); //read 2 bytes DATA = I2c.receive()<<8; Temperatura =(DATA|I2c.receive())>>2; DATA = 1; I2c.write(Si7005,0x03,0x01); //configura el dispositivo para medir temperatura delay(15); while (DATA&0x0001 == 0x0001) { I2c.read(Si7005,0x00,1); //read 1 byte DATA = I2c.receive(); } I2c.read(Si7005,0x01,2); //read 2 bytes DATA = I2c.receive()<<8; Humedad =(DATA|I2c.receive())>>4; Serial.print("Temperatura: "); Serial.print(((float)Temperatura/32)-50); Serial.print(" C, Humedad: "); Serial.print(((float)Humedad/16)-24); Serial.println(" %"); } /* Wire library equivalent would be this //#include #define HMC5883L 0x1E int x = 0; int y = 0; int z = 0; void setup() { Wire.begin(); Wire.beginTransmission(HMC5883L); Wire.send(0x02); Wire.send(0x00); Wire.endTransmission(); } void loop() { Wire.beginTransmission(HMC5883L); Wire.send(0x03); Wire.endTransmission(); Wire.requestFrom(HMC5883L,6); x = Wire.receive() << 8; x |= Wire.receive(); y = Wire.receive() << 8; y |= Wire.receive(); z = Wire.receive() << 8; z |= Wire.receive(); } ********************************************/