BMP180 and BLE
Dependencies: BLE_API mbed nRF51822
Fork of WeatherStation by
Revision 6:25ed8e2df02e, committed 2018-01-10
- Comitter:
- phivari
- Date:
- Wed Jan 10 16:42:44 2018 +0000
- Parent:
- 5:fe4888cc60cc
- Commit message:
- WeatherStation_BLE_BMP180
Changed in this revision
diff -r fe4888cc60cc -r 25ed8e2df02e SHT21_ncleee.lib --- a/SHT21_ncleee.lib Mon Dec 21 00:25:08 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/graeme88/code/SHT21_ncleee/#03bbabb7b0b0
diff -r fe4888cc60cc -r 25ed8e2df02e battery.h --- a/battery.h Mon Dec 21 00:25:08 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,43 +0,0 @@ - - -#ifndef __BATTERY_H__ -#define __BATTERY_H__ - -#include "mbed.h" - -class Battery { -public: - Battery(PinName pin) { - uint32_t n = (uint32_t) pin; - channel = 1 << (1 + n); - } - - float read() { - uint32_t pre_enable_register = NRF_ADC->ENABLE; - uint32_t pre_config_register = NRF_ADC->CONFIG; - - - NRF_ADC->ENABLE = ADC_ENABLE_ENABLE_Enabled; - NRF_ADC->CONFIG = (ADC_CONFIG_RES_10bit << ADC_CONFIG_RES_Pos) | - (ADC_CONFIG_INPSEL_AnalogInputNoPrescaling << ADC_CONFIG_INPSEL_Pos) | - (ADC_CONFIG_REFSEL_VBG << ADC_CONFIG_REFSEL_Pos) | - (channel << ADC_CONFIG_PSEL_Pos) | - (ADC_CONFIG_EXTREFSEL_None << ADC_CONFIG_EXTREFSEL_Pos); - - NRF_ADC->TASKS_START = 1; - while (((NRF_ADC->BUSY & ADC_BUSY_BUSY_Msk) >> ADC_BUSY_BUSY_Pos) == ADC_BUSY_BUSY_Busy) { - } - - uint16_t value = NRF_ADC->RESULT; - - NRF_ADC->ENABLE = pre_enable_register; - NRF_ADC->CONFIG = pre_config_register; - - return (float)value * (1.0f / (float)0x3FF) * 1.2 * 12.2 / 2.2; - } - -private: - uint32_t channel; -}; - -#endif // __BATTERY_H__
diff -r fe4888cc60cc -r 25ed8e2df02e main.cpp --- a/main.cpp Mon Dec 21 00:25:08 2015 +0000 +++ b/main.cpp Wed Jan 10 16:42:44 2018 +0000 @@ -1,19 +1,13 @@ -#define I2C_SDA p3 -#define I2C_SCL p4 +#define I2C_SDA p29 +#define I2C_SCL p28 #include "mbed.h" #include "BLE.h" -#include "battery.h" #include "WeatherService.h" -#include "BatteryService.h" #include "BMP180.h" -#include "SHT21_ncleee.h" - float temperature1; -float temperature2; float pressure; -float humidity; BLE ble; @@ -22,15 +16,13 @@ DigitalOut instrumentsPower(p30); BMP180 bmp180; -SHT21 sht21(&i2c); const static char DEVICE_NAME[] = "Weather Station"; static const uint16_t serviceList[] = { - GattService::UUID_ENVIRONMENTAL_SERVICE, - GattService::UUID_BATTERY_SERVICE -}; + GattService::UUID_ENVIRONMENTAL_SERVICE + }; static volatile bool triggerSensorPolling = false; @@ -69,10 +61,6 @@ pressure = (float)bmp180.BMP180GetPressure(); } -void updateFromSHT21() { - temperature2 = sht21.readTemp(); - humidity = sht21.readHumidity(); -} int main(void) { @@ -89,8 +77,6 @@ /* Setup weather service. */ WeatherService weatherService(ble); - BatteryService batteryService(ble, 0); - Battery battery(BATTERY_PIN); /* setup advertising */ ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE); @@ -109,25 +95,18 @@ instrumentsPower = 1; wait(1); updateFromBMP180(); - updateFromSHT21(); instrumentsPower = 0; - float temperature = (temperature1 + temperature2) / 2; + float temperature = (temperature1)/ 2; printf("Temp1: %.1f ºC \n", temperature1); - printf("Temp2: %.1f ºC \n", temperature2); printf("Temp Avg.: %.1f ºC \n", temperature); printf("Pressure: %.3f Pa \n", pressure); - printf("Humidity: %.1f%% \n", humidity); printf("---\n"); - - + weatherService.updateTemperature(temperature); weatherService.updatePressure(pressure); - weatherService.updateHumidity(humidity); - - - batteryService.updateBatteryLevel(battery.read()); + } else { ble.waitForEvent(); }