Created
April 8, 2014 18:03
-
-
Save spirilis/10164288 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Enrf24.h> | |
#include <nRF24L01.h> | |
#include <SPI.h> | |
// Parameters | |
#define RADIO_CHANNEL 10 | |
#define RADIO_SPEED 250000 | |
#define DEVICE_ID 0x08 | |
#define SLEEP_INTERVAL 120 // seconds | |
Enrf24 radio(4, 5, 6); // CE, CSN, IRQ | |
const uint8_t unused_pins[] = {P1_0, P1_1, P2_0, P2_1, P2_2, P2_3, P2_4, P2_5, P2_7, 0}; | |
void setup() | |
{ | |
// put your setup code here, to run once: | |
SPI.begin(); | |
SPI.setDataMode(SPI_MODE0); | |
SPI.setBitOrder(MSBFIRST); | |
for (uint8_t *pidx = (uint8_t *)&unused_pins[0]; *pidx != 0; pidx++) { | |
pinMode(*pidx, INPUT_PULLDOWN); | |
} | |
radio.begin(RADIO_SPEED, RADIO_CHANNEL); | |
radio.setCRC(true, true); // CRC enabled, 16-bit | |
radio.autoAck(false); | |
radio.setTXpower(0); // Maximum TX strength (0dBm) | |
} | |
#define TAG_ADC10_1_ 0x10DA /* ADC10_1 calibration tag */ | |
#define CAL_ADC_25T85 (*(unsigned short *)(TAG_ADC10_1_+0x0010)) | |
#define CAL_ADC_25T30 (*(unsigned short *)(TAG_ADC10_1_+0x000E)) | |
#define CAL_ADC_25VREF_FACTOR (*(unsigned short *)(TAG_ADC10_1_+0x000C)) | |
#define CAL_ADC_15T85 (*(unsigned short *)(TAG_ADC10_1_+0x000A)) | |
#define CAL_ADC_15T30 (*(unsigned short *)(TAG_ADC10_1_+0x0008)) | |
#define CAL_ADC_15VREF_FACTOR (*(unsigned short *)(TAG_ADC10_1_+0x0006)) | |
#define CAL_ADC_OFFSET (*(short *)(TAG_ADC10_1_+0x0004)) | |
#define CAL_ADC_GAIN_FACTOR (*(unsigned short *)(TAG_ADC10_1_+0x0002)) | |
uint16_t sample_count = 0; | |
void loop() | |
{ | |
// put your main code here, to run repeatedly: | |
long lTempval, lTempC, lAdcmem; | |
int tempC; | |
uint8_t rfbuf[16]; | |
// Sample TEMPSENSOR with 1.5V Vref | |
analogReference(INTERNAL1V5); | |
lAdcmem = analogRead(TEMPSENSOR); | |
// Scale to degrees Celsius using built-in Info_A calibration constants. | |
// TODO: Convert #define's for calibration constants into an actual "Tag Reader" code routine | |
// for better chip cross-compatibility. | |
lTempval = 3604480L / (CAL_ADC_15T85 - CAL_ADC_15T30); // cc_scale | |
lTempC = lTempval * lAdcmem + (1998848L - (CAL_ADC_15T30 * lTempval)); | |
lTempC /= 65536; | |
tempC = (int) lTempC; | |
// Craft nRF24L01+ packet | |
rfbuf[0] = 0x10; // Thermocouple (or other temp sensor) program ID | |
rfbuf[1] = 6; | |
rfbuf[2] = DEVICE_ID; | |
rfbuf[3] = tempC & 0xFF; | |
rfbuf[4] = tempC >> 8; | |
rfbuf[5] = tempC & 0xFF; // repeat value for the thermocouple "cold junction temp" field since | |
rfbuf[6] = tempC >> 8; // it doesn't apply here. | |
rfbuf[7] = 0; // Fault codes not applicable here either. | |
rfbuf[8] = 0xFE; // DEBUG program ID | |
rfbuf[9] = 3; | |
rfbuf[10] = DEVICE_ID; | |
rfbuf[11] = sample_count & 0xFF; | |
rfbuf[12] = sample_count >> 8; | |
sample_count++; | |
// Send 'er out | |
radio.write(rfbuf, 12); | |
radio.flush(); | |
radio.deepsleep(); | |
// Bye bye for a while! | |
sleepSeconds(SLEEP_INTERVAL); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment