OpenAccess temperature functions

The thought behind the temperature sensor was to be able to set the contrast of the LCD based on it, I didn’t know how to put the logic in the uart lcd so I made it externally controllable with the thought to add logic later.  The function to check the temperature can be called by the serial port and reports back that way and to the dot matrix printer.  Here is the temperature sensor setup for checking outside temperature:

// Interface to DS1822 chip, record data to EEPROM
#include <OneWire.h>
OneWire ds(30); // define the pin the interface is on */
float current_temperature;

Here is my function for getting the temperature:

float getTemp()
byte data[9];
byte addr[8];
int temp;

while ( !
//Serial.print(“No more addresses.\n”);
byte present = ds.reset();;
for (byte i = 0; i < 9; i++)
data[i] =;
boolean negative = (data[1] & 1<<5);
data[1] <<=4;
data[1] >>=4;
temp = data[1];
temp <<= 8; /* shift left eight bits */
temp += data[0]; /* add second byte of temperature */
float tempFloat = (float)temp/16.0;
tempFloat = -tempFloat;
return tempFloat;

This temperature is used in the function another wrapper function to get the temperature and log it:

// logs temperature
void check_temp()
char temp[8];
current_temperature = getTemp();//stored for calculation of contrast value later
//dtostrf(voltage,8,2,volt); should work?
printname = “Temperature outside: “;
printname += temp;

logging(” – “);

That variable “current_temperature” is used nowhere else and need not be declared globally.  This is part of the greater OpenAccess project.

One Response to “OpenAccess temperature functions”

  1. OpenAccess 3.0 replacement software | Evan's Techie-Blog Says:

    […] temperature functions […]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: