Implemented BTLE and normal nRF24 message with temperature and LCD display.
authorPat Thoyts <patthoyts@users.sourceforge.net>
Sat, 17 Oct 2015 20:30:39 +0000 (21:30 +0100)
committerPat Thoyts <patthoyts@users.sourceforge.net>
Sat, 17 Oct 2015 20:30:39 +0000 (21:30 +0100)
While waiting for the next DS18B20 conversion we transmit the last temp
reading over channel 85 to the IoT hub.
The LCD display shows temperature and humidity and the Bluetooth beacon
transmits the temperature.
Included the Atmel Studio project file (used with Visual Micro Arduino
support plugin).

.gitignore [new file with mode: 0644]
BLE24.cpp [new file with mode: 0644]
BLE24.h [new file with mode: 0644]
nRF24_BLE_Temperature.cppproj [new file with mode: 0644]
nRF24_BLE_Temperature.ino

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..b9e61c8
--- /dev/null
@@ -0,0 +1,4 @@
+*.atsln\r
+*.atsuo\r
+Visual Micro/\r
+Debug/\r
diff --git a/BLE24.cpp b/BLE24.cpp
new file mode 100644 (file)
index 0000000..1d824a2
--- /dev/null
+++ b/BLE24.cpp
@@ -0,0 +1,235 @@
+#include <Arduino.h>\r
+#include <SPI.h>\r
+#include "BLE24.h"\r
+\r
+static void btLeCrc(const uint8_t *data, uint8_t len, uint8_t *dst)\r
+{\r
+    uint8_t v, t, d;\r
+\r
+    while(len--)\r
+    {\r
+        d = *data++;\r
+        for(v = 0; v < 8; v++, d >>= 1)\r
+        {\r
+            t = dst[0] >> 7;\r
+\r
+            dst[0] <<= 1;\r
+            if(dst[1] & 0x80)\r
+                dst[0] |= 1;\r
+            dst[1] <<= 1;\r
+            if(dst[2] & 0x80)\r
+                dst[1] |= 1;\r
+            dst[2] <<= 1;\r
+\r
+            if (t != (d & 1))\r
+            {\r
+                dst[2] ^= 0x5B;\r
+                dst[1] ^= 0x06;\r
+            }\r
+        }\r
+    }\r
+}\r
+\r
+static uint8_t swapbits(uint8_t x)\r
+{\r
+#ifdef __BUILTIN_AVR_INSERT_BITS\r
+    return __builtin_avr_insert_bits(0x01234567, x, 0);\r
+#else\r
+    uint8_t v = 0;\r
+    if (x & 0x80) v |= 0x01;\r
+    if (x & 0x40) v |= 0x02;\r
+    if (x & 0x20) v |= 0x04;\r
+    if (x & 0x10) v |= 0x08;\r
+    if (x & 0x08) v |= 0x10;\r
+    if (x & 0x04) v |= 0x20;\r
+    if (x & 0x02) v |= 0x40;\r
+    if (x & 0x01) v |= 0x80;\r
+    return v;\r
+#endif\r
+}\r
+\r
+static void btLeWhiten(uint8_t *data, uint8_t len, uint8_t whitenCoeff)\r
+{\r
+    uint8_t  m;\r
+\r
+    while(len--)\r
+    {\r
+        for(m = 1; m; m <<= 1)\r
+        {\r
+            if (whitenCoeff & 0x80)\r
+            {\r
+                whitenCoeff ^= 0x11;\r
+                (*data) ^= m;\r
+            }\r
+            whitenCoeff <<= 1;\r
+        }\r
+        data++;\r
+    }\r
+}\r
+\r
+inline static uint8_t btLeWhitenStart(uint8_t chan)\r
+{\r
+    /* the value we actually use is what BT'd use left shifted one...makes our life easier */\r
+    return swapbits(chan) | 2;\r
+}\r
+\r
+static void btLePacketEncode(uint8_t *packet, uint8_t len, uint8_t chan)\r
+{\r
+    /* length is of packet, including crc. pre-populate crc in packet with initial crc value! */\r
+    uint8_t i, dataLen = len - 3;\r
+\r
+    btLeCrc(packet, dataLen, packet + dataLen);\r
+    for (i = 0; i < 3; i++, dataLen++)\r
+        packet[dataLen] = swapbits(packet[dataLen]);\r
+    btLeWhiten(packet, len, btLeWhitenStart(chan));\r
+    for (i = 0; i < len; i++)\r
+        packet[i] = swapbits(packet[i]);\r
+}\r
+\r
+inline static uint8_t spi_byte(uint8_t byte)\r
+{\r
+    return SPI.transfer(byte);\r
+}\r
+\r
+static void nrf_cmd(uint8_t cmd, uint8_t data)\r
+{\r
+    digitalWrite(PIN_CSN, LOW);\r
+    spi_byte(cmd);\r
+    spi_byte(data);\r
+    digitalWrite(PIN_CSN, HIGH);\r
+}\r
+\r
+static void nrf_simplebyte(uint8_t cmd)\r
+{\r
+    digitalWrite(PIN_CSN, LOW);\r
+    spi_byte(cmd);\r
+    digitalWrite(PIN_CSN, HIGH);\r
+}\r
+\r
+static void nrf_manybytes(uint8_t *data, uint8_t len)\r
+{\r
+    digitalWrite(PIN_CSN, LOW);\r
+    do {\r
+        spi_byte(*data++);\r
+    } while(--len);\r
+    digitalWrite(PIN_CSN, HIGH);\r
+}\r
+\r
+static void nrf_init()\r
+{\r
+    uint8_t buf[5];\r
+\r
+    // Now initialize nRF24L01+, setting general parameters\r
+    nrf_cmd(0x20, 0x12); //on, no crc, int on RX/TX done   : write register 0x00 (config)\r
+    nrf_cmd(0x21, 0x00); //no auto-acknowledge             : write register 0x01 (autoack)\r
+    nrf_cmd(0x22, 0x00); //no RX                           : write register 0x02 (enabled rx pipes)\r
+    nrf_cmd(0x23, 0x02); //4-byte address                  : write register 0x03 (config addr width: 0b11 == 4 byte)\r
+    nrf_cmd(0x24, 0x00); //no auto-retransmit              : write register 0x04 (auto retrans: off)\r
+    nrf_cmd(0x26, 0x06); //1MBps at 0dBm                   : write register 0x06 (rf setup 0x110 == 0dBm xmit)\r
+    nrf_cmd(0x27, 0x3E); //clear various flags             : write register 0x07\r
+    nrf_cmd(0x3C, 0x00); //no dynamic payloads             : write register 0x1c (enable dynamic payload: all disabled)\r
+    nrf_cmd(0x3D, 0x00); //no features                     : write register 0x1d (features: none)\r
+    nrf_cmd(0x31, 32);   //always RX 32 bytes              : write register 0x11 (rx max size: 32 is max)\r
+    nrf_cmd(0x22, 0x01); //RX on pipe 0                    : write register 0x02 (enable rx pipes: enable pipe 0)\r
+\r
+    // Set access addresses (TX address in nRF24L01) to BLE advertising 0x8E89BED6\r
+    // Remember that both bit and byte orders are reversed for BLE packet format\r
+    buf[0] = 0x30; //                                      : write register 0x10 (tx addr: expects <=5 bytes)\r
+    buf[1] = swapbits(0x8E);\r
+    buf[2] = swapbits(0x89);\r
+    buf[3] = swapbits(0xBE);\r
+    buf[4] = swapbits(0xD6);\r
+    nrf_manybytes(buf, 5);\r
+    // set RX address in nRF24L01, doesn't matter because RX is ignored in this case\r
+    buf[0] = 0x2A; //                                      : write register 0x0A (rx addr)\r
+    nrf_manybytes(buf, 5);\r
+}\r
+\r
+void CBTLE::begin(int pinCSN, int pinCE)\r
+{\r
+    SPI.begin();\r
+    SPI.setBitOrder(MSBFIRST);\r
+\r
+    pinMode(pinCSN, OUTPUT);\r
+    pinMode(pinCE, OUTPUT);\r
+    digitalWrite(pinCSN, HIGH);\r
+    digitalWrite(pinCE, LOW);\r
+\r
+    nrf_init();\r
+}\r
+\r
+// Converts a temperature value in 100ths degrees C into a nRF float (4 bytes)\r
+btle_float_t CBTLE::nrf_float(float t)\r
+{\r
+    const int32_t exponent = -2;\r
+    return static_cast<btle_float_t>(((exponent & 0xff) << 24) | (((int32_t)(t * 100)) & 0x00ffffff));\r
+}\r
+\r
+unsigned int CBTLE::mkpacket(uint8_t *buf, unsigned int size, float val)\r
+{\r
+    unsigned int ndx = 0;\r
+    btle_float_t t;\r
+    \r
+    buf[ndx++] = 0x42; // PDU type, given address is random; 0x42 for Android and 0x40 for iPhone\r
+    buf[ndx++] = 24;   // length of payload\r
+\r
+    buf[ndx++] = MY_MAC_0;\r
+    buf[ndx++] = MY_MAC_1;\r
+    buf[ndx++] = MY_MAC_2;\r
+    buf[ndx++] = MY_MAC_3;\r
+    buf[ndx++] = MY_MAC_4;\r
+    buf[ndx++] = MY_MAC_5;\r
+\r
+    /* device descriptor chunk */\r
+    buf[ndx++] = 2;     /* chunk size 2 bytes */\r
+    buf[ndx++] = 0x01;  /* chunk type: device flags */\r
+    buf[ndx++] = 0x05;  /* data: 0x05 == LE only, limited discovery mode */\r
+\r
+    /* name chunk */\r
+    buf[ndx++] = 6;     /* chunk size: 7 bytes */\r
+    buf[ndx++] = 0x09;  /* chunk type: complete name */\r
+    buf[ndx++] = 'n';\r
+    buf[ndx++] = 'R';\r
+    buf[ndx++] = 'F';\r
+    buf[ndx++] = '2';\r
+    buf[ndx++] = '4';\r
+\r
+    buf[ndx++] = 7;\r
+    buf[ndx++] = 0x16;\r
+    buf[ndx++] = (uint8_t)(NRF_TEMPERATURE_SERVICE_UUID);\r
+    buf[ndx++] = (uint8_t)((NRF_TEMPERATURE_SERVICE_UUID >> 8) & 0xff);\r
+    t = nrf_float(val);\r
+    memcpy(&buf[ndx], &t, 4);\r
+    ndx += 4;\r
+\r
+    buf[ndx++] = 0x55; //CRC start value: 0x555555\r
+    buf[ndx++] = 0x55;\r
+    buf[ndx++] = 0x55;\r
+    return ndx;\r
+}\r
+\r
+void CBTLE::announce(unsigned int channel_index, uint8_t *data, unsigned int len)\r
+{\r
+    static const uint8_t chRf[BTLE_NUM_CHANNELS] = {2, 26,80};
+    static const uint8_t chLe[BTLE_NUM_CHANNELS] = {37,38,39};\r
+    unsigned int n;\r
+\r
+    nrf_cmd(0x25, chRf[channel_index]);\r
+    nrf_cmd(0x27, 0x6E); // Clear flags\r
+\r
+    btLePacketEncode(data, len, chLe[channel_index]);\r
+\r
+    nrf_simplebyte(0xE2); //Clear RX Fifo\r
+    nrf_simplebyte(0xE1); //Clear TX Fifo\r
+\r
+    digitalWrite(PIN_CSN, LOW);\r
+    spi_byte(0xA0);\r
+    for (n = 0 ; n < len ; n++)\r
+        spi_byte(data[n]);\r
+    digitalWrite(PIN_CSN, HIGH);\r
+\r
+    nrf_cmd(0x20, 0x12);        // TX on\r
+    digitalWrite(PIN_CE, HIGH); // Enable Chip\r
+    delay(2);\r
+    digitalWrite(PIN_CE, LOW);  // (in preparation of switching to RX quickly)\r
+}\r
diff --git a/BLE24.h b/BLE24.h
new file mode 100644 (file)
index 0000000..c6dcd26
--- /dev/null
+++ b/BLE24.h
@@ -0,0 +1,36 @@
+#ifndef _BTLE23_h_INCLUDE\r
+#define _BTLE23_h_INCLUDE\r
+\r
+#include <Arduino.h>\r
+#include <stdint.h>\r
+\r
+#define PIN_CE  8 // chip enable
+#define PIN_CSN 10  // chip select (for SPI)
+\r
+// Service UUIDs used on the nRF8001 and nRF51822 platforms
+#define NRF_TEMPERATURE_SERVICE_UUID        0x1809
+#define NRF_BATTERY_SERVICE_UUID            0x180F
+#define NRF_DEVICE_INFORMATION_SERVICE_UUID 0x180A\r
+\r
+#define MY_MAC_0 0x01
+#define MY_MAC_1 0x02
+#define MY_MAC_2 0xef
+#define MY_MAC_3 0xbe
+#define MY_MAC_4 0xad
+#define MY_MAC_5 0xde
+\r
+#define BTLE_BUFFER_SIZE 32\r
+#define BTLE_NUM_CHANNELS 3\r
+typedef int32_t btle_float_t;\r
+\r
+class CBTLE\r
+{\r
+public:\r
+    void begin(int pinCE, int pinCSN);\r
+    void end() {}\r
+    btle_float_t nrf_float(float val);\r
+    unsigned int mkpacket(uint8_t *buf, unsigned int size, float val);\r
+    void announce(unsigned int channel_index, uint8_t *data, unsigned int len);\r
+};\r
+\r
+#endif\r
diff --git a/nRF24_BLE_Temperature.cppproj b/nRF24_BLE_Temperature.cppproj
new file mode 100644 (file)
index 0000000..e8117d0
--- /dev/null
@@ -0,0 +1,656 @@
+<?xml version="1.0" encoding="utf-8"?>\r
+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">\r
+  <PropertyGroup>\r
+    <SchemaVersion>2.0</SchemaVersion>\r
+    <ProjectVersion>6.2</ProjectVersion>\r
+    <ToolchainName>com.Atmel.AVRGCC8.CPP</ToolchainName>\r
+    <ProjectGuid>{f0db6327-9b78-4838-8341-d7f74af011b7}</ProjectGuid>\r
+    <avrdevice>atmega328p</avrdevice>\r
+    <avrdeviceseries>none</avrdeviceseries>\r
+    <OutputType>Executable</OutputType>\r
+    <Language>CPP</Language>\r
+    <OutputFileName>$(MSBuildProjectName)</OutputFileName>\r
+    <OutputFileExtension>.elf</OutputFileExtension>\r
+    <OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory>\r
+    <AssemblyName>nRF24_BLE_Temperature</AssemblyName>\r
+    <Name>nRF24_BLE_Temperature</Name>\r
+    <RootNamespace>nRF24_BLE_Temperature</RootNamespace>\r
+    <ToolchainFlavour>Native</ToolchainFlavour>\r
+    <KeepTimersRunning>true</KeepTimersRunning>\r
+    <OverrideVtor>false</OverrideVtor>\r
+    <OverrideVtorValue>exception_table</OverrideVtorValue>\r
+    <eraseonlaunchrule>0</eraseonlaunchrule>\r
+    <ProgFlashFromRam>true</ProgFlashFromRam>\r
+    <RamSnippetAddress>0x20000000</RamSnippetAddress>\r
+    <CacheFlash>true</CacheFlash>\r
+    <UncachedRange />\r
+    <BootSegment>0</BootSegment>\r
+    <AsfFrameworkConfig>\r
+      <framework-data xmlns="">\r
+        <options />\r
+        <configurations />\r
+        <files />\r
+        <documentation help="" />\r
+        <dependencies>\r
+          <content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.21.0" />\r
+        </dependencies>\r
+      </framework-data>\r
+    </AsfFrameworkConfig>\r
+    <preserveEEPROM>true</preserveEEPROM>\r
+    <avrtool>com.atmel.avrdbg.tool.atmelice</avrtool>\r
+    <com_atmel_avrdbg_tool_atmelice>\r
+      <ToolOptions>\r
+        <InterfaceProperties>\r
+          <IspClock>2000000</IspClock>\r
+        </InterfaceProperties>\r
+        <InterfaceName>ISP</InterfaceName>\r
+      </ToolOptions>\r
+      <ToolType>com.atmel.avrdbg.tool.atmelice</ToolType>\r
+      <ToolNumber>J41800030372</ToolNumber>\r
+      <ToolName>Atmel-ICE</ToolName>\r
+    </com_atmel_avrdbg_tool_atmelice>\r
+    <avrtoolinterface>ISP</avrtoolinterface>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">\r
+    <ToolchainSettings>\r
+      <AvrGccCpp>\r
+  <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>\r
+  <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>\r
+  <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>\r
+  <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>\r
+  <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>\r
+  <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>\r
+  <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>\r
+  <avrgcc.compiler.symbols.DefSymbols>\r
+    <ListValues>\r
+      <Value>__AVR_ATmega328p__</Value>\r
+      <Value>__AVR_ATmega328P__</Value>\r
+      <Value>ARDUINO=165</Value>\r
+      <Value>ARDUINO_MAIN</Value>\r
+      <Value>F_CPU=20000000L</Value>\r
+      <Value>__AVR__</Value>\r
+      <Value>ARDUINO_BARE</Value>\r
+      <Value>ARDUINO_ARCH_AVR</Value>\r
+    </ListValues>\r
+  </avrgcc.compiler.symbols.DefSymbols>\r
+  <avrgcc.compiler.directories.IncludePaths>\r
+    <ListValues>\r
+      <Value>C:/opt/arduino-1.6.5-r2/hardware/tools/avr/lib/gcc/avr/4.8.1/include</Value>\r
+      <Value>C:/opt/arduino-1.6.5-r2/hardware/tools/avr//avr/include/avr/</Value>\r
+      <Value>C:/opt/arduino-1.6.5-r2/hardware/tools/avr/avr/include/</Value>\r
+      <Value>c:/Code/arduino/libraries</Value>\r
+      <Value>C:/Program Files (x86)/Visual Micro/Visual Micro for Arduino/Micro Platforms/default/debuggers</Value>\r
+      <Value>c:/Code/arduino/hardware/Custom/avr/libraries</Value>\r
+      <Value>C:/Users/pt111992/AppData/Roaming/arduino15/packages/arduino/hardware/avr/1.6.8/libraries</Value>\r
+      <Value>C:/opt/arduino-1.6.5-r2/libraries</Value>\r
+      <Value>C:/Users/pt111992/AppData/Roaming/arduino15/packages/arduino/hardware/avr/1.6.8/libraries/SPI/utility</Value>\r
+      <Value>C:/Users/pt111992/AppData/Roaming/arduino15/packages/arduino/hardware/avr/1.6.8/libraries/SPI</Value>\r
+      <Value>c:/Code/arduino/libraries/OneWire/utility</Value>\r
+      <Value>c:/Code/arduino/libraries/OneWire</Value>\r
+      <Value>c:/Code/arduino/libraries/LiquidCrystal/utility</Value>\r
+      <Value>c:/Code/arduino/libraries/LiquidCrystal</Value>\r
+      <Value>c:/Code/arduino/libraries/DallasTemperature/utility</Value>\r
+      <Value>c:/Code/arduino/libraries/DallasTemperature</Value>\r
+      <Value>../../nRF24_BLE_Temperature</Value>\r
+      <Value>C:/opt/arduino-1.6.5-r2/hardware/arduino/avr/variants/eightanaloginputs</Value>\r
+      <Value>C:/opt/arduino-1.6.5-r2/hardware/arduino/avr/cores/arduino</Value>\r
+    </ListValues>\r
+  </avrgcc.compiler.directories.IncludePaths>\r
+  <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>\r
+  <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>\r
+  <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>\r
+  <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>\r
+  <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>\r
+  <avrgcccpp.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcccpp.compiler.general.ChangeDefaultCharTypeUnsigned>\r
+  <avrgcccpp.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcccpp.compiler.general.ChangeDefaultBitFieldUnsigned>\r
+  <avrgcccpp.compiler.symbols.DefSymbols>\r
+    <ListValues>\r
+      <Value>__AVR_ATmega328p__</Value>\r
+      <Value>__AVR_ATmega328P__</Value>\r
+      <Value>ARDUINO=165</Value>\r
+      <Value>ARDUINO_MAIN</Value>\r
+      <Value>F_CPU=20000000L</Value>\r
+      <Value>__AVR__</Value>\r
+      <Value>ARDUINO_BARE</Value>\r
+      <Value>ARDUINO_ARCH_AVR</Value>\r
+    </ListValues>\r
+  </avrgcccpp.compiler.symbols.DefSymbols>\r
+  <avrgcccpp.compiler.directories.IncludePaths>\r
+    <ListValues>\r
+      <Value>C:/opt/arduino-1.6.5-r2/hardware/tools/avr/lib/gcc/avr/4.8.1/include</Value>\r
+      <Value>C:/opt/arduino-1.6.5-r2/hardware/tools/avr//avr/include/avr/</Value>\r
+      <Value>C:/opt/arduino-1.6.5-r2/hardware/tools/avr/avr/include/</Value>\r
+      <Value>c:/Code/arduino/libraries</Value>\r
+      <Value>C:/Program Files (x86)/Visual Micro/Visual Micro for Arduino/Micro Platforms/default/debuggers</Value>\r
+      <Value>c:/Code/arduino/hardware/Custom/avr/libraries</Value>\r
+      <Value>C:/Users/pt111992/AppData/Roaming/arduino15/packages/arduino/hardware/avr/1.6.8/libraries</Value>\r
+      <Value>C:/opt/arduino-1.6.5-r2/libraries</Value>\r
+      <Value>C:/Users/pt111992/AppData/Roaming/arduino15/packages/arduino/hardware/avr/1.6.8/libraries/SPI/utility</Value>\r
+      <Value>C:/Users/pt111992/AppData/Roaming/arduino15/packages/arduino/hardware/avr/1.6.8/libraries/SPI</Value>\r
+      <Value>c:/Code/arduino/libraries/OneWire/utility</Value>\r
+      <Value>c:/Code/arduino/libraries/OneWire</Value>\r
+      <Value>c:/Code/arduino/libraries/LiquidCrystal/utility</Value>\r
+      <Value>c:/Code/arduino/libraries/LiquidCrystal</Value>\r
+      <Value>c:/Code/arduino/libraries/DallasTemperature/utility</Value>\r
+      <Value>c:/Code/arduino/libraries/DallasTemperature</Value>\r
+      <Value>../../nRF24_BLE_Temperature</Value>\r
+      <Value>C:/opt/arduino-1.6.5-r2/hardware/arduino/avr/variants/eightanaloginputs</Value>\r
+      <Value>C:/opt/arduino-1.6.5-r2/hardware/arduino/avr/cores/arduino</Value>\r
+    </ListValues>\r
+  </avrgcccpp.compiler.directories.IncludePaths>\r
+  <avrgcccpp.compiler.optimization.level>Optimize (-O1)</avrgcccpp.compiler.optimization.level>\r
+  <avrgcccpp.compiler.optimization.PackStructureMembers>True</avrgcccpp.compiler.optimization.PackStructureMembers>\r
+  <avrgcccpp.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcccpp.compiler.optimization.AllocateBytesNeededForEnum>\r
+  <avrgcccpp.compiler.optimization.DebugLevel>Default (-g2)</avrgcccpp.compiler.optimization.DebugLevel>\r
+  <avrgcccpp.compiler.warnings.AllWarnings>True</avrgcccpp.compiler.warnings.AllWarnings>\r
+  <avrgcccpp.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcccpp.assembler.debugging.DebugLevel>\r
+</AvrGccCpp>\r
+    </ToolchainSettings>\r
+    <VMSETTING_IncludePaths>C:/Users/pt111992/AppData/Roaming/arduino15/packages/arduino/hardware/avr/1.6.8/cores/arduino;C:/Users/pt111992/AppData/Roaming/arduino15/packages/arduino/hardware/avr/1.6.8/variants/standard;../../nRF24_BLE_Temperature;c:/Code/arduino/libraries/DallasTemperature;c:/Code/arduino/libraries/DallasTemperature/utility;c:/Code/arduino/libraries/OneWire;c:/Code/arduino/libraries/OneWire/utility;C:/Users/pt111992/AppData/Roaming/arduino15/packages/arduino/hardware/avr/1.6.8/libraries/SPI;C:/Users/pt111992/AppData/Roaming/arduino15/packages/arduino/hardware/avr/1.6.8/libraries/SPI/utility;C:/opt/arduino-1.6.5-r2/libraries;C:/Users/pt111992/AppData/Roaming/arduino15/packages/arduino/hardware/avr/1.6.8/libraries;C:/Program Files (x86)/Visual Micro/Visual Micro for Arduino/Micro Platforms/default/debuggers;c:/Code/arduino/libraries;C:/opt/arduino-1.6.5-r2/hardware/tools/avr/avr/include/;C:/opt/arduino-1.6.5-r2/hardware/tools/avr//avr/include/avr/;C:/opt/arduino-1.6.5-r2/hardware/tools/avr/lib/gcc/avr/4.8.1/include;C:/opt/arduino-1.6.5-r2/hardware/arduino/avr/cores/arduino;C:/opt/arduino-1.6.5-r2/hardware/arduino/avr/variants/eightanaloginputs;c:/Code/arduino/hardware/Custom/avr/libraries;c:/Code/arduino/libraries/LiquidCrystal;c:/Code/arduino/libraries/LiquidCrystal/utility;</VMSETTING_IncludePaths>\r
+    <VisualMicroSettings>\r
+      <VisualMicroSettings>\r
+        <arduino.board.name>bare_20MHzatmega328</arduino.board.name>\r
+        <arduino.board.desc>Bare Arduino-style boards w/ ATmega328 (5V, 20 MHz)</arduino.board.desc>\r
+        <arduino.board.property_bag>name=Bare Arduino-style boards w/ ATmega328 (5V, 20 MHz)\r
+upload.tool=avrdude\r
+upload.protocol=arduino\r
+bootloader.tool=arduino:avrdude\r
+bootloader.unlock_bits=0x3F\r
+bootloader.lock_bits=0x0F\r
+build.board=BARE\r
+build.core=arduino:arduino\r
+build.variant=arduino:eightanaloginputs\r
+menu.cpu.16MHzatmega328=ATmega328 (5V, 16 MHz)\r
+menu.cpu.16MHzatmega328.upload.maximum_size=30720\r
+menu.cpu.16MHzatmega328.upload.maximum_data_size=2048\r
+menu.cpu.16MHzatmega328.upload.speed=57600\r
+menu.cpu.16MHzatmega328.bootloader.low_fuses=0xFF\r
+menu.cpu.16MHzatmega328.bootloader.high_fuses=0xDA\r
+menu.cpu.16MHzatmega328.bootloader.extended_fuses=0x05\r
+menu.cpu.16MHzatmega328.bootloader.file=atmega/ATmegaBOOT_168_atmega328.hex\r
+menu.cpu.16MHzatmega328.build.mcu=atmega328p\r
+menu.cpu.16MHzatmega328.build.f_cpu=16000000L\r
+menu.cpu.20MHzatmega328=ATmega328 (5V, 20 MHz)\r
+menu.cpu.20MHzatmega328.upload.maximum_size=30720\r
+menu.cpu.20MHzatmega328.upload.maximum_data_size=2048\r
+menu.cpu.20MHzatmega328.upload.speed=57600\r
+menu.cpu.20MHzatmega328.bootloader.low_fuses=0xF7\r
+menu.cpu.20MHzatmega328.bootloader.high_fuses=0xDA\r
+menu.cpu.20MHzatmega328.bootloader.extended_fuses=0x05\r
+menu.cpu.20MHzatmega328.bootloader.file=atmega/ATmegaBOOT_168_atmega328.hex\r
+menu.cpu.20MHzatmega328.build.mcu=atmega328p\r
+menu.cpu.20MHzatmega328.build.f_cpu=20000000L\r
+menu.cpu.8MHzatmega328=ATmega328 (3.3V, 8 MHz)\r
+menu.cpu.8MHzatmega328.upload.maximum_size=30720\r
+menu.cpu.8MHzatmega328.upload.maximum_data_size=2048\r
+menu.cpu.8MHzatmega328.upload.speed=57600\r
+menu.cpu.8MHzatmega328.bootloader.low_fuses=0xFF\r
+menu.cpu.8MHzatmega328.bootloader.high_fuses=0xDA\r
+menu.cpu.8MHzatmega328.bootloader.extended_fuses=0x05\r
+menu.cpu.8MHzatmega328.bootloader.file=atmega/ATmegaBOOT_168_atmega328_pro_8MHz.hex\r
+menu.cpu.8MHzatmega328.build.mcu=atmega328p\r
+menu.cpu.8MHzatmega328.build.f_cpu=8000000L\r
+runtime.ide.path=C:\opt\arduino-1.6.5-r2\r
+build.system.path=c:\Code\arduino\hardware\Custom\avr\system\r
+runtime.ide.version=165\r
+target_package=Custom\r
+target_platform=avr\r
+runtime.hardware.path=c:\Code\arduino\hardware\Custom\r
+originalid=bare\r
+intellisense.tools.path={runtime.tools.avr-gcc.path}/\r
+intellisense.include.paths={intellisense.tools.path}avr/include/;{intellisense.tools.path}/avr/include/avr/;{intellisense.tools.path}lib\gcc\avr\4.8.1\include\r
+tools.atprogram.cmd.path=%AVRSTUDIO_EXE_PATH%\atbackend\atprogram\r
+tools.atprogram.cmd.setwinpath=true\r
+tools.atprogram.program.params.verbose=-v\r
+tools.atprogram.program.params.quiet=-q\r
+tools.atprogram.program.pattern="{cmd.path}" -d {build.mcu} {program.verbose} {program.extra_params} program -c -f "{build.path}\{build.project_name}.hex"\r
+tools.atprogram.program.xpattern="{cmd.path}" {AVRSTUDIO_BACKEND_CONNECTION} -d {build.mcu} {program.verbose} {program.extra_params} program -c -f "{build.path}\{build.project_name}.hex"\r
+version=1.0.0\r
+compiler.warning_flags=-w\r
+compiler.warning_flags.none=-w\r
+compiler.warning_flags.default=\r
+compiler.warning_flags.more=-Wall\r
+compiler.warning_flags.all=-Wall -Wextra\r
+compiler.path={runtime.tools.avr-gcc.path}/bin/\r
+compiler.c.cmd=avr-gcc\r
+compiler.c.flags=-c -g -Os {compiler.warning_flags} -ffunction-sections -fdata-sections -MMD\r
+compiler.c.elf.flags={compiler.warning_flags} -Os -Wl,--gc-sections\r
+compiler.c.elf.cmd=avr-gcc\r
+compiler.S.flags=-c -g -x assembler-with-cpp\r
+compiler.cpp.cmd=avr-g++\r
+compiler.cpp.flags=-c -g -Os {compiler.warning_flags} -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD\r
+compiler.ar.cmd=avr-ar\r
+compiler.ar.flags=rcs\r
+compiler.objcopy.cmd=avr-objcopy\r
+compiler.objcopy.eep.flags=-O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0\r
+compiler.elf2hex.flags=-O ihex -R .eeprom\r
+compiler.elf2hex.cmd=avr-objcopy\r
+compiler.ldflags=\r
+compiler.size.cmd=avr-size\r
+build.extra_flags=\r
+compiler.c.extra_flags=\r
+compiler.c.elf.extra_flags=\r
+compiler.S.extra_flags=\r
+compiler.cpp.extra_flags=\r
+compiler.ar.extra_flags=\r
+compiler.objcopy.eep.extra_flags=\r
+compiler.elf2hex.extra_flags=\r
+recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.c.flags} -mmcu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.c.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"\r
+recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} -mmcu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"\r
+recipe.S.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.S.flags} -mmcu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.S.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"\r
+recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{build.path}/{archive_file}" "{object_file}"\r
+recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.flags} -mmcu={build.mcu} {compiler.c.elf.extra_flags} -o "{build.path}/{build.project_name}.elf" {object_files} "{build.path}/{archive_file}" "-L{build.path}" -lm\r
+recipe.objcopy.eep.pattern="{compiler.path}{compiler.objcopy.cmd}" {compiler.objcopy.eep.flags} {compiler.objcopy.eep.extra_flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.eep"\r
+recipe.objcopy.hex.pattern="{compiler.path}{compiler.elf2hex.cmd}" {compiler.elf2hex.flags} {compiler.elf2hex.extra_flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.hex"\r
+recipe.output.tmp_file={build.project_name}.hex\r
+recipe.output.save_file={build.project_name}.{build.variant}.hex\r
+recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/{build.project_name}.elf"\r
+recipe.size.regex=^(?:\.text|\.data|\.bootloader)\s+([0-9]+).*\r
+recipe.size.regex.data=^(?:\.data|\.bss|\.noinit)\s+([0-9]+).*\r
+recipe.size.regex.eeprom=^(?:\.eeprom)\s+([0-9]+).*\r
+tools.avrdude.path={runtime.tools.avrdude.path}\r
+tools.avrdude.cmd.path={path}/bin/avrdude\r
+tools.avrdude.config.path={path}/etc/avrdude.conf\r
+tools.avrdude.upload.params.verbose=-v\r
+tools.avrdude.upload.params.quiet=-q -q\r
+tools.avrdude.upload.pattern="{cmd.path}" "-C{config.path}" {upload.verbose} -p{build.mcu} -c{upload.protocol} -P{serial.port} -b{upload.speed} -D "-Uflash:w:{build.path}/{build.project_name}.hex:i"\r
+tools.avrdude.program.params.verbose=-v\r
+tools.avrdude.program.params.quiet=-q -q\r
+tools.avrdude.program.pattern="{cmd.path}" "-C{config.path}" {program.verbose} -p{build.mcu} -c{protocol} {program.extra_params} "-Uflash:w:{build.path}/{build.project_name}.hex:i"\r
+tools.avrdude.erase.params.verbose=-v\r
+tools.avrdude.erase.params.quiet=-q -q\r
+tools.avrdude.erase.pattern="{cmd.path}" "-C{config.path}" {erase.verbose} -p{build.mcu} -c{protocol} {program.extra_params} -e -Ulock:w:{bootloader.unlock_bits}:m -Uefuse:w:{bootloader.extended_fuses}:m -Uhfuse:w:{bootloader.high_fuses}:m -Ulfuse:w:{bootloader.low_fuses}:m\r
+tools.avrdude.bootloader.params.verbose=-v\r
+tools.avrdude.bootloader.params.quiet=-q -q\r
+tools.avrdude.bootloader.pattern="{cmd.path}" "-C{config.path}" {bootloader.verbose} -p{build.mcu} -c{protocol} {program.extra_params} "-Uflash:w:{runtime.platform.path}/bootloaders/{bootloader.file}:i" -Ulock:w:{bootloader.lock_bits}:m\r
+build.usb_manufacturer="Unknown"\r
+build.usb_flags=-DUSB_VID={build.vid} -DUSB_PID={build.pid} '-DUSB_MANUFACTURER={build.usb_manufacturer}' '-DUSB_PRODUCT={build.usb_product}'\r
+vm.platform.root.path=C:\Program Files (x86)\Visual Micro\Visual Micro for Arduino\Micro Platforms\arduino16x\r
+runtime.tools.arm-none-eabi-gcc.path=C:\Users\pt111992\AppData\Roaming\arduino15\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1\r
+runtime.tools.arm-none-eabi-gcc-4.8.3-2014q1.path=C:\Users\pt111992\AppData\Roaming\arduino15\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1\r
+runtime.tools.avrdude.path=C:\opt\arduino-1.6.5-r2\hardware\tools\avr\r
+runtime.tools.avrdude-6.0.1-arduino5.path=C:\opt\arduino-1.6.5-r2\hardware\tools\avr\r
+runtime.tools.avr-gcc.path=C:\opt\arduino-1.6.5-r2\hardware\tools\avr\r
+runtime.tools.avr-gcc-4.8.1-arduino5.path=C:\opt\arduino-1.6.5-r2\hardware\tools\avr\r
+runtime.tools.bossac.path=C:\Users\pt111992\AppData\Roaming\arduino15\packages\arduino\tools\bossac\1.6-arduino\r
+runtime.tools.bossac-1.6-arduino.path=C:\Users\pt111992\AppData\Roaming\arduino15\packages\arduino\tools\bossac\1.6-arduino\r
+runtime.tools.CMSIS.path=C:\Users\pt111992\AppData\Roaming\arduino15\packages\arduino\tools\CMSIS\4.0.0-atmel\r
+runtime.tools.CMSIS-4.0.0-atmel.path=C:\Users\pt111992\AppData\Roaming\arduino15\packages\arduino\tools\CMSIS\4.0.0-atmel\r
+runtime.tools.openocd.path=C:\Users\pt111992\AppData\Roaming\arduino15\packages\arduino\tools\openocd\0.9.0-arduino\r
+runtime.tools.openocd-0.9.0-arduino.path=C:\Users\pt111992\AppData\Roaming\arduino15\packages\arduino\tools\openocd\0.9.0-arduino\r
+upload.maximum_size=30720\r
+upload.maximum_data_size=2048\r
+upload.speed=57600\r
+bootloader.low_fuses=0xF7\r
+bootloader.high_fuses=0xDA\r
+bootloader.extended_fuses=0x05\r
+bootloader.file=atmega/ATmegaBOOT_168_atmega328.hex\r
+build.mcu=atmega328p\r
+build.f_cpu=20000000L\r
+ide.hint=Arduino 1.6.x ide with support for downloaded Board Manager custom tools and hardware\r
+ide.location.key=Arduino16x\r
+ide.location.ide.winreg=Arduino 1.6.x Application\r
+ide.location.sketchbook.winreg=Arduino 1.6.x Sketchbook\r
+ide.location.sketchbook.preferences=sketchbook.path\r
+ide.default.version=160\r
+ide.default.package=arduino\r
+ide.default.platform=avr\r
+ide.multiplatform=true\r
+ide.includes=arduino.h\r
+ide.exe_name=arduino\r
+ide.platformswithoutpackage=false\r
+ide.includes.fallback=wprogram.h\r
+ide.extension=ino\r
+ide.extension.fallback=pde\r
+ide.versionGTEQ=160\r
+ide.exe=arduino.exe\r
+ide.hosts=atmel\r
+ide.url=http://arduino.cc/en/Main/Software\r
+ide.help.reference.path=reference\arduino.cc\en\Reference\r
+vm.debug=true\r
+software=ARDUINO\r
+ssh.user.name=root\r
+ssh.user.default.password=arduino\r
+ssh.host.wwwfiles.path=/www/sd\r
+build.working_directory={runtime.ide.path}\r
+ide.location.preferences.portable={runtime.ide.path}\portable\r
+ide.location.preferences=%VM_APPDATA_ROAMING%\arduino15\preferences.txt\r
+ide.location.preferences_fallback=%VM_APPDATA_LOCAL%\arduino15\preferences.txt\r
+ide.location.contributions=%VM_APPDATA_LOCAL%\arduino15\r
+ide.location.contributions_fallback=%VM_APPDATA_ROAMING%\arduino15\r
+ide.contributions.boards.allow=true\r
+ide.contributions.boards.ignore_unless_rewrite_found=true\r
+ide.contributions.libraries.allow=true\r
+ide.contributions.boards.support.urls.wiki=https://github.com/arduino/Arduino/wiki/Unofficial-list-of-3rd-party-boards-support-urls\r
+ide.appid=arduino16x\r
+location.sketchbook=c:\Code\arduino\r
+vm.core.include=arduino.h\r
+vm.boardsource.path=c:\Code\arduino\hardware\Custom\avr\r
+runtime.platform.path=c:\Code\arduino\hardware\Custom\avr\r
+vm.platformname.name=avr\r
+build.arch=AVR\r
+</arduino.board.property_bag>\r
+        <arduino.build.mcu>atmega328p</arduino.build.mcu>\r
+        <arduino.build.f_cpu>20000000L</arduino.build.f_cpu>\r
+        <arduino.build.core>arduino</arduino.build.core>\r
+        <arduino.upload.protocol>arduino</arduino.upload.protocol>\r
+        <arduino.upload.speed>57600</arduino.upload.speed>\r
+        <arduino.upload.maximum_size>30720</arduino.upload.maximum_size>\r
+        <visualmicro.application.name>arduino16x</visualmicro.application.name>\r
+        <visualmicro.package.name>Custom</visualmicro.package.name>\r
+        <visualmicro.platform.name>avr</visualmicro.platform.name>\r
+      </VisualMicroSettings>\r
+    </VisualMicroSettings>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">\r
+    <ToolchainSettings>\r
+      <AvrGccCpp>\r
+  <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>\r
+  <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>\r
+  <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>\r
+  <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>\r
+  <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>\r
+  <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>\r
+  <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>\r
+  <avrgcc.compiler.symbols.DefSymbols>\r
+    <ListValues>\r
+      <Value>__AVR_ATmega328p__</Value>\r
+      <Value>__AVR_ATmega328P__</Value>\r
+      <Value>ARDUINO=165</Value>\r
+      <Value>ARDUINO_MAIN</Value>\r
+      <Value>F_CPU=20000000L</Value>\r
+      <Value>__AVR__</Value>\r
+      <Value>ARDUINO_BARE</Value>\r
+      <Value>ARDUINO_ARCH_AVR</Value>\r
+    </ListValues>\r
+  </avrgcc.compiler.symbols.DefSymbols>\r
+  <avrgcc.compiler.directories.IncludePaths>\r
+    <ListValues>\r
+      <Value>C:/opt/arduino-1.6.5-r2/hardware/tools/avr/lib/gcc/avr/4.8.1/include</Value>\r
+      <Value>C:/opt/arduino-1.6.5-r2/hardware/tools/avr//avr/include/avr/</Value>\r
+      <Value>C:/opt/arduino-1.6.5-r2/hardware/tools/avr/avr/include/</Value>\r
+      <Value>c:/Code/arduino/libraries</Value>\r
+      <Value>C:/Program Files (x86)/Visual Micro/Visual Micro for Arduino/Micro Platforms/default/debuggers</Value>\r
+      <Value>c:/Code/arduino/hardware/Custom/avr/libraries</Value>\r
+      <Value>C:/Users/pt111992/AppData/Roaming/arduino15/packages/arduino/hardware/avr/1.6.8/libraries</Value>\r
+      <Value>C:/opt/arduino-1.6.5-r2/libraries</Value>\r
+      <Value>C:/Users/pt111992/AppData/Roaming/arduino15/packages/arduino/hardware/avr/1.6.8/libraries/SPI/utility</Value>\r
+      <Value>C:/Users/pt111992/AppData/Roaming/arduino15/packages/arduino/hardware/avr/1.6.8/libraries/SPI</Value>\r
+      <Value>c:/Code/arduino/libraries/OneWire/utility</Value>\r
+      <Value>c:/Code/arduino/libraries/OneWire</Value>\r
+      <Value>c:/Code/arduino/libraries/LiquidCrystal/utility</Value>\r
+      <Value>c:/Code/arduino/libraries/LiquidCrystal</Value>\r
+      <Value>c:/Code/arduino/libraries/DallasTemperature/utility</Value>\r
+      <Value>c:/Code/arduino/libraries/DallasTemperature</Value>\r
+      <Value>../../nRF24_BLE_Temperature</Value>\r
+      <Value>C:/opt/arduino-1.6.5-r2/hardware/arduino/avr/variants/eightanaloginputs</Value>\r
+      <Value>C:/opt/arduino-1.6.5-r2/hardware/arduino/avr/cores/arduino</Value>\r
+    </ListValues>\r
+  </avrgcc.compiler.directories.IncludePaths>\r
+  <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>\r
+  <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>\r
+  <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>\r
+  <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>\r
+  <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>\r
+  <avrgcccpp.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcccpp.compiler.general.ChangeDefaultCharTypeUnsigned>\r
+  <avrgcccpp.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcccpp.compiler.general.ChangeDefaultBitFieldUnsigned>\r
+  <avrgcccpp.compiler.symbols.DefSymbols>\r
+    <ListValues>\r
+      <Value>__AVR_ATmega328p__</Value>\r
+      <Value>__AVR_ATmega328P__</Value>\r
+      <Value>ARDUINO=165</Value>\r
+      <Value>ARDUINO_MAIN</Value>\r
+      <Value>F_CPU=20000000L</Value>\r
+      <Value>__AVR__</Value>\r
+      <Value>ARDUINO_BARE</Value>\r
+      <Value>ARDUINO_ARCH_AVR</Value>\r
+    </ListValues>\r
+  </avrgcccpp.compiler.symbols.DefSymbols>\r
+  <avrgcccpp.compiler.directories.IncludePaths>\r
+    <ListValues>\r
+      <Value>C:/opt/arduino-1.6.5-r2/hardware/tools/avr/lib/gcc/avr/4.8.1/include</Value>\r
+      <Value>C:/opt/arduino-1.6.5-r2/hardware/tools/avr//avr/include/avr/</Value>\r
+      <Value>C:/opt/arduino-1.6.5-r2/hardware/tools/avr/avr/include/</Value>\r
+      <Value>c:/Code/arduino/libraries</Value>\r
+      <Value>C:/Program Files (x86)/Visual Micro/Visual Micro for Arduino/Micro Platforms/default/debuggers</Value>\r
+      <Value>c:/Code/arduino/hardware/Custom/avr/libraries</Value>\r
+      <Value>C:/Users/pt111992/AppData/Roaming/arduino15/packages/arduino/hardware/avr/1.6.8/libraries</Value>\r
+      <Value>C:/opt/arduino-1.6.5-r2/libraries</Value>\r
+      <Value>C:/Users/pt111992/AppData/Roaming/arduino15/packages/arduino/hardware/avr/1.6.8/libraries/SPI/utility</Value>\r
+      <Value>C:/Users/pt111992/AppData/Roaming/arduino15/packages/arduino/hardware/avr/1.6.8/libraries/SPI</Value>\r
+      <Value>c:/Code/arduino/libraries/OneWire/utility</Value>\r
+      <Value>c:/Code/arduino/libraries/OneWire</Value>\r
+      <Value>c:/Code/arduino/libraries/LiquidCrystal/utility</Value>\r
+      <Value>c:/Code/arduino/libraries/LiquidCrystal</Value>\r
+      <Value>c:/Code/arduino/libraries/DallasTemperature/utility</Value>\r
+      <Value>c:/Code/arduino/libraries/DallasTemperature</Value>\r
+      <Value>../../nRF24_BLE_Temperature</Value>\r
+      <Value>C:/opt/arduino-1.6.5-r2/hardware/arduino/avr/variants/eightanaloginputs</Value>\r
+      <Value>C:/opt/arduino-1.6.5-r2/hardware/arduino/avr/cores/arduino</Value>\r
+    </ListValues>\r
+  </avrgcccpp.compiler.directories.IncludePaths>\r
+  <avrgcccpp.compiler.optimization.level>Optimize (-O1)</avrgcccpp.compiler.optimization.level>\r
+  <avrgcccpp.compiler.optimization.PackStructureMembers>True</avrgcccpp.compiler.optimization.PackStructureMembers>\r
+  <avrgcccpp.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcccpp.compiler.optimization.AllocateBytesNeededForEnum>\r
+  <avrgcccpp.compiler.optimization.DebugLevel>Default (-g2)</avrgcccpp.compiler.optimization.DebugLevel>\r
+  <avrgcccpp.compiler.warnings.AllWarnings>True</avrgcccpp.compiler.warnings.AllWarnings>\r
+  <avrgcccpp.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcccpp.assembler.debugging.DebugLevel>\r
+</AvrGccCpp>\r
+    </ToolchainSettings>\r
+    <VMSETTING_IncludePaths>C:/Users/pt111992/AppData/Roaming/arduino15/packages/arduino/hardware/avr/1.6.8/cores/arduino;C:/Users/pt111992/AppData/Roaming/arduino15/packages/arduino/hardware/avr/1.6.8/variants/standard;../../nRF24_BLE_Temperature;c:/Code/arduino/libraries/DallasTemperature;c:/Code/arduino/libraries/DallasTemperature/utility;c:/Code/arduino/libraries/OneWire;c:/Code/arduino/libraries/OneWire/utility;C:/Users/pt111992/AppData/Roaming/arduino15/packages/arduino/hardware/avr/1.6.8/libraries/SPI;C:/Users/pt111992/AppData/Roaming/arduino15/packages/arduino/hardware/avr/1.6.8/libraries/SPI/utility;C:/opt/arduino-1.6.5-r2/libraries;C:/Users/pt111992/AppData/Roaming/arduino15/packages/arduino/hardware/avr/1.6.8/libraries;C:/Program Files (x86)/Visual Micro/Visual Micro for Arduino/Micro Platforms/default/debuggers;c:/Code/arduino/libraries;C:/opt/arduino-1.6.5-r2/hardware/tools/avr/avr/include/;C:/opt/arduino-1.6.5-r2/hardware/tools/avr//avr/include/avr/;C:/opt/arduino-1.6.5-r2/hardware/tools/avr/lib/gcc/avr/4.8.1/include;C:/opt/arduino-1.6.5-r2/hardware/arduino/avr/cores/arduino;C:/opt/arduino-1.6.5-r2/hardware/arduino/avr/variants/eightanaloginputs;c:/Code/arduino/hardware/Custom/avr/libraries;c:/Code/arduino/libraries/LiquidCrystal;c:/Code/arduino/libraries/LiquidCrystal/utility;</VMSETTING_IncludePaths>\r
+    <VisualMicroSettings>\r
+      <VisualMicroSettings>\r
+        <arduino.board.name>bare_20MHzatmega328</arduino.board.name>\r
+        <arduino.board.desc>Bare Arduino-style boards w/ ATmega328 (5V, 20 MHz)</arduino.board.desc>\r
+        <arduino.board.property_bag>name=Bare Arduino-style boards w/ ATmega328 (5V, 20 MHz)\r
+upload.tool=avrdude\r
+upload.protocol=arduino\r
+bootloader.tool=arduino:avrdude\r
+bootloader.unlock_bits=0x3F\r
+bootloader.lock_bits=0x0F\r
+build.board=BARE\r
+build.core=arduino:arduino\r
+build.variant=arduino:eightanaloginputs\r
+menu.cpu.16MHzatmega328=ATmega328 (5V, 16 MHz)\r
+menu.cpu.16MHzatmega328.upload.maximum_size=30720\r
+menu.cpu.16MHzatmega328.upload.maximum_data_size=2048\r
+menu.cpu.16MHzatmega328.upload.speed=57600\r
+menu.cpu.16MHzatmega328.bootloader.low_fuses=0xFF\r
+menu.cpu.16MHzatmega328.bootloader.high_fuses=0xDA\r
+menu.cpu.16MHzatmega328.bootloader.extended_fuses=0x05\r
+menu.cpu.16MHzatmega328.bootloader.file=atmega/ATmegaBOOT_168_atmega328.hex\r
+menu.cpu.16MHzatmega328.build.mcu=atmega328p\r
+menu.cpu.16MHzatmega328.build.f_cpu=16000000L\r
+menu.cpu.20MHzatmega328=ATmega328 (5V, 20 MHz)\r
+menu.cpu.20MHzatmega328.upload.maximum_size=30720\r
+menu.cpu.20MHzatmega328.upload.maximum_data_size=2048\r
+menu.cpu.20MHzatmega328.upload.speed=57600\r
+menu.cpu.20MHzatmega328.bootloader.low_fuses=0xF7\r
+menu.cpu.20MHzatmega328.bootloader.high_fuses=0xDA\r
+menu.cpu.20MHzatmega328.bootloader.extended_fuses=0x05\r
+menu.cpu.20MHzatmega328.bootloader.file=atmega/ATmegaBOOT_168_atmega328.hex\r
+menu.cpu.20MHzatmega328.build.mcu=atmega328p\r
+menu.cpu.20MHzatmega328.build.f_cpu=20000000L\r
+menu.cpu.8MHzatmega328=ATmega328 (3.3V, 8 MHz)\r
+menu.cpu.8MHzatmega328.upload.maximum_size=30720\r
+menu.cpu.8MHzatmega328.upload.maximum_data_size=2048\r
+menu.cpu.8MHzatmega328.upload.speed=57600\r
+menu.cpu.8MHzatmega328.bootloader.low_fuses=0xFF\r
+menu.cpu.8MHzatmega328.bootloader.high_fuses=0xDA\r
+menu.cpu.8MHzatmega328.bootloader.extended_fuses=0x05\r
+menu.cpu.8MHzatmega328.bootloader.file=atmega/ATmegaBOOT_168_atmega328_pro_8MHz.hex\r
+menu.cpu.8MHzatmega328.build.mcu=atmega328p\r
+menu.cpu.8MHzatmega328.build.f_cpu=8000000L\r
+runtime.ide.path=C:\opt\arduino-1.6.5-r2\r
+build.system.path=c:\Code\arduino\hardware\Custom\avr\system\r
+runtime.ide.version=165\r
+target_package=Custom\r
+target_platform=avr\r
+runtime.hardware.path=c:\Code\arduino\hardware\Custom\r
+originalid=bare\r
+intellisense.tools.path={runtime.tools.avr-gcc.path}/\r
+intellisense.include.paths={intellisense.tools.path}avr/include/;{intellisense.tools.path}/avr/include/avr/;{intellisense.tools.path}lib\gcc\avr\4.8.1\include\r
+tools.atprogram.cmd.path=%AVRSTUDIO_EXE_PATH%\atbackend\atprogram\r
+tools.atprogram.cmd.setwinpath=true\r
+tools.atprogram.program.params.verbose=-v\r
+tools.atprogram.program.params.quiet=-q\r
+tools.atprogram.program.pattern="{cmd.path}" -d {build.mcu} {program.verbose} {program.extra_params} program -c -f "{build.path}\{build.project_name}.hex"\r
+tools.atprogram.program.xpattern="{cmd.path}" {AVRSTUDIO_BACKEND_CONNECTION} -d {build.mcu} {program.verbose} {program.extra_params} program -c -f "{build.path}\{build.project_name}.hex"\r
+version=1.0.0\r
+compiler.warning_flags=-w\r
+compiler.warning_flags.none=-w\r
+compiler.warning_flags.default=\r
+compiler.warning_flags.more=-Wall\r
+compiler.warning_flags.all=-Wall -Wextra\r
+compiler.path={runtime.tools.avr-gcc.path}/bin/\r
+compiler.c.cmd=avr-gcc\r
+compiler.c.flags=-c -g -Os {compiler.warning_flags} -ffunction-sections -fdata-sections -MMD\r
+compiler.c.elf.flags={compiler.warning_flags} -Os -Wl,--gc-sections\r
+compiler.c.elf.cmd=avr-gcc\r
+compiler.S.flags=-c -g -x assembler-with-cpp\r
+compiler.cpp.cmd=avr-g++\r
+compiler.cpp.flags=-c -g -Os {compiler.warning_flags} -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD\r
+compiler.ar.cmd=avr-ar\r
+compiler.ar.flags=rcs\r
+compiler.objcopy.cmd=avr-objcopy\r
+compiler.objcopy.eep.flags=-O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0\r
+compiler.elf2hex.flags=-O ihex -R .eeprom\r
+compiler.elf2hex.cmd=avr-objcopy\r
+compiler.ldflags=\r
+compiler.size.cmd=avr-size\r
+build.extra_flags=\r
+compiler.c.extra_flags=\r
+compiler.c.elf.extra_flags=\r
+compiler.S.extra_flags=\r
+compiler.cpp.extra_flags=\r
+compiler.ar.extra_flags=\r
+compiler.objcopy.eep.extra_flags=\r
+compiler.elf2hex.extra_flags=\r
+recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.c.flags} -mmcu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.c.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"\r
+recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} -mmcu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"\r
+recipe.S.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.S.flags} -mmcu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.S.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"\r
+recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{build.path}/{archive_file}" "{object_file}"\r
+recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.flags} -mmcu={build.mcu} {compiler.c.elf.extra_flags} -o "{build.path}/{build.project_name}.elf" {object_files} "{build.path}/{archive_file}" "-L{build.path}" -lm\r
+recipe.objcopy.eep.pattern="{compiler.path}{compiler.objcopy.cmd}" {compiler.objcopy.eep.flags} {compiler.objcopy.eep.extra_flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.eep"\r
+recipe.objcopy.hex.pattern="{compiler.path}{compiler.elf2hex.cmd}" {compiler.elf2hex.flags} {compiler.elf2hex.extra_flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.hex"\r
+recipe.output.tmp_file={build.project_name}.hex\r
+recipe.output.save_file={build.project_name}.{build.variant}.hex\r
+recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/{build.project_name}.elf"\r
+recipe.size.regex=^(?:\.text|\.data|\.bootloader)\s+([0-9]+).*\r
+recipe.size.regex.data=^(?:\.data|\.bss|\.noinit)\s+([0-9]+).*\r
+recipe.size.regex.eeprom=^(?:\.eeprom)\s+([0-9]+).*\r
+tools.avrdude.path={runtime.tools.avrdude.path}\r
+tools.avrdude.cmd.path={path}/bin/avrdude\r
+tools.avrdude.config.path={path}/etc/avrdude.conf\r
+tools.avrdude.upload.params.verbose=-v\r
+tools.avrdude.upload.params.quiet=-q -q\r
+tools.avrdude.upload.pattern="{cmd.path}" "-C{config.path}" {upload.verbose} -p{build.mcu} -c{upload.protocol} -P{serial.port} -b{upload.speed} -D "-Uflash:w:{build.path}/{build.project_name}.hex:i"\r
+tools.avrdude.program.params.verbose=-v\r
+tools.avrdude.program.params.quiet=-q -q\r
+tools.avrdude.program.pattern="{cmd.path}" "-C{config.path}" {program.verbose} -p{build.mcu} -c{protocol} {program.extra_params} "-Uflash:w:{build.path}/{build.project_name}.hex:i"\r
+tools.avrdude.erase.params.verbose=-v\r
+tools.avrdude.erase.params.quiet=-q -q\r
+tools.avrdude.erase.pattern="{cmd.path}" "-C{config.path}" {erase.verbose} -p{build.mcu} -c{protocol} {program.extra_params} -e -Ulock:w:{bootloader.unlock_bits}:m -Uefuse:w:{bootloader.extended_fuses}:m -Uhfuse:w:{bootloader.high_fuses}:m -Ulfuse:w:{bootloader.low_fuses}:m\r
+tools.avrdude.bootloader.params.verbose=-v\r
+tools.avrdude.bootloader.params.quiet=-q -q\r
+tools.avrdude.bootloader.pattern="{cmd.path}" "-C{config.path}" {bootloader.verbose} -p{build.mcu} -c{protocol} {program.extra_params} "-Uflash:w:{runtime.platform.path}/bootloaders/{bootloader.file}:i" -Ulock:w:{bootloader.lock_bits}:m\r
+build.usb_manufacturer="Unknown"\r
+build.usb_flags=-DUSB_VID={build.vid} -DUSB_PID={build.pid} '-DUSB_MANUFACTURER={build.usb_manufacturer}' '-DUSB_PRODUCT={build.usb_product}'\r
+vm.platform.root.path=C:\Program Files (x86)\Visual Micro\Visual Micro for Arduino\Micro Platforms\arduino16x\r
+runtime.tools.arm-none-eabi-gcc.path=C:\Users\pt111992\AppData\Roaming\arduino15\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1\r
+runtime.tools.arm-none-eabi-gcc-4.8.3-2014q1.path=C:\Users\pt111992\AppData\Roaming\arduino15\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1\r
+runtime.tools.avrdude.path=C:\opt\arduino-1.6.5-r2\hardware\tools\avr\r
+runtime.tools.avrdude-6.0.1-arduino5.path=C:\opt\arduino-1.6.5-r2\hardware\tools\avr\r
+runtime.tools.avr-gcc.path=C:\opt\arduino-1.6.5-r2\hardware\tools\avr\r
+runtime.tools.avr-gcc-4.8.1-arduino5.path=C:\opt\arduino-1.6.5-r2\hardware\tools\avr\r
+runtime.tools.bossac.path=C:\Users\pt111992\AppData\Roaming\arduino15\packages\arduino\tools\bossac\1.6-arduino\r
+runtime.tools.bossac-1.6-arduino.path=C:\Users\pt111992\AppData\Roaming\arduino15\packages\arduino\tools\bossac\1.6-arduino\r
+runtime.tools.CMSIS.path=C:\Users\pt111992\AppData\Roaming\arduino15\packages\arduino\tools\CMSIS\4.0.0-atmel\r
+runtime.tools.CMSIS-4.0.0-atmel.path=C:\Users\pt111992\AppData\Roaming\arduino15\packages\arduino\tools\CMSIS\4.0.0-atmel\r
+runtime.tools.openocd.path=C:\Users\pt111992\AppData\Roaming\arduino15\packages\arduino\tools\openocd\0.9.0-arduino\r
+runtime.tools.openocd-0.9.0-arduino.path=C:\Users\pt111992\AppData\Roaming\arduino15\packages\arduino\tools\openocd\0.9.0-arduino\r
+upload.maximum_size=30720\r
+upload.maximum_data_size=2048\r
+upload.speed=57600\r
+bootloader.low_fuses=0xF7\r
+bootloader.high_fuses=0xDA\r
+bootloader.extended_fuses=0x05\r
+bootloader.file=atmega/ATmegaBOOT_168_atmega328.hex\r
+build.mcu=atmega328p\r
+build.f_cpu=20000000L\r
+ide.hint=Arduino 1.6.x ide with support for downloaded Board Manager custom tools and hardware\r
+ide.location.key=Arduino16x\r
+ide.location.ide.winreg=Arduino 1.6.x Application\r
+ide.location.sketchbook.winreg=Arduino 1.6.x Sketchbook\r
+ide.location.sketchbook.preferences=sketchbook.path\r
+ide.default.version=160\r
+ide.default.package=arduino\r
+ide.default.platform=avr\r
+ide.multiplatform=true\r
+ide.includes=arduino.h\r
+ide.exe_name=arduino\r
+ide.platformswithoutpackage=false\r
+ide.includes.fallback=wprogram.h\r
+ide.extension=ino\r
+ide.extension.fallback=pde\r
+ide.versionGTEQ=160\r
+ide.exe=arduino.exe\r
+ide.hosts=atmel\r
+ide.url=http://arduino.cc/en/Main/Software\r
+ide.help.reference.path=reference\arduino.cc\en\Reference\r
+vm.debug=true\r
+software=ARDUINO\r
+ssh.user.name=root\r
+ssh.user.default.password=arduino\r
+ssh.host.wwwfiles.path=/www/sd\r
+build.working_directory={runtime.ide.path}\r
+ide.location.preferences.portable={runtime.ide.path}\portable\r
+ide.location.preferences=%VM_APPDATA_ROAMING%\arduino15\preferences.txt\r
+ide.location.preferences_fallback=%VM_APPDATA_LOCAL%\arduino15\preferences.txt\r
+ide.location.contributions=%VM_APPDATA_LOCAL%\arduino15\r
+ide.location.contributions_fallback=%VM_APPDATA_ROAMING%\arduino15\r
+ide.contributions.boards.allow=true\r
+ide.contributions.boards.ignore_unless_rewrite_found=true\r
+ide.contributions.libraries.allow=true\r
+ide.contributions.boards.support.urls.wiki=https://github.com/arduino/Arduino/wiki/Unofficial-list-of-3rd-party-boards-support-urls\r
+ide.appid=arduino16x\r
+location.sketchbook=c:\Code\arduino\r
+vm.core.include=arduino.h\r
+vm.boardsource.path=c:\Code\arduino\hardware\Custom\avr\r
+runtime.platform.path=c:\Code\arduino\hardware\Custom\avr\r
+vm.platformname.name=avr\r
+build.arch=AVR\r
+</arduino.board.property_bag>\r
+        <arduino.build.mcu>atmega328p</arduino.build.mcu>\r
+        <arduino.build.f_cpu>20000000L</arduino.build.f_cpu>\r
+        <arduino.build.core>arduino</arduino.build.core>\r
+        <arduino.upload.protocol>arduino</arduino.upload.protocol>\r
+        <arduino.upload.speed>57600</arduino.upload.speed>\r
+        <arduino.upload.maximum_size>30720</arduino.upload.maximum_size>\r
+        <visualmicro.application.name>arduino16x</visualmicro.application.name>\r
+        <visualmicro.package.name>Custom</visualmicro.package.name>\r
+        <visualmicro.platform.name>avr</visualmicro.platform.name>\r
+      </VisualMicroSettings>\r
+    </VisualMicroSettings>\r
+  </PropertyGroup>\r
+  <ItemGroup>\r
+    <None Include="nRF24_BLE_Temperature.ino">\r
+      <SubType>compile</SubType>\r
+    </None>\r
+  </ItemGroup>\r
+  <ItemGroup>\r
+    <Folder Include="Visual Micro\" />\r
+  </ItemGroup>\r
+  <ItemGroup>\r
+    <Compile Include="BLE24.cpp">\r
+      <SubType>compile</SubType>\r
+    </Compile>\r
+    <Compile Include="BLE24.h">\r
+      <SubType>compile</SubType>\r
+    </Compile>\r
+    <Compile Include="Visual Micro\.nRF24_BLE_Temperature.vsarduino.h">\r
+      <SubType>compile</SubType>\r
+    </Compile>\r
+  </ItemGroup>\r
+  <Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />\r
+</Project>
\ No newline at end of file
index 047ab1874b34ef0d6e026696efb7564cb04ea925..88e6b8bc62ee0c919b63a5ffc8091b83447d47b5 100644 (file)
 #include <SPI.h>
 #include <OneWire.h>
 #include <DallasTemperature.h>
-#include <LiquidCrystal_I2C.h>
-
-#define LCD_ADDR 0x20
-#define LCD_EN_BIT 4
-#define LCD_RW_BIT 5
-#define LCD_RS_BIT 6
-#define LCD_D4_BIT 0
-#define LCD_BL_BIT 7
-
-LiquidCrystal_I2C lcd(LCD_ADDR, LCD_EN_BIT, LCD_RW_BIT, LCD_RS_BIT,
-LCD_D4_BIT, LCD_D4_BIT+1, LCD_D4_BIT+2, LCD_D4_BIT+3);
-
-#define PIN_CE  8 // chip enable
-#define PIN_CSN 10  // chip select (for SPI)
+#include <LiquidCrystal_I2C.h>\r
+#include <RHDatagram.h>\r
+#include <RH_NRF24.h>\r
+#include "BLE24.h"\r
+\r
+static void I2C_Init();\r
+static void LCD_Init();\r
+static void RTC_Init();\r
+static void Radio_Init();\r
+static void DS18B20_Init();\r
+static void PrintAddress(Print *stream, DeviceAddress address);\r
+\r
+#define RADIO_CE_PIN  8\r
+#define RADIO_CHANNEL 85\r
 #define PIN_LED 6
 #define PIN_ONEWIRE 4
-
-// The MAC address of BLE advertiser -- just make one up
-#define MY_MAC_0       0x01
-#define MY_MAC_1       0x02
-#define MY_MAC_2       0xef
-#define MY_MAC_3       0xbe
-#define MY_MAC_4       0xad
-#define MY_MAC_5       0xde
-
-// Service UUIDs used on the nRF8001 and nRF51822 platforms
-#define NRF_TEMPERATURE_SERVICE_UUID        0x1809
-#define NRF_BATTERY_SERVICE_UUID            0x180F
-#define NRF_DEVICE_INFORMATION_SERVICE_UUID 0x180A
-
-uint8_t buf[32];
-static const uint8_t chRf[] = {2, 26,80};
-static const uint8_t chLe[] = {37,38,39};
-uint8_t ch = 0;  // RF channel for frequency hopping
+\r
+#define SENSOR_HUB_ADDRESS 1\r
+#define DEVICE_ADDRESS 2\r
+\r
+#define LCD_ADDR 0x20\r
+#define LCD_EN_BIT 4\r
+#define LCD_RW_BIT 5\r
+#define LCD_RS_BIT 6\r
+#define LCD_D4_BIT 0\r
+#define LCD_BL_BIT 7\r
+\r
+LiquidCrystal_I2C lcd(LCD_ADDR, LCD_EN_BIT, LCD_RW_BIT, LCD_RS_BIT,\r
+LCD_D4_BIT, LCD_D4_BIT+1, LCD_D4_BIT+2, LCD_D4_BIT+3);
 
 #define SENSOR_RESOLUTION 12
 OneWire w1bus(PIN_ONEWIRE);
-DallasTemperature sensor(&w1bus);
-DeviceAddress sensorAddress;
-bool have_sensor = false;
+DallasTemperature w1sensors(&w1bus);
+DeviceAddress w1sensorAddress;
+RH_NRF24 nrf24(PIN_CSN, PIN_CE);\r
+RHDatagram Radio(nrf24, SENSOR_HUB_ADDRESS);
+CBTLE BTLE;
+bool UseLCDDisplay = false;
+bool UseOneWire = false;
+bool UseRadio = false;
 float currentTemperature = 20.0f;
 uint8_t state = 0;
-
-// Converts a temperature value in 100ths degrees C into a nRF float (4 bytes)
-int32_t nrf_float(float t)
-{
-    const int32_t exponent = -2;
-    return ((exponent & 0xff) << 24) | (((int32_t)(t * 100)) & 0x00ffffff);
-}
-
-// implementing CRC with LFSR
-void btLeCrc(const uint8_t* data, uint8_t len, uint8_t* dst)
-{
-    uint8_t v, t, d;
-
-    while(len--)
-    {
-        d = *data++;
-        for(v = 0; v < 8; v++, d >>= 1)
-        {
-            t = dst[0] >> 7;
-            dst[0] <<= 1;
-            if(dst[1] & 0x80) dst[0] |= 1;
-            dst[1] <<= 1;
-            if(dst[2] & 0x80) dst[1] |= 1;
-            dst[2] <<= 1;
-
-            if(t != (d & 1))
-            {
-              dst[2] ^= 0x5B;
-              dst[1] ^= 0x06;
-            }
-        }
-    }
-}
-
-// reverse the bit order in a single byte
-uint8_t swapbits(uint8_t x)
-{
-#ifdef __BUILTIN_AVR_INSERT_BITS
-    return __builtin_avr_insert_bits(0x01234567, x, 0);
-#else
-    uint8_t v = 0;
-    if(x & 0x80) v |= 0x01;
-    if(x & 0x40) v |= 0x02;
-    if(x & 0x20) v |= 0x04;
-    if(x & 0x10) v |= 0x08;
-    if(x & 0x08) v |= 0x10;
-    if(x & 0x04) v |= 0x20;
-    if(x & 0x02) v |= 0x40;
-    if(x & 0x01) v |= 0x80;
-    return v;
-#endif
-}
-
-// Implementing whitening with LFSR
-void btLeWhiten(uint8_t* data, uint8_t len, uint8_t whitenCoeff)
-{
-    uint8_t  m;
-    while(len--){
-        for(m = 1; m; m <<= 1){
-            if(whitenCoeff & 0x80){
-                whitenCoeff ^= 0x11;
-                (*data) ^= m;
-            }
-            whitenCoeff <<= 1;
-        }
-        data++;
-    }
-}
-
-//the value we actually use is what BT'd use left shifted one...makes our life easier
-static inline uint8_t btLeWhitenStart(uint8_t chan)
-{
-    return swapbits(chan) | 2; 
-}
-
-// Assemble the packet to be transmitted
-// Length is of packet, including crc. pre-populate crc in packet with initial crc value!
-void btLePacketEncode(uint8_t* packet, uint8_t len, uint8_t chan)
-{
-    uint8_t i, dataLen = len - 3;
-    btLeCrc(packet, dataLen, packet + dataLen);
-    for(i = 0; i < 3; i++, dataLen++) 
-        packet[dataLen] = swapbits(packet[dataLen]);
-    btLeWhiten(packet, len, btLeWhitenStart(chan));
-    for(i = 0; i < len; i++) 
-        packet[i] = swapbits(packet[i]); // the byte order of the packet should be reversed as well
-}
-
-uint8_t spi_byte(uint8_t byte)
-{
-    // using Arduino's SPI library; clock out one byte
-    SPI.transfer(byte); 
-    return byte;
-}
-
-void nrf_cmd(uint8_t cmd, uint8_t data)
-{
-    // Write to nRF24's register
-    digitalWrite(PIN_CSN, LOW);
-    spi_byte(cmd);
-    spi_byte(data);
-    digitalWrite(PIN_CSN, HIGH); 
-}
-
-void nrf_simplebyte(uint8_t cmd)
-{
-    // transfer only one byte 
-    digitalWrite(PIN_CSN, LOW); 
-    spi_byte(cmd);
-    digitalWrite(PIN_CSN, HIGH); 
-}
-
-void nrf_manybytes(uint8_t* data, uint8_t len)
-{
-    // transfer several bytes in a row
-    digitalWrite(PIN_CSN, LOW); 
-        do{
-            spi_byte(*data++);
-    } while(--len);
-    digitalWrite(PIN_CSN, HIGH); 
-}
-
-volatile int analogValue;
-static void Analog_Init()
-{
-    analogValue = 0;
-    // REFS[1:0]: 0b00: AREF; 0b01: AVCC; 0b11: internal 1V1
-    // ADLAR = 0: do not enable left adjust
-    // MUX[3:0]: using pin A1 (0b0001)
-    ADMUX = _BV(MUX0) | _BV(REFS0);// Internal 5V
-    // ADEN: enable the ADC
-    // ADATE: enable auto trigger
-    // ADIE: adc interrupt enabled
-    // ADPS[2:0]: adc clock prescale 16MHz/128 so 125kHz
-    ADCSRA = _BV(ADEN) | _BV(ADATE) | _BV(ADIE)
-    | _BV(ADPS2) | _BV(ADPS1) | _BV(ADPS0);
-    // ADTS[2:0]: AutoTrigger Source: use free running mode
-    ADCSRB = 0;
-    // Disable the digital functions for pin A2
-    DIDR0 |= _BV(ADC2D);
-    // ADSC: start the freerunning conversion
-    //    if not freerunning we could alternate between a set of sources
-    //     like AD8 which is the internal temperature.
-    ADCSRA |= _BV(ADSC);
-}
-
-static int GetAnalogValue() { return analogValue; }
-static int GetAnalogMillivolts() { return (analogValue * 5120) / 1024; }
-
-static long GetHumidity()
-{
-    // Vref is externally provided and set to 5ishV.
-    long millivolts = (analogValue * 5120) / 1024;
-    // HU10 range is 1V == 0% to 3V == 100%.
-    long rh = ((millivolts - 1000) * 100000) / 2000;
-    return rh; /* value is percentage * 1000 */
-}
-
-ISR(ADC_vect)
-{
-    // NOTE: MUST read the low byte first, reading ADCH resets.
-    analogValue = ADCL | (ADCH << 8);
-    // If not in free-running mode then start another conversion
-    // ADCSRA |= _BV(ADSC);
+unsigned long btle_time = 0;
+
+static void Radio_Init()\r
+{\r
+    if (Radio.init())\r
+    {\r
+        Radio.setThisAddress(DEVICE_ADDRESS);\r
+        if (nrf24.setChannel(RADIO_CHANNEL))\r
+        {\r
+            UseRadio = true;\r
+            Serial.println(F("Radio initialized"));\r
+        }\r
+        else\r
+        {\r
+            Serial.println(F("Radio: failed to select channel"));\r
+        }\r
+    }\r
+    else\r
+    {\r
+        Serial.println(F("Radio initialization failed"));\r
+    }\r
+}\r
+\r
+static void Radio_End()\r
+{\r
+    \r
+}\r
+\r
+static void Radio_Send(uint8_t *data, uint8_t len)\r
+{\r
+    if (UseRadio)\r
+    {\r
+        nrf24.setModeTx();\r
+        if (!Radio.sendto(data, len, SENSOR_HUB_ADDRESS))\r
+        {\r
+            Serial.println(F("Radio: failed to send"));\r
+        }\r
+        //if (!nrf24.sleep())\r
+        //    Serial.println(F("Radio: failed to enter sleep mode"));\r
+    }\r
+}\r
+\r
+// Find any 1-wire sensors and use the first one. Trigger an async conversion.\r
+static void OneWire_Init()\r
+{\r
+    Serial.println(F("Initializing OneWire bus..."));\r
+    w1sensors.begin();\r
+    w1sensors.setResolution(12);\r
+    w1sensors.setWaitForConversion(false);\r
+    int count = w1sensors.getDeviceCount();\r
+    for (int n = 0; n < count; ++n)\r
+    {\r
+        if (w1sensors.getAddress(w1sensorAddress, n))\r
+        {\r
+            Serial.print(n);\r
+            Serial.print(F(": "));\r
+            PrintAddress(&Serial, w1sensorAddress);\r
+            Serial.println();\r
+            UseOneWire = true;\r
+            w1sensors.requestTemperatures();\r
+        }\r
+    }\r
+}\r
+\r
+static void PrintAddress(Print *stream, DeviceAddress address)\r
+{\r
+    for (int n = 0; n < 8; ++n)\r
+    {\r
+        if (address[n] < 16)\r
+        stream->print('0');\r
+        stream->print(address[n], HEX);\r
+    }\r
+}\r
+\r
+static void I2C_Init()\r
+{\r
+    for (uint8_t addr = 0; addr < 127; ++addr)\r
+    {\r
+        Wire.beginTransmission(addr);\r
+        uint8_t err = Wire.endTransmission();\r
+        if (err == 0)\r
+        {\r
+            Serial.print(F("# Found I2C device at 0x"));\r
+            if (addr < 16) Serial.print('0');\r
+            Serial.print(addr, HEX);\r
+            if (addr == 0x20) { Serial.print(F(" (LCD)")); UseLCDDisplay = true; }\r
+            if (addr == 0x22) { Serial.print(F(" (LED)")); /*UseLedDisplay = true;*/ }\r
+            if (addr == 0x57) { Serial.print(F(" (EEPROM)")); }\r
+            if (addr == 0x68) { Serial.print(F(" (RTC)")); /* UseRTC = true; */}\r
+            Serial.println();\r
+        }\r
+        else if (err == 4)\r
+        {\r
+            Serial.print(F("# Unknown error at address 0x"));\r
+            if (addr < 16) Serial.print('0');\r
+            Serial.print(addr, HEX);\r
+        }\r
+    }\r
+}\r
+\r
+static void LCD_Init()\r
+{\r
+    if (UseLCDDisplay)\r
+    {\r
+        lcd.begin(16, 2);\r
+        lcd.clear();\r
+        lcd.print(F("BTLE Beacon"));\r
+    }\r
+}\r
+\r
+volatile int analogValue;\r
+static void Analog_Init()\r
+{\r
+    analogValue = 0;\r
+    // REFS[1:0]: 0b00: AREF; 0b01: AVCC; 0b11: internal 1V1\r
+    // ADLAR = 0: do not enable left adjust\r
+    // MUX[3:0]: using pin A1 (0b0001)\r
+    ADMUX = _BV(MUX0) | _BV(REFS0);// Internal 5V\r
+    // ADEN: enable the ADC\r
+    // ADATE: enable auto trigger\r
+    // ADIE: adc interrupt enabled\r
+    // ADPS[2:0]: adc clock prescale 16MHz/128 so 125kHz\r
+    ADCSRA = _BV(ADEN) | _BV(ADATE) | _BV(ADIE)\r
+    | _BV(ADPS2) | _BV(ADPS1) | _BV(ADPS0);\r
+    // ADTS[2:0]: AutoTrigger Source: use free running mode\r
+    ADCSRB = 0;\r
+    // Disable the digital functions for pin A2\r
+    DIDR0 |= _BV(ADC2D);\r
+    // ADSC: start the freerunning conversion\r
+    //    if not freerunning we could alternate between a set of sources\r
+    //     like AD8 which is the internal temperature.\r
+    ADCSRA |= _BV(ADSC);\r
+}\r
+\r
+static int GetAnalogValue() { return analogValue; }\r
+static int GetAnalogMillivolts() { return (analogValue * 5120) / 1024; }\r
+\r
+static long GetHumidity()\r
+{\r
+    // Vref is externally provided and set to 5ishV.\r
+    long millivolts = (analogValue * 5120) / 1024;\r
+    // HU10 range is 1V == 0% to 3V == 100%.\r
+    long rh = ((millivolts - 1000) * 100000) / 2000;\r
+    return rh; /* value is percentage * 1000 */\r
 }
+\r
+ISR(ADC_vect)\r
+{\r
+    // NOTE: MUST read the low byte first, reading ADCH resets.\r
+    analogValue = ADCL | (ADCH << 8);\r
+    // If not in free-running mode then start another conversion\r
+    // ADCSRA |= _BV(ADSC);\r
+}\r
 
 static void UpdateDisplay()
 {
-    lcd.setCursor(0, 1);
-    lcd.print(currentTemperature);
-    lcd.print((char)0xdf);
+    lcd.home();
+    lcd.print(currentTemperature);\r
+    lcd.print((char)0xdf);\r
     lcd.print("C ");
     lcd.print(static_cast<float>(GetHumidity())/1000.0f);
     lcd.print(" RH");
+    lcd.setCursor(0, 1);\r
+    lcd.print("BTLE Beacon: ");\r
+    lcd.print(btle_time);
+    lcd.print("ms");
 }
 
-void setup()
+// Send the temperature using normal NRF24 comms over channel 85
+static void Send_IoT()
 {
-    pinMode(PIN_LED, OUTPUT);
-    pinMode(PIN_CSN, OUTPUT);
-    pinMode(PIN_CE, OUTPUT);
-    pinMode(11, OUTPUT);
-    pinMode(13, OUTPUT);
-    digitalWrite(PIN_LED, HIGH);
-    digitalWrite(PIN_CSN, HIGH);
-    digitalWrite(PIN_CE, LOW);
-
-    sensor.begin();
-    sensor.setResolution(SENSOR_RESOLUTION);
-    sensor.setWaitForConversion(false);
-    have_sensor = sensor.getAddress(sensorAddress, 0);
-    if (have_sensor)
-        sensor.requestTemperatures();
-
-    Serial.begin(57600);
-    Serial.println(F("# BTLE beacon"));
-    SPI.begin();
-    SPI.setBitOrder(MSBFIRST);
+    BTLE.end();
+    Radio_Init();
+    Radio_Send((uint8_t *)&currentTemperature, sizeof(currentTemperature));
+    Radio_End();
+    BTLE.begin(PIN_CE, PIN_CSN);
+}
 
+void setup()
+{
     Analog_Init();
-
     Wire.begin();
-    lcd.begin(16,2);
-    lcd.clear();
-    lcd.print("BTLE Beacon");
+    SPI.begin();
+    SPI.setBitOrder(MSBFIRST);
+    Serial.begin(57600);
+    Serial.println(F("# BTLE Beacon"));
+    I2C_Init();
+    LCD_Init();
+    OneWire_Init();
 
-    // Now initialize nRF24L01+, setting general parameters
-    nrf_cmd(0x20, 0x12);       //on, no crc, int on RX/TX done
-    nrf_cmd(0x21, 0x00);       //no auto-acknowledge
-    nrf_cmd(0x22, 0x00);       //no RX
-    nrf_cmd(0x23, 0x02);       //4-byte address
-    nrf_cmd(0x24, 0x00);       //no auto-retransmit
-    nrf_cmd(0x26, 0x06);       //1MBps at 0dBm
-    nrf_cmd(0x27, 0x3E);       //clear various flags
-    nrf_cmd(0x3C, 0x00);       //no dynamic payloads
-    nrf_cmd(0x3D, 0x00);       //no features
-    nrf_cmd(0x31, 32);   //always RX 32 bytes
-    nrf_cmd(0x22, 0x01);       //RX on pipe 0
+    pinMode(PIN_LED, OUTPUT);
+    digitalWrite(PIN_LED, HIGH);
 
-    // Set access addresses (TX address in nRF24L01) to BLE advertising 0x8E89BED6
-    // Remember that both bit and byte orders are reversed for BLE packet format
-    buf[0] = 0x30;
-    buf[1] = swapbits(0x8E);
-    buf[2] = swapbits(0x89);
-    buf[3] = swapbits(0xBE);
-    buf[4] = swapbits(0xD6);
-    nrf_manybytes(buf, 5);
-    buf[0] = 0x2A;    // set RX address in nRF24L01, doesn't matter because RX is ignored in this case
-    nrf_manybytes(buf, 5);
+    BTLE.begin(PIN_CE, PIN_CSN);
 
     for (int n = 0; n < 20; ++n)
     {
@@ -282,89 +247,41 @@ void setup()
     }
 
     // must have waited a total of 750 ms
-    if (have_sensor)
+    if (UseOneWire)
     {
-        currentTemperature = sensor.getTempC(sensorAddress);
+        currentTemperature = w1sensors.getTempC(w1sensorAddress);
     }
-    UpdateDisplay();
 }
 
 void loop()
 {
-    // Channel hopping
-    for (ch=0; ch<sizeof(chRf); ch++)
-    {
-        uint8_t i, L=0;
-
-        buf[L++] = 0x42;       //PDU type, given address is random; 0x42 for Android and 0x40 for iPhone
-        buf[L++] = 24; // length of payload
-
-        buf[L++] = MY_MAC_0;
-        buf[L++] = MY_MAC_1;
-        buf[L++] = MY_MAC_2;
-        buf[L++] = MY_MAC_3;
-        buf[L++] = MY_MAC_4;
-        buf[L++] = MY_MAC_5;
-
-        /* device descriptor chunk */
-        buf[L++] = 2;     /* chunk size 2 bytes */
-        buf[L++] = 0x01;  /* chunk type: device flags */
-        buf[L++] = 0x05;  /* data: 0x05 == LE only, limited discovery mode */
-
-        /* name chunk */
-        buf[L++] = 6;     /* chunk size: 7 bytes */
-        buf[L++] = 0x09;  /* chunk type: complete name */
-        buf[L++] = 'n';
-        buf[L++] = 'R';
-        buf[L++] = 'F';
-        buf[L++] = '2';
-        buf[L++] = '4';
-
-        buf[L++] = 7;
-        buf[L++] = 0x16;
-        buf[L++] = (uint8_t)(NRF_TEMPERATURE_SERVICE_UUID);
-        buf[L++] = (uint8_t)((NRF_TEMPERATURE_SERVICE_UUID >> 8) & 0xff);
-        {
-            int32_t t = nrf_float(currentTemperature);
-            memcpy(&buf[L], &t, sizeof(t));
-            L += sizeof(t);
-        }
-
-        buf[L++] = 0x55;       //CRC start value: 0x555555
-        buf[L++] = 0x55;
-        buf[L++] = 0x55;
-
-        nrf_cmd(0x25, chRf[ch]);
-        nrf_cmd(0x27, 0x6E);   // Clear flags
-
-        btLePacketEncode(buf, L, chLe[ch]);
-        nrf_simplebyte(0xE2); //Clear RX Fifo
-        nrf_simplebyte(0xE1); //Clear TX Fifo
-
-        digitalWrite(PIN_CSN, LOW);
-        spi_byte(0xA0);
-        for(i = 0 ; i < L ; i++) spi_byte(buf[i]);
-        digitalWrite(PIN_CSN, HIGH); 
-
-        nrf_cmd(0x20, 0x12);   // TX on
-        digitalWrite(PIN_CE, HIGH); // Enable Chip
-        delay(2);        // 
-        digitalWrite(PIN_CE, LOW);   // (in preparation of switching to RX quickly)
-    }
-
-    if (have_sensor)
+    unsigned int channel_index;
+    uint8_t btle_packet[BTLE_BUFFER_SIZE];\r
+    unsigned int btle_packet_len;
+
+    unsigned long start = millis();
+    btle_packet_len = BTLE.mkpacket(btle_packet, sizeof(btle_packet), currentTemperature);
+    for (unsigned int channel_index = 0; channel_index < BTLE_NUM_CHANNELS; ++channel_index)\r
+    {\r
+        BTLE.announce(channel_index, btle_packet, btle_packet_len);\r
+    }\r
+    btle_time = millis() - start;\r
+
+    if (UseOneWire)
     {
         switch (state)
         {
           case 0:
-              sensor.requestTemperatures();
+              w1sensors.requestTemperatures();
               state = 1;
               break;
           case 1:
+              if (UseRadio)
+                  Send_IoT();
               state = 2; // just allow over 750ms for conversion.
               break;
           case 2:
-              currentTemperature = sensor.getTempC(sensorAddress);
+              currentTemperature = w1sensors.getTempC(w1sensorAddress);
               Serial.println(currentTemperature);
               UpdateDisplay();
               state = 0;