Skip to content

Commit

Permalink
Change temperature sensor to transmit meaningful C*256 values
Browse files Browse the repository at this point in the history
  • Loading branch information
maniacbug committed Mar 27, 2012
1 parent 442edb2 commit 7c76f97
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
5 changes: 3 additions & 2 deletions examples/sensornet/S_message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ char S_message::buffer[32];

char* S_message::toString(void)
{
snprintf(buffer,sizeof(buffer),"#%06u %04x /%2u.%02uV",
snprintf(buffer,sizeof(buffer),"#%06u %2u.%02uC /%2u.%02uV",
counter,
temp_reading,
temp_reading >> 8,
( temp_reading & 0xFF ) * 100 / 256,
voltage_reading >> 8,
( voltage_reading & 0xFF ) * 100 / 256
);
Expand Down
12 changes: 9 additions & 3 deletions examples/sensornet/sensornet.pde
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,18 @@ void loop(void)

// Take the temp reading
i = num_measurements;
uint32_t reading = 0;
while(i--)
message.temp_reading += analogRead(temp_pin);

reading += analogRead(temp_pin);

// Convert the voltage reading to celcius*256
// This is the formula for MCP9700.
// C = ( V - 1/2 ) / 100
message.temp_reading = ( reading - 0x8000 ) * 0x100 / ( 0x10000 / 100 );

// Take the voltage reading
i = num_measurements;
uint32_t reading = 0;
reading = 0;
while(i--)
reading += analogRead(voltage_pin);

Expand Down

0 comments on commit 7c76f97

Please sign in to comment.