Skip to content

Commit

Permalink
Add manual temperature calibration
Browse files Browse the repository at this point in the history
  • Loading branch information
maniacbug committed Aug 21, 2013
1 parent 5042b2c commit 3a1a2a7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
23 changes: 21 additions & 2 deletions examples/sensornet/nodeconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const eeprom_info_t& nodeconfig_read(void)
{
printf_P(PSTR("ADDRESS: %o\n\r"),eeprom_info.address);
printf_P(PSTR("ROLE: %S\n\r"),eeprom_info.relay ? PSTR("Relay") : PSTR("Leaf") );
printf_P(PSTR("TEMP: %04x\n\r"),eeprom_info.temp_calibration);
}
else
{
Expand Down Expand Up @@ -53,8 +54,8 @@ void nodeconfig_listen(void)
if (Serial.available())
{
// If the character on serial input is in a valid range...
char c = Serial.read();
if ( c >= '0' && c <= '5' )
char c = tolower(Serial.read());
if ( (c >= '0' && c <= '9' ) || (c >= 'a' && c <= 'f' ) )
{
*nextserialat++ = c;
if ( nextserialat == maxserial )
Expand Down Expand Up @@ -82,6 +83,24 @@ void nodeconfig_listen(void)
if ( ! eeprom_info.isValid() )
printf_P(PSTR("Please assign an address\r\n"));
}
else if ( tolower(c) == 't' )
{
// Send temperature calibration as 2-digit 4.4-fixed decimal signed degrees
// celcius--followed by a 't'. So, for -1.5 degrees, send "e8t". Or for +2 degrees
// send "20t"

*nextserialat = 0;
int8_t val = strtol(serialdata,NULL,16);
nextserialat = serialdata;

eeprom_info.temp_calibration = val * 0x10;
printf_P(PSTR("TEMP: %02x\n\r"),eeprom_info.temp_calibration);

eeprom_update_block(&eeprom_info,address_at_eeprom_location,sizeof(eeprom_info));
printf_P(PSTR("RESET NODE before changes take effect\r\n"));
if ( ! eeprom_info.isValid() )
printf_P(PSTR("Please assign an address\r\n"));
}
else if ( c == 13 )
{
// Convert to octal
Expand Down
4 changes: 3 additions & 1 deletion examples/sensornet/nodeconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ struct eeprom_info_t
{
uint8_t flag;
uint16_t address;
int16_t temp_calibration; // sensor adjustment in signed fixed-8.8 degrees, e.g. 0xFE80 is -1.5
bool relay:1;

static const uint8_t valid_flag = 0xde;
static const uint8_t valid_flag = 0xdd;

eeprom_info_t()
{
Expand All @@ -33,6 +34,7 @@ struct eeprom_info_t
flag = valid_flag;
address = 0xffff;
relay = false;
temp_calibration = 0;
}

};
Expand Down
4 changes: 3 additions & 1 deletion examples/sensornet/sensornet.pde
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,9 @@ void loop(void)
// This is the formula for MCP9700.
// C = reading * 1.1
// C = ( V - 1/2 ) * 100
message.temp_reading = ( ( ( reading * 0x120 ) - 0x800000 ) * 0x64 ) >> 16;
//
// Then adjust for the calibation value on this sensor
message.temp_reading = ( ( ( ( reading * 0x120 ) - 0x800000 ) * 0x64 ) >> 16 ) + this_node.temp_calibration;

// Take the voltage reading
i = num_measurements;
Expand Down

0 comments on commit 3a1a2a7

Please sign in to comment.