From e3c89a1a22cf8b01891bb962a5c774f544cf8b50 Mon Sep 17 00:00:00 2001 From: Pat Thoyts Date: Sat, 17 Oct 2015 21:30:39 +0100 Subject: [PATCH] Implemented BTLE and normal nRF24 message with temperature and LCD display. 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 | 4 + BLE24.cpp | 235 ++++++++++++ BLE24.h | 36 ++ nRF24_BLE_Temperature.cppproj | 656 ++++++++++++++++++++++++++++++++++ nRF24_BLE_Temperature.ino | 549 ++++++++++++---------------- 5 files changed, 1164 insertions(+), 316 deletions(-) create mode 100644 .gitignore create mode 100644 BLE24.cpp create mode 100644 BLE24.h create mode 100644 nRF24_BLE_Temperature.cppproj diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b9e61c8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +*.atsln +*.atsuo +Visual Micro/ +Debug/ diff --git a/BLE24.cpp b/BLE24.cpp new file mode 100644 index 0000000..1d824a2 --- /dev/null +++ b/BLE24.cpp @@ -0,0 +1,235 @@ +#include +#include +#include "BLE24.h" + +static 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; + } + } + } +} + +static 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 +} + +static 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++; + } +} + +inline static uint8_t btLeWhitenStart(uint8_t chan) +{ + /* the value we actually use is what BT'd use left shifted one...makes our life easier */ + return swapbits(chan) | 2; +} + +static void btLePacketEncode(uint8_t *packet, uint8_t len, uint8_t chan) +{ + /* length is of packet, including crc. pre-populate crc in packet with initial crc value! */ + 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]); +} + +inline static uint8_t spi_byte(uint8_t byte) +{ + return SPI.transfer(byte); +} + +static void nrf_cmd(uint8_t cmd, uint8_t data) +{ + digitalWrite(PIN_CSN, LOW); + spi_byte(cmd); + spi_byte(data); + digitalWrite(PIN_CSN, HIGH); +} + +static void nrf_simplebyte(uint8_t cmd) +{ + digitalWrite(PIN_CSN, LOW); + spi_byte(cmd); + digitalWrite(PIN_CSN, HIGH); +} + +static void nrf_manybytes(uint8_t *data, uint8_t len) +{ + digitalWrite(PIN_CSN, LOW); + do { + spi_byte(*data++); + } while(--len); + digitalWrite(PIN_CSN, HIGH); +} + +static void nrf_init() +{ + uint8_t buf[5]; + + // Now initialize nRF24L01+, setting general parameters + nrf_cmd(0x20, 0x12); //on, no crc, int on RX/TX done : write register 0x00 (config) + nrf_cmd(0x21, 0x00); //no auto-acknowledge : write register 0x01 (autoack) + nrf_cmd(0x22, 0x00); //no RX : write register 0x02 (enabled rx pipes) + nrf_cmd(0x23, 0x02); //4-byte address : write register 0x03 (config addr width: 0b11 == 4 byte) + nrf_cmd(0x24, 0x00); //no auto-retransmit : write register 0x04 (auto retrans: off) + nrf_cmd(0x26, 0x06); //1MBps at 0dBm : write register 0x06 (rf setup 0x110 == 0dBm xmit) + nrf_cmd(0x27, 0x3E); //clear various flags : write register 0x07 + nrf_cmd(0x3C, 0x00); //no dynamic payloads : write register 0x1c (enable dynamic payload: all disabled) + nrf_cmd(0x3D, 0x00); //no features : write register 0x1d (features: none) + nrf_cmd(0x31, 32); //always RX 32 bytes : write register 0x11 (rx max size: 32 is max) + nrf_cmd(0x22, 0x01); //RX on pipe 0 : write register 0x02 (enable rx pipes: enable pipe 0) + + // 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; // : write register 0x10 (tx addr: expects <=5 bytes) + buf[1] = swapbits(0x8E); + buf[2] = swapbits(0x89); + buf[3] = swapbits(0xBE); + buf[4] = swapbits(0xD6); + nrf_manybytes(buf, 5); + // set RX address in nRF24L01, doesn't matter because RX is ignored in this case + buf[0] = 0x2A; // : write register 0x0A (rx addr) + nrf_manybytes(buf, 5); +} + +void CBTLE::begin(int pinCSN, int pinCE) +{ + SPI.begin(); + SPI.setBitOrder(MSBFIRST); + + pinMode(pinCSN, OUTPUT); + pinMode(pinCE, OUTPUT); + digitalWrite(pinCSN, HIGH); + digitalWrite(pinCE, LOW); + + nrf_init(); +} + +// Converts a temperature value in 100ths degrees C into a nRF float (4 bytes) +btle_float_t CBTLE::nrf_float(float t) +{ + const int32_t exponent = -2; + return static_cast(((exponent & 0xff) << 24) | (((int32_t)(t * 100)) & 0x00ffffff)); +} + +unsigned int CBTLE::mkpacket(uint8_t *buf, unsigned int size, float val) +{ + unsigned int ndx = 0; + btle_float_t t; + + buf[ndx++] = 0x42; // PDU type, given address is random; 0x42 for Android and 0x40 for iPhone + buf[ndx++] = 24; // length of payload + + buf[ndx++] = MY_MAC_0; + buf[ndx++] = MY_MAC_1; + buf[ndx++] = MY_MAC_2; + buf[ndx++] = MY_MAC_3; + buf[ndx++] = MY_MAC_4; + buf[ndx++] = MY_MAC_5; + + /* device descriptor chunk */ + buf[ndx++] = 2; /* chunk size 2 bytes */ + buf[ndx++] = 0x01; /* chunk type: device flags */ + buf[ndx++] = 0x05; /* data: 0x05 == LE only, limited discovery mode */ + + /* name chunk */ + buf[ndx++] = 6; /* chunk size: 7 bytes */ + buf[ndx++] = 0x09; /* chunk type: complete name */ + buf[ndx++] = 'n'; + buf[ndx++] = 'R'; + buf[ndx++] = 'F'; + buf[ndx++] = '2'; + buf[ndx++] = '4'; + + buf[ndx++] = 7; + buf[ndx++] = 0x16; + buf[ndx++] = (uint8_t)(NRF_TEMPERATURE_SERVICE_UUID); + buf[ndx++] = (uint8_t)((NRF_TEMPERATURE_SERVICE_UUID >> 8) & 0xff); + t = nrf_float(val); + memcpy(&buf[ndx], &t, 4); + ndx += 4; + + buf[ndx++] = 0x55; //CRC start value: 0x555555 + buf[ndx++] = 0x55; + buf[ndx++] = 0x55; + return ndx; +} + +void CBTLE::announce(unsigned int channel_index, uint8_t *data, unsigned int len) +{ + static const uint8_t chRf[BTLE_NUM_CHANNELS] = {2, 26,80}; + static const uint8_t chLe[BTLE_NUM_CHANNELS] = {37,38,39}; + unsigned int n; + + nrf_cmd(0x25, chRf[channel_index]); + nrf_cmd(0x27, 0x6E); // Clear flags + + btLePacketEncode(data, len, chLe[channel_index]); + + nrf_simplebyte(0xE2); //Clear RX Fifo + nrf_simplebyte(0xE1); //Clear TX Fifo + + digitalWrite(PIN_CSN, LOW); + spi_byte(0xA0); + for (n = 0 ; n < len ; n++) + spi_byte(data[n]); + 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) +} diff --git a/BLE24.h b/BLE24.h new file mode 100644 index 0000000..c6dcd26 --- /dev/null +++ b/BLE24.h @@ -0,0 +1,36 @@ +#ifndef _BTLE23_h_INCLUDE +#define _BTLE23_h_INCLUDE + +#include +#include + +#define PIN_CE 8 // chip enable +#define PIN_CSN 10 // chip select (for SPI) + +// 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 + +#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 + +#define BTLE_BUFFER_SIZE 32 +#define BTLE_NUM_CHANNELS 3 +typedef int32_t btle_float_t; + +class CBTLE +{ +public: + void begin(int pinCE, int pinCSN); + void end() {} + btle_float_t nrf_float(float val); + unsigned int mkpacket(uint8_t *buf, unsigned int size, float val); + void announce(unsigned int channel_index, uint8_t *data, unsigned int len); +}; + +#endif diff --git a/nRF24_BLE_Temperature.cppproj b/nRF24_BLE_Temperature.cppproj new file mode 100644 index 0000000..e8117d0 --- /dev/null +++ b/nRF24_BLE_Temperature.cppproj @@ -0,0 +1,656 @@ + + + + 2.0 + 6.2 + com.Atmel.AVRGCC8.CPP + {f0db6327-9b78-4838-8341-d7f74af011b7} + atmega328p + none + Executable + CPP + $(MSBuildProjectName) + .elf + $(MSBuildProjectDirectory)\$(Configuration) + nRF24_BLE_Temperature + nRF24_BLE_Temperature + nRF24_BLE_Temperature + Native + true + false + exception_table + 0 + true + 0x20000000 + true + + 0 + + + + + + + + + + + + true + com.atmel.avrdbg.tool.atmelice + + + + 2000000 + + ISP + + com.atmel.avrdbg.tool.atmelice + J41800030372 + Atmel-ICE + + ISP + + + + + True + True + True + True + False + True + True + + + __AVR_ATmega328p__ + __AVR_ATmega328P__ + ARDUINO=165 + ARDUINO_MAIN + F_CPU=20000000L + __AVR__ + ARDUINO_BARE + ARDUINO_ARCH_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/tools/avr//avr/include/avr/ + C:/opt/arduino-1.6.5-r2/hardware/tools/avr/avr/include/ + c:/Code/arduino/libraries + C:/Program Files (x86)/Visual Micro/Visual Micro for Arduino/Micro Platforms/default/debuggers + c:/Code/arduino/hardware/Custom/avr/libraries + C:/Users/pt111992/AppData/Roaming/arduino15/packages/arduino/hardware/avr/1.6.8/libraries + C:/opt/arduino-1.6.5-r2/libraries + C:/Users/pt111992/AppData/Roaming/arduino15/packages/arduino/hardware/avr/1.6.8/libraries/SPI/utility + C:/Users/pt111992/AppData/Roaming/arduino15/packages/arduino/hardware/avr/1.6.8/libraries/SPI + c:/Code/arduino/libraries/OneWire/utility + c:/Code/arduino/libraries/OneWire + c:/Code/arduino/libraries/LiquidCrystal/utility + c:/Code/arduino/libraries/LiquidCrystal + c:/Code/arduino/libraries/DallasTemperature/utility + c:/Code/arduino/libraries/DallasTemperature + ../../nRF24_BLE_Temperature + C:/opt/arduino-1.6.5-r2/hardware/arduino/avr/variants/eightanaloginputs + C:/opt/arduino-1.6.5-r2/hardware/arduino/avr/cores/arduino + + + Optimize (-O1) + True + True + Default (-g2) + True + True + True + + + __AVR_ATmega328p__ + __AVR_ATmega328P__ + ARDUINO=165 + ARDUINO_MAIN + F_CPU=20000000L + __AVR__ + ARDUINO_BARE + ARDUINO_ARCH_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/tools/avr//avr/include/avr/ + C:/opt/arduino-1.6.5-r2/hardware/tools/avr/avr/include/ + c:/Code/arduino/libraries + C:/Program Files (x86)/Visual Micro/Visual Micro for Arduino/Micro Platforms/default/debuggers + c:/Code/arduino/hardware/Custom/avr/libraries + C:/Users/pt111992/AppData/Roaming/arduino15/packages/arduino/hardware/avr/1.6.8/libraries + C:/opt/arduino-1.6.5-r2/libraries + C:/Users/pt111992/AppData/Roaming/arduino15/packages/arduino/hardware/avr/1.6.8/libraries/SPI/utility + C:/Users/pt111992/AppData/Roaming/arduino15/packages/arduino/hardware/avr/1.6.8/libraries/SPI + c:/Code/arduino/libraries/OneWire/utility + c:/Code/arduino/libraries/OneWire + c:/Code/arduino/libraries/LiquidCrystal/utility + c:/Code/arduino/libraries/LiquidCrystal + c:/Code/arduino/libraries/DallasTemperature/utility + c:/Code/arduino/libraries/DallasTemperature + ../../nRF24_BLE_Temperature + C:/opt/arduino-1.6.5-r2/hardware/arduino/avr/variants/eightanaloginputs + C:/opt/arduino-1.6.5-r2/hardware/arduino/avr/cores/arduino + + + Optimize (-O1) + True + True + Default (-g2) + True + Default (-Wa,-g) + + + 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; + + + bare_20MHzatmega328 + Bare Arduino-style boards w/ ATmega328 (5V, 20 MHz) + name=Bare Arduino-style boards w/ ATmega328 (5V, 20 MHz) +upload.tool=avrdude +upload.protocol=arduino +bootloader.tool=arduino:avrdude +bootloader.unlock_bits=0x3F +bootloader.lock_bits=0x0F +build.board=BARE +build.core=arduino:arduino +build.variant=arduino:eightanaloginputs +menu.cpu.16MHzatmega328=ATmega328 (5V, 16 MHz) +menu.cpu.16MHzatmega328.upload.maximum_size=30720 +menu.cpu.16MHzatmega328.upload.maximum_data_size=2048 +menu.cpu.16MHzatmega328.upload.speed=57600 +menu.cpu.16MHzatmega328.bootloader.low_fuses=0xFF +menu.cpu.16MHzatmega328.bootloader.high_fuses=0xDA +menu.cpu.16MHzatmega328.bootloader.extended_fuses=0x05 +menu.cpu.16MHzatmega328.bootloader.file=atmega/ATmegaBOOT_168_atmega328.hex +menu.cpu.16MHzatmega328.build.mcu=atmega328p +menu.cpu.16MHzatmega328.build.f_cpu=16000000L +menu.cpu.20MHzatmega328=ATmega328 (5V, 20 MHz) +menu.cpu.20MHzatmega328.upload.maximum_size=30720 +menu.cpu.20MHzatmega328.upload.maximum_data_size=2048 +menu.cpu.20MHzatmega328.upload.speed=57600 +menu.cpu.20MHzatmega328.bootloader.low_fuses=0xF7 +menu.cpu.20MHzatmega328.bootloader.high_fuses=0xDA +menu.cpu.20MHzatmega328.bootloader.extended_fuses=0x05 +menu.cpu.20MHzatmega328.bootloader.file=atmega/ATmegaBOOT_168_atmega328.hex +menu.cpu.20MHzatmega328.build.mcu=atmega328p +menu.cpu.20MHzatmega328.build.f_cpu=20000000L +menu.cpu.8MHzatmega328=ATmega328 (3.3V, 8 MHz) +menu.cpu.8MHzatmega328.upload.maximum_size=30720 +menu.cpu.8MHzatmega328.upload.maximum_data_size=2048 +menu.cpu.8MHzatmega328.upload.speed=57600 +menu.cpu.8MHzatmega328.bootloader.low_fuses=0xFF +menu.cpu.8MHzatmega328.bootloader.high_fuses=0xDA +menu.cpu.8MHzatmega328.bootloader.extended_fuses=0x05 +menu.cpu.8MHzatmega328.bootloader.file=atmega/ATmegaBOOT_168_atmega328_pro_8MHz.hex +menu.cpu.8MHzatmega328.build.mcu=atmega328p +menu.cpu.8MHzatmega328.build.f_cpu=8000000L +runtime.ide.path=C:\opt\arduino-1.6.5-r2 +build.system.path=c:\Code\arduino\hardware\Custom\avr\system +runtime.ide.version=165 +target_package=Custom +target_platform=avr +runtime.hardware.path=c:\Code\arduino\hardware\Custom +originalid=bare +intellisense.tools.path={runtime.tools.avr-gcc.path}/ +intellisense.include.paths={intellisense.tools.path}avr/include/;{intellisense.tools.path}/avr/include/avr/;{intellisense.tools.path}lib\gcc\avr\4.8.1\include +tools.atprogram.cmd.path=%AVRSTUDIO_EXE_PATH%\atbackend\atprogram +tools.atprogram.cmd.setwinpath=true +tools.atprogram.program.params.verbose=-v +tools.atprogram.program.params.quiet=-q +tools.atprogram.program.pattern="{cmd.path}" -d {build.mcu} {program.verbose} {program.extra_params} program -c -f "{build.path}\{build.project_name}.hex" +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" +version=1.0.0 +compiler.warning_flags=-w +compiler.warning_flags.none=-w +compiler.warning_flags.default= +compiler.warning_flags.more=-Wall +compiler.warning_flags.all=-Wall -Wextra +compiler.path={runtime.tools.avr-gcc.path}/bin/ +compiler.c.cmd=avr-gcc +compiler.c.flags=-c -g -Os {compiler.warning_flags} -ffunction-sections -fdata-sections -MMD +compiler.c.elf.flags={compiler.warning_flags} -Os -Wl,--gc-sections +compiler.c.elf.cmd=avr-gcc +compiler.S.flags=-c -g -x assembler-with-cpp +compiler.cpp.cmd=avr-g++ +compiler.cpp.flags=-c -g -Os {compiler.warning_flags} -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD +compiler.ar.cmd=avr-ar +compiler.ar.flags=rcs +compiler.objcopy.cmd=avr-objcopy +compiler.objcopy.eep.flags=-O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 +compiler.elf2hex.flags=-O ihex -R .eeprom +compiler.elf2hex.cmd=avr-objcopy +compiler.ldflags= +compiler.size.cmd=avr-size +build.extra_flags= +compiler.c.extra_flags= +compiler.c.elf.extra_flags= +compiler.S.extra_flags= +compiler.cpp.extra_flags= +compiler.ar.extra_flags= +compiler.objcopy.eep.extra_flags= +compiler.elf2hex.extra_flags= +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}" +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}" +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}" +recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{build.path}/{archive_file}" "{object_file}" +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 +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" +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" +recipe.output.tmp_file={build.project_name}.hex +recipe.output.save_file={build.project_name}.{build.variant}.hex +recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/{build.project_name}.elf" +recipe.size.regex=^(?:\.text|\.data|\.bootloader)\s+([0-9]+).* +recipe.size.regex.data=^(?:\.data|\.bss|\.noinit)\s+([0-9]+).* +recipe.size.regex.eeprom=^(?:\.eeprom)\s+([0-9]+).* +tools.avrdude.path={runtime.tools.avrdude.path} +tools.avrdude.cmd.path={path}/bin/avrdude +tools.avrdude.config.path={path}/etc/avrdude.conf +tools.avrdude.upload.params.verbose=-v +tools.avrdude.upload.params.quiet=-q -q +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" +tools.avrdude.program.params.verbose=-v +tools.avrdude.program.params.quiet=-q -q +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" +tools.avrdude.erase.params.verbose=-v +tools.avrdude.erase.params.quiet=-q -q +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 +tools.avrdude.bootloader.params.verbose=-v +tools.avrdude.bootloader.params.quiet=-q -q +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 +build.usb_manufacturer="Unknown" +build.usb_flags=-DUSB_VID={build.vid} -DUSB_PID={build.pid} '-DUSB_MANUFACTURER={build.usb_manufacturer}' '-DUSB_PRODUCT={build.usb_product}' +vm.platform.root.path=C:\Program Files (x86)\Visual Micro\Visual Micro for Arduino\Micro Platforms\arduino16x +runtime.tools.arm-none-eabi-gcc.path=C:\Users\pt111992\AppData\Roaming\arduino15\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1 +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 +runtime.tools.avrdude.path=C:\opt\arduino-1.6.5-r2\hardware\tools\avr +runtime.tools.avrdude-6.0.1-arduino5.path=C:\opt\arduino-1.6.5-r2\hardware\tools\avr +runtime.tools.avr-gcc.path=C:\opt\arduino-1.6.5-r2\hardware\tools\avr +runtime.tools.avr-gcc-4.8.1-arduino5.path=C:\opt\arduino-1.6.5-r2\hardware\tools\avr +runtime.tools.bossac.path=C:\Users\pt111992\AppData\Roaming\arduino15\packages\arduino\tools\bossac\1.6-arduino +runtime.tools.bossac-1.6-arduino.path=C:\Users\pt111992\AppData\Roaming\arduino15\packages\arduino\tools\bossac\1.6-arduino +runtime.tools.CMSIS.path=C:\Users\pt111992\AppData\Roaming\arduino15\packages\arduino\tools\CMSIS\4.0.0-atmel +runtime.tools.CMSIS-4.0.0-atmel.path=C:\Users\pt111992\AppData\Roaming\arduino15\packages\arduino\tools\CMSIS\4.0.0-atmel +runtime.tools.openocd.path=C:\Users\pt111992\AppData\Roaming\arduino15\packages\arduino\tools\openocd\0.9.0-arduino +runtime.tools.openocd-0.9.0-arduino.path=C:\Users\pt111992\AppData\Roaming\arduino15\packages\arduino\tools\openocd\0.9.0-arduino +upload.maximum_size=30720 +upload.maximum_data_size=2048 +upload.speed=57600 +bootloader.low_fuses=0xF7 +bootloader.high_fuses=0xDA +bootloader.extended_fuses=0x05 +bootloader.file=atmega/ATmegaBOOT_168_atmega328.hex +build.mcu=atmega328p +build.f_cpu=20000000L +ide.hint=Arduino 1.6.x ide with support for downloaded Board Manager custom tools and hardware +ide.location.key=Arduino16x +ide.location.ide.winreg=Arduino 1.6.x Application +ide.location.sketchbook.winreg=Arduino 1.6.x Sketchbook +ide.location.sketchbook.preferences=sketchbook.path +ide.default.version=160 +ide.default.package=arduino +ide.default.platform=avr +ide.multiplatform=true +ide.includes=arduino.h +ide.exe_name=arduino +ide.platformswithoutpackage=false +ide.includes.fallback=wprogram.h +ide.extension=ino +ide.extension.fallback=pde +ide.versionGTEQ=160 +ide.exe=arduino.exe +ide.hosts=atmel +ide.url=http://arduino.cc/en/Main/Software +ide.help.reference.path=reference\arduino.cc\en\Reference +vm.debug=true +software=ARDUINO +ssh.user.name=root +ssh.user.default.password=arduino +ssh.host.wwwfiles.path=/www/sd +build.working_directory={runtime.ide.path} +ide.location.preferences.portable={runtime.ide.path}\portable +ide.location.preferences=%VM_APPDATA_ROAMING%\arduino15\preferences.txt +ide.location.preferences_fallback=%VM_APPDATA_LOCAL%\arduino15\preferences.txt +ide.location.contributions=%VM_APPDATA_LOCAL%\arduino15 +ide.location.contributions_fallback=%VM_APPDATA_ROAMING%\arduino15 +ide.contributions.boards.allow=true +ide.contributions.boards.ignore_unless_rewrite_found=true +ide.contributions.libraries.allow=true +ide.contributions.boards.support.urls.wiki=https://github.com/arduino/Arduino/wiki/Unofficial-list-of-3rd-party-boards-support-urls +ide.appid=arduino16x +location.sketchbook=c:\Code\arduino +vm.core.include=arduino.h +vm.boardsource.path=c:\Code\arduino\hardware\Custom\avr +runtime.platform.path=c:\Code\arduino\hardware\Custom\avr +vm.platformname.name=avr +build.arch=AVR + + atmega328p + 20000000L + arduino + arduino + 57600 + 30720 + arduino16x + Custom + avr + + + + + + + True + True + True + True + False + True + True + + + __AVR_ATmega328p__ + __AVR_ATmega328P__ + ARDUINO=165 + ARDUINO_MAIN + F_CPU=20000000L + __AVR__ + ARDUINO_BARE + ARDUINO_ARCH_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/tools/avr//avr/include/avr/ + C:/opt/arduino-1.6.5-r2/hardware/tools/avr/avr/include/ + c:/Code/arduino/libraries + C:/Program Files (x86)/Visual Micro/Visual Micro for Arduino/Micro Platforms/default/debuggers + c:/Code/arduino/hardware/Custom/avr/libraries + C:/Users/pt111992/AppData/Roaming/arduino15/packages/arduino/hardware/avr/1.6.8/libraries + C:/opt/arduino-1.6.5-r2/libraries + C:/Users/pt111992/AppData/Roaming/arduino15/packages/arduino/hardware/avr/1.6.8/libraries/SPI/utility + C:/Users/pt111992/AppData/Roaming/arduino15/packages/arduino/hardware/avr/1.6.8/libraries/SPI + c:/Code/arduino/libraries/OneWire/utility + c:/Code/arduino/libraries/OneWire + c:/Code/arduino/libraries/LiquidCrystal/utility + c:/Code/arduino/libraries/LiquidCrystal + c:/Code/arduino/libraries/DallasTemperature/utility + c:/Code/arduino/libraries/DallasTemperature + ../../nRF24_BLE_Temperature + C:/opt/arduino-1.6.5-r2/hardware/arduino/avr/variants/eightanaloginputs + C:/opt/arduino-1.6.5-r2/hardware/arduino/avr/cores/arduino + + + Optimize (-O1) + True + True + Default (-g2) + True + True + True + + + __AVR_ATmega328p__ + __AVR_ATmega328P__ + ARDUINO=165 + ARDUINO_MAIN + F_CPU=20000000L + __AVR__ + ARDUINO_BARE + ARDUINO_ARCH_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/tools/avr//avr/include/avr/ + C:/opt/arduino-1.6.5-r2/hardware/tools/avr/avr/include/ + c:/Code/arduino/libraries + C:/Program Files (x86)/Visual Micro/Visual Micro for Arduino/Micro Platforms/default/debuggers + c:/Code/arduino/hardware/Custom/avr/libraries + C:/Users/pt111992/AppData/Roaming/arduino15/packages/arduino/hardware/avr/1.6.8/libraries + C:/opt/arduino-1.6.5-r2/libraries + C:/Users/pt111992/AppData/Roaming/arduino15/packages/arduino/hardware/avr/1.6.8/libraries/SPI/utility + C:/Users/pt111992/AppData/Roaming/arduino15/packages/arduino/hardware/avr/1.6.8/libraries/SPI + c:/Code/arduino/libraries/OneWire/utility + c:/Code/arduino/libraries/OneWire + c:/Code/arduino/libraries/LiquidCrystal/utility + c:/Code/arduino/libraries/LiquidCrystal + c:/Code/arduino/libraries/DallasTemperature/utility + c:/Code/arduino/libraries/DallasTemperature + ../../nRF24_BLE_Temperature + C:/opt/arduino-1.6.5-r2/hardware/arduino/avr/variants/eightanaloginputs + C:/opt/arduino-1.6.5-r2/hardware/arduino/avr/cores/arduino + + + Optimize (-O1) + True + True + Default (-g2) + True + Default (-Wa,-g) + + + 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; + + + bare_20MHzatmega328 + Bare Arduino-style boards w/ ATmega328 (5V, 20 MHz) + name=Bare Arduino-style boards w/ ATmega328 (5V, 20 MHz) +upload.tool=avrdude +upload.protocol=arduino +bootloader.tool=arduino:avrdude +bootloader.unlock_bits=0x3F +bootloader.lock_bits=0x0F +build.board=BARE +build.core=arduino:arduino +build.variant=arduino:eightanaloginputs +menu.cpu.16MHzatmega328=ATmega328 (5V, 16 MHz) +menu.cpu.16MHzatmega328.upload.maximum_size=30720 +menu.cpu.16MHzatmega328.upload.maximum_data_size=2048 +menu.cpu.16MHzatmega328.upload.speed=57600 +menu.cpu.16MHzatmega328.bootloader.low_fuses=0xFF +menu.cpu.16MHzatmega328.bootloader.high_fuses=0xDA +menu.cpu.16MHzatmega328.bootloader.extended_fuses=0x05 +menu.cpu.16MHzatmega328.bootloader.file=atmega/ATmegaBOOT_168_atmega328.hex +menu.cpu.16MHzatmega328.build.mcu=atmega328p +menu.cpu.16MHzatmega328.build.f_cpu=16000000L +menu.cpu.20MHzatmega328=ATmega328 (5V, 20 MHz) +menu.cpu.20MHzatmega328.upload.maximum_size=30720 +menu.cpu.20MHzatmega328.upload.maximum_data_size=2048 +menu.cpu.20MHzatmega328.upload.speed=57600 +menu.cpu.20MHzatmega328.bootloader.low_fuses=0xF7 +menu.cpu.20MHzatmega328.bootloader.high_fuses=0xDA +menu.cpu.20MHzatmega328.bootloader.extended_fuses=0x05 +menu.cpu.20MHzatmega328.bootloader.file=atmega/ATmegaBOOT_168_atmega328.hex +menu.cpu.20MHzatmega328.build.mcu=atmega328p +menu.cpu.20MHzatmega328.build.f_cpu=20000000L +menu.cpu.8MHzatmega328=ATmega328 (3.3V, 8 MHz) +menu.cpu.8MHzatmega328.upload.maximum_size=30720 +menu.cpu.8MHzatmega328.upload.maximum_data_size=2048 +menu.cpu.8MHzatmega328.upload.speed=57600 +menu.cpu.8MHzatmega328.bootloader.low_fuses=0xFF +menu.cpu.8MHzatmega328.bootloader.high_fuses=0xDA +menu.cpu.8MHzatmega328.bootloader.extended_fuses=0x05 +menu.cpu.8MHzatmega328.bootloader.file=atmega/ATmegaBOOT_168_atmega328_pro_8MHz.hex +menu.cpu.8MHzatmega328.build.mcu=atmega328p +menu.cpu.8MHzatmega328.build.f_cpu=8000000L +runtime.ide.path=C:\opt\arduino-1.6.5-r2 +build.system.path=c:\Code\arduino\hardware\Custom\avr\system +runtime.ide.version=165 +target_package=Custom +target_platform=avr +runtime.hardware.path=c:\Code\arduino\hardware\Custom +originalid=bare +intellisense.tools.path={runtime.tools.avr-gcc.path}/ +intellisense.include.paths={intellisense.tools.path}avr/include/;{intellisense.tools.path}/avr/include/avr/;{intellisense.tools.path}lib\gcc\avr\4.8.1\include +tools.atprogram.cmd.path=%AVRSTUDIO_EXE_PATH%\atbackend\atprogram +tools.atprogram.cmd.setwinpath=true +tools.atprogram.program.params.verbose=-v +tools.atprogram.program.params.quiet=-q +tools.atprogram.program.pattern="{cmd.path}" -d {build.mcu} {program.verbose} {program.extra_params} program -c -f "{build.path}\{build.project_name}.hex" +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" +version=1.0.0 +compiler.warning_flags=-w +compiler.warning_flags.none=-w +compiler.warning_flags.default= +compiler.warning_flags.more=-Wall +compiler.warning_flags.all=-Wall -Wextra +compiler.path={runtime.tools.avr-gcc.path}/bin/ +compiler.c.cmd=avr-gcc +compiler.c.flags=-c -g -Os {compiler.warning_flags} -ffunction-sections -fdata-sections -MMD +compiler.c.elf.flags={compiler.warning_flags} -Os -Wl,--gc-sections +compiler.c.elf.cmd=avr-gcc +compiler.S.flags=-c -g -x assembler-with-cpp +compiler.cpp.cmd=avr-g++ +compiler.cpp.flags=-c -g -Os {compiler.warning_flags} -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD +compiler.ar.cmd=avr-ar +compiler.ar.flags=rcs +compiler.objcopy.cmd=avr-objcopy +compiler.objcopy.eep.flags=-O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 +compiler.elf2hex.flags=-O ihex -R .eeprom +compiler.elf2hex.cmd=avr-objcopy +compiler.ldflags= +compiler.size.cmd=avr-size +build.extra_flags= +compiler.c.extra_flags= +compiler.c.elf.extra_flags= +compiler.S.extra_flags= +compiler.cpp.extra_flags= +compiler.ar.extra_flags= +compiler.objcopy.eep.extra_flags= +compiler.elf2hex.extra_flags= +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}" +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}" +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}" +recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{build.path}/{archive_file}" "{object_file}" +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 +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" +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" +recipe.output.tmp_file={build.project_name}.hex +recipe.output.save_file={build.project_name}.{build.variant}.hex +recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/{build.project_name}.elf" +recipe.size.regex=^(?:\.text|\.data|\.bootloader)\s+([0-9]+).* +recipe.size.regex.data=^(?:\.data|\.bss|\.noinit)\s+([0-9]+).* +recipe.size.regex.eeprom=^(?:\.eeprom)\s+([0-9]+).* +tools.avrdude.path={runtime.tools.avrdude.path} +tools.avrdude.cmd.path={path}/bin/avrdude +tools.avrdude.config.path={path}/etc/avrdude.conf +tools.avrdude.upload.params.verbose=-v +tools.avrdude.upload.params.quiet=-q -q +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" +tools.avrdude.program.params.verbose=-v +tools.avrdude.program.params.quiet=-q -q +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" +tools.avrdude.erase.params.verbose=-v +tools.avrdude.erase.params.quiet=-q -q +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 +tools.avrdude.bootloader.params.verbose=-v +tools.avrdude.bootloader.params.quiet=-q -q +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 +build.usb_manufacturer="Unknown" +build.usb_flags=-DUSB_VID={build.vid} -DUSB_PID={build.pid} '-DUSB_MANUFACTURER={build.usb_manufacturer}' '-DUSB_PRODUCT={build.usb_product}' +vm.platform.root.path=C:\Program Files (x86)\Visual Micro\Visual Micro for Arduino\Micro Platforms\arduino16x +runtime.tools.arm-none-eabi-gcc.path=C:\Users\pt111992\AppData\Roaming\arduino15\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1 +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 +runtime.tools.avrdude.path=C:\opt\arduino-1.6.5-r2\hardware\tools\avr +runtime.tools.avrdude-6.0.1-arduino5.path=C:\opt\arduino-1.6.5-r2\hardware\tools\avr +runtime.tools.avr-gcc.path=C:\opt\arduino-1.6.5-r2\hardware\tools\avr +runtime.tools.avr-gcc-4.8.1-arduino5.path=C:\opt\arduino-1.6.5-r2\hardware\tools\avr +runtime.tools.bossac.path=C:\Users\pt111992\AppData\Roaming\arduino15\packages\arduino\tools\bossac\1.6-arduino +runtime.tools.bossac-1.6-arduino.path=C:\Users\pt111992\AppData\Roaming\arduino15\packages\arduino\tools\bossac\1.6-arduino +runtime.tools.CMSIS.path=C:\Users\pt111992\AppData\Roaming\arduino15\packages\arduino\tools\CMSIS\4.0.0-atmel +runtime.tools.CMSIS-4.0.0-atmel.path=C:\Users\pt111992\AppData\Roaming\arduino15\packages\arduino\tools\CMSIS\4.0.0-atmel +runtime.tools.openocd.path=C:\Users\pt111992\AppData\Roaming\arduino15\packages\arduino\tools\openocd\0.9.0-arduino +runtime.tools.openocd-0.9.0-arduino.path=C:\Users\pt111992\AppData\Roaming\arduino15\packages\arduino\tools\openocd\0.9.0-arduino +upload.maximum_size=30720 +upload.maximum_data_size=2048 +upload.speed=57600 +bootloader.low_fuses=0xF7 +bootloader.high_fuses=0xDA +bootloader.extended_fuses=0x05 +bootloader.file=atmega/ATmegaBOOT_168_atmega328.hex +build.mcu=atmega328p +build.f_cpu=20000000L +ide.hint=Arduino 1.6.x ide with support for downloaded Board Manager custom tools and hardware +ide.location.key=Arduino16x +ide.location.ide.winreg=Arduino 1.6.x Application +ide.location.sketchbook.winreg=Arduino 1.6.x Sketchbook +ide.location.sketchbook.preferences=sketchbook.path +ide.default.version=160 +ide.default.package=arduino +ide.default.platform=avr +ide.multiplatform=true +ide.includes=arduino.h +ide.exe_name=arduino +ide.platformswithoutpackage=false +ide.includes.fallback=wprogram.h +ide.extension=ino +ide.extension.fallback=pde +ide.versionGTEQ=160 +ide.exe=arduino.exe +ide.hosts=atmel +ide.url=http://arduino.cc/en/Main/Software +ide.help.reference.path=reference\arduino.cc\en\Reference +vm.debug=true +software=ARDUINO +ssh.user.name=root +ssh.user.default.password=arduino +ssh.host.wwwfiles.path=/www/sd +build.working_directory={runtime.ide.path} +ide.location.preferences.portable={runtime.ide.path}\portable +ide.location.preferences=%VM_APPDATA_ROAMING%\arduino15\preferences.txt +ide.location.preferences_fallback=%VM_APPDATA_LOCAL%\arduino15\preferences.txt +ide.location.contributions=%VM_APPDATA_LOCAL%\arduino15 +ide.location.contributions_fallback=%VM_APPDATA_ROAMING%\arduino15 +ide.contributions.boards.allow=true +ide.contributions.boards.ignore_unless_rewrite_found=true +ide.contributions.libraries.allow=true +ide.contributions.boards.support.urls.wiki=https://github.com/arduino/Arduino/wiki/Unofficial-list-of-3rd-party-boards-support-urls +ide.appid=arduino16x +location.sketchbook=c:\Code\arduino +vm.core.include=arduino.h +vm.boardsource.path=c:\Code\arduino\hardware\Custom\avr +runtime.platform.path=c:\Code\arduino\hardware\Custom\avr +vm.platformname.name=avr +build.arch=AVR + + atmega328p + 20000000L + arduino + arduino + 57600 + 30720 + arduino16x + Custom + avr + + + + + + compile + + + + + + + + compile + + + compile + + + compile + + + + \ No newline at end of file diff --git a/nRF24_BLE_Temperature.ino b/nRF24_BLE_Temperature.ino index 047ab18..88e6b8b 100644 --- a/nRF24_BLE_Temperature.ino +++ b/nRF24_BLE_Temperature.ino @@ -3,277 +3,242 @@ #include #include #include -#include - -#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 +#include +#include +#include "BLE24.h" + +static void I2C_Init(); +static void LCD_Init(); +static void RTC_Init(); +static void Radio_Init(); +static void DS18B20_Init(); +static void PrintAddress(Print *stream, DeviceAddress address); + +#define RADIO_CE_PIN 8 +#define RADIO_CHANNEL 85 #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 + +#define SENSOR_HUB_ADDRESS 1 +#define DEVICE_ADDRESS 2 + +#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 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); +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() +{ + if (Radio.init()) + { + Radio.setThisAddress(DEVICE_ADDRESS); + if (nrf24.setChannel(RADIO_CHANNEL)) + { + UseRadio = true; + Serial.println(F("Radio initialized")); + } + else + { + Serial.println(F("Radio: failed to select channel")); + } + } + else + { + Serial.println(F("Radio initialization failed")); + } +} + +static void Radio_End() +{ + +} + +static void Radio_Send(uint8_t *data, uint8_t len) +{ + if (UseRadio) + { + nrf24.setModeTx(); + if (!Radio.sendto(data, len, SENSOR_HUB_ADDRESS)) + { + Serial.println(F("Radio: failed to send")); + } + //if (!nrf24.sleep()) + // Serial.println(F("Radio: failed to enter sleep mode")); + } +} + +// Find any 1-wire sensors and use the first one. Trigger an async conversion. +static void OneWire_Init() +{ + Serial.println(F("Initializing OneWire bus...")); + w1sensors.begin(); + w1sensors.setResolution(12); + w1sensors.setWaitForConversion(false); + int count = w1sensors.getDeviceCount(); + for (int n = 0; n < count; ++n) + { + if (w1sensors.getAddress(w1sensorAddress, n)) + { + Serial.print(n); + Serial.print(F(": ")); + PrintAddress(&Serial, w1sensorAddress); + Serial.println(); + UseOneWire = true; + w1sensors.requestTemperatures(); + } + } +} + +static void PrintAddress(Print *stream, DeviceAddress address) +{ + for (int n = 0; n < 8; ++n) + { + if (address[n] < 16) + stream->print('0'); + stream->print(address[n], HEX); + } +} + +static void I2C_Init() +{ + for (uint8_t addr = 0; addr < 127; ++addr) + { + Wire.beginTransmission(addr); + uint8_t err = Wire.endTransmission(); + if (err == 0) + { + Serial.print(F("# Found I2C device at 0x")); + if (addr < 16) Serial.print('0'); + Serial.print(addr, HEX); + if (addr == 0x20) { Serial.print(F(" (LCD)")); UseLCDDisplay = true; } + if (addr == 0x22) { Serial.print(F(" (LED)")); /*UseLedDisplay = true;*/ } + if (addr == 0x57) { Serial.print(F(" (EEPROM)")); } + if (addr == 0x68) { Serial.print(F(" (RTC)")); /* UseRTC = true; */} + Serial.println(); + } + else if (err == 4) + { + Serial.print(F("# Unknown error at address 0x")); + if (addr < 16) Serial.print('0'); + Serial.print(addr, HEX); + } + } +} + +static void LCD_Init() +{ + if (UseLCDDisplay) + { + lcd.begin(16, 2); + lcd.clear(); + lcd.print(F("BTLE Beacon")); + } +} + +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); +} static void UpdateDisplay() { - lcd.setCursor(0, 1); - lcd.print(currentTemperature); - lcd.print((char)0xdf); + lcd.home(); + lcd.print(currentTemperature); + lcd.print((char)0xdf); lcd.print("C "); lcd.print(static_cast(GetHumidity())/1000.0f); lcd.print(" RH"); + lcd.setCursor(0, 1); + lcd.print("BTLE Beacon: "); + 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 *)¤tTemperature, 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> 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]; + 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) + { + BTLE.announce(channel_index, btle_packet, btle_packet_len); + } + btle_time = millis() - start; + + 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; -- 2.23.0