Balloon Collaboration
February 27, 2020, 12:10:35 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: is now part of the BarnTek information network...Currently redirected to
   Home   Help Search gallery Calendar Login Register  
Pages: [1]
Author Topic: Temperature Sensors  (Read 1677 times)
Hero Member
Posts: 1167

View Profile
« on: March 21, 2014, 09:46:24 PM »

I have been playing with my temperature sensors.  I have one soldered to the expansion board mounted on the Pi.  I, also, have a second, external sensor connected which will measure outside temperature.  These are mounted on what will become the Master Pi, I hope.  This program is generating 2 files: temp.dat and ctemp.  Temp.dat is the data log of all the temperatures collected every 10 seconds.  Ctemp is a file which only stores the current temperatures from sensor 1 and sensor2, comma delimited and ended with a CRLF.  I thought that Danny could just read this file to obtain the current temperature reading when he is compiling the telemetry statement.  If you want me to formatted differently, let me know.

I am, also, using a 2x20 char LCD display to show the temps instead of printing to the screen.

FYI, the sensors measure in C to a degree, and I have to convert it into F, hence the odd steps in the readings.


###  DS1621 Digital Thermometer and Thermostat
###  This program access the device via I2C
###        by Larry Barnes

import time
import smbus
import serial

port=serial.Serial("/dev/ttyAMA0", baudrate=115200, timeout=3.0)




SCP=chr(0xFE)+chr(0x45)  # Set Cursor Position   +chr(position value)
HOM=chr(0xFE)+chr(0x46)  # Home Cursor
CLS=chr(0xFE)+chr(0x51)  # Clear Display
def StartConvertT(address):

def ReadTemperature(address):
    x1=x>>8 # Get the left Byte
    x2=x-(x1<<8) # Get the right Byte
    x3=bool(x1&128) # All I need is bit 7 for the half degree indicator
    x4=x2+half[x3]  # Temperature in Celcius
    return x4

def convertC2F(x):
    return x1


# Start the Temperature Calculations

    while True:
        temp1C='%.1f' % (temp1)
        temp1F='%.1f' % (f1)
   temp2C='%.1f' % (temp2)
   temp2F='%.1f' % (f2)        

        port.write(SCP+chr(42)+temp1F+" F ")
   port.write(SCP+chr(52)+temp2F+" F ")

   with open('temp.dat','a') as d:
   with open('ctemp','w') as d:   

except KeyboardInterrupt:
Pages: [1]
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!