Simple example that reads temperature and humidity from Si7006-A20 chip over i2c.

Dependencies:   Si7006A20 aconno_I2C adc52832_common mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /*
00002  * Made by Jurica @ aconno
00003  * jurica_resetar@yahoo.com
00004  *
00005 */
00006 
00007 #include <stdio.h>
00008 #include "mbed.h"
00009 #include "Si7006A20.h"
00010 #include "nrf52_digital.h"
00011 
00012 #define DEBUG_PRINT     (1)
00013 
00014 #if DEBUG_PRINT
00015     #include "nrf52_uart.h"
00016     #define TX_PIN_NUMBER p25
00017     #define RX_PIN_NUMBER p26
00018     NRF52_UART serial(TX_PIN_NUMBER, RX_PIN_NUMBER, Baud9600);
00019     char buffer[255]={0};
00020     #define SEND(...) {uint8_t len = sprintf(buffer, __VA_ARGS__); serial.send(buffer, len);}
00021 #else
00022     #define SEND(...);
00023 #endif
00024 
00025 Si7006 si(p19, p20);
00026 NRF52_DigitalOut power(p2);
00027 
00028 int main(){    
00029     float temperature;  
00030     float humidity;
00031     
00032     SEND("Main started.\r\n");
00033     power = 1;
00034     SEND("Main power activated.\r\n");
00035     
00036     while(1){
00037         humidity = si.getHumidity();
00038         SEND("Humidity is: %f%%\r\n", humidity);
00039         temperature = si.getTemperature();
00040         SEND("Temperature is: %fC\r\n", temperature);
00041         wait(1);
00042     }
00043 }