
Simple example that reads temperature and humidity from Si7006-A20 chip over i2c.
Dependencies: Si7006A20 aconno_I2C adc52832_common mbed
main.cpp@0:c8fa7e8568c6, 2017-09-25 (annotated)
- Committer:
- jurica238814
- Date:
- Mon Sep 25 10:22:28 2017 +0000
- Revision:
- 0:c8fa7e8568c6
Temperature and humidity reading work.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jurica238814 | 0:c8fa7e8568c6 | 1 | /* |
jurica238814 | 0:c8fa7e8568c6 | 2 | * Made by Jurica @ aconno |
jurica238814 | 0:c8fa7e8568c6 | 3 | * jurica_resetar@yahoo.com |
jurica238814 | 0:c8fa7e8568c6 | 4 | * |
jurica238814 | 0:c8fa7e8568c6 | 5 | */ |
jurica238814 | 0:c8fa7e8568c6 | 6 | |
jurica238814 | 0:c8fa7e8568c6 | 7 | #include <stdio.h> |
jurica238814 | 0:c8fa7e8568c6 | 8 | #include "mbed.h" |
jurica238814 | 0:c8fa7e8568c6 | 9 | #include "Si7006A20.h" |
jurica238814 | 0:c8fa7e8568c6 | 10 | #include "nrf52_digital.h" |
jurica238814 | 0:c8fa7e8568c6 | 11 | |
jurica238814 | 0:c8fa7e8568c6 | 12 | #define DEBUG_PRINT (1) |
jurica238814 | 0:c8fa7e8568c6 | 13 | |
jurica238814 | 0:c8fa7e8568c6 | 14 | #if DEBUG_PRINT |
jurica238814 | 0:c8fa7e8568c6 | 15 | #include "nrf52_uart.h" |
jurica238814 | 0:c8fa7e8568c6 | 16 | #define TX_PIN_NUMBER p25 |
jurica238814 | 0:c8fa7e8568c6 | 17 | #define RX_PIN_NUMBER p26 |
jurica238814 | 0:c8fa7e8568c6 | 18 | NRF52_UART serial(TX_PIN_NUMBER, RX_PIN_NUMBER, Baud9600); |
jurica238814 | 0:c8fa7e8568c6 | 19 | char buffer[255]={0}; |
jurica238814 | 0:c8fa7e8568c6 | 20 | #define SEND(...) {uint8_t len = sprintf(buffer, __VA_ARGS__); serial.send(buffer, len);} |
jurica238814 | 0:c8fa7e8568c6 | 21 | #else |
jurica238814 | 0:c8fa7e8568c6 | 22 | #define SEND(...); |
jurica238814 | 0:c8fa7e8568c6 | 23 | #endif |
jurica238814 | 0:c8fa7e8568c6 | 24 | |
jurica238814 | 0:c8fa7e8568c6 | 25 | Si7006 si(p19, p20); |
jurica238814 | 0:c8fa7e8568c6 | 26 | NRF52_DigitalOut power(p2); |
jurica238814 | 0:c8fa7e8568c6 | 27 | |
jurica238814 | 0:c8fa7e8568c6 | 28 | int main(){ |
jurica238814 | 0:c8fa7e8568c6 | 29 | float temperature; |
jurica238814 | 0:c8fa7e8568c6 | 30 | float humidity; |
jurica238814 | 0:c8fa7e8568c6 | 31 | |
jurica238814 | 0:c8fa7e8568c6 | 32 | SEND("Main started.\r\n"); |
jurica238814 | 0:c8fa7e8568c6 | 33 | power = 1; |
jurica238814 | 0:c8fa7e8568c6 | 34 | SEND("Main power activated.\r\n"); |
jurica238814 | 0:c8fa7e8568c6 | 35 | |
jurica238814 | 0:c8fa7e8568c6 | 36 | while(1){ |
jurica238814 | 0:c8fa7e8568c6 | 37 | humidity = si.getHumidity(); |
jurica238814 | 0:c8fa7e8568c6 | 38 | SEND("Humidity is: %f%%\r\n", humidity); |
jurica238814 | 0:c8fa7e8568c6 | 39 | temperature = si.getTemperature(); |
jurica238814 | 0:c8fa7e8568c6 | 40 | SEND("Temperature is: %fC\r\n", temperature); |
jurica238814 | 0:c8fa7e8568c6 | 41 | wait(1); |
jurica238814 | 0:c8fa7e8568c6 | 42 | } |
jurica238814 | 0:c8fa7e8568c6 | 43 | } |