Skip to content

Instantly share code, notes, and snippets.

@amirhaleem
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amirhaleem/86ce66039919ac986579 to your computer and use it in GitHub Desktop.
Save amirhaleem/86ce66039919ac986579 to your computer and use it in GitHub Desktop.
#include <SoftwareSerial.h>
#include <helium.h>
HeliumModem *modem;
void setup() {
modem = new HeliumModem();
}
void loop() {
static u32 lastTime;
u32 time;
time = millis();
if (time - lastTime > 5000) {
lastTime = time;
DataPack dp(1);
dp.appendFloat((float)get_temp());
modem->sendPack(&dp);
}
}
// return onboard temperature in degrees celcius
double get_temp(void) {
unsigned int wADC;
double t;
// set the internal reference and mux
ADMUX = (_BV(REFS1) | _BV(REFS0) | _BV(MUX3));
ADCSRA |= _BV(ADEN); // enable the ADC
delay(20); // wait for voltages to become stable
ADCSRA |= _BV(ADSC); // start the ADC
// detect end-of-conversion
while (bit_is_set(ADCSRA, ADSC));
// reading register "adcw" takes care of how to read adcl and adch
wADC = ADCW;
t = (wADC - 324.31) / 1.22;
// convert to F
t = ((t * 9) / 5) + 32;
return t;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment