Lieven Hollevoet / Mbed 2 deprecated Si7005_example

Dependencies:   Si7005 mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "Si7005.h"
00003 
00004 Si7005 rh(p28, p27);          // sda, scl
00005 DigitalOut rh_cs_n(p26); // Chip select signal
00006 Serial uart(USBTX, USBRX); // tx, rx
00007 
00008 int main() {
00009     while(1) {
00010         // Enable RH sensor
00011         rh_cs_n = 0;
00012         // Let it startup!
00013         wait(0.05);
00014  
00015         char id;
00016         id = rh.readID();
00017         uart.printf("Sensor type: %02X\n", id);
00018  
00019         // Relative humidity measurement
00020         rh.startMeasurement(SI7005_RH);
00021         while (!rh.conversionDone()) {
00022             wait(0.01);
00023         }
00024         int measurement = rh.readResult(SI7005_RH);
00025         uart.printf("RH = %i procent\n", measurement);
00026  
00027         // Start temperature measurement
00028         rh.startMeasurement(SI7005_T);
00029         while (!rh.conversionDone()){
00030             wait (0.01);
00031         }
00032         measurement = rh.readResult(SI7005_T);
00033         uart.printf("Temp = %i degrees C\n", measurement);
00034  
00035         // Disable the sensor
00036         rh_cs_n = 1;
00037     }
00038 }