diff --git a/examples/tmp36-lm35.py b/examples/tmp36-lm35.py new file mode 100644 index 0000000..8ceaac3 --- /dev/null +++ b/examples/tmp36-lm35.py @@ -0,0 +1,30 @@ +""" + tmp36-lm35.py + Alaa Agwa - 3/2014 + + Example program for PyBBIO's TMP36LM35 library. + Reads the temerature from the TMP36 or LM35 sensors from analog pin. + + This example program is in the public domain. +""" +from bbio import * +from TMP36LM35 import * + +data_pin = GPIO1_15 # P8.15 + +sensor = TMP36LM35(data_pin) + +def setup(): + pass + +def loop(): + temp = sensor.readTempC() + if (not temp): + # The sensor reported an error. + print "Error reading the sensor value" + else: + print "Temp: %0.2f C" % temp + + delay(1000) + +run(setup,loop) diff --git a/libraries/TMP36-LM35/README b/libraries/TMP36-LM35/README new file mode 100644 index 0000000..aa3328f --- /dev/null +++ b/libraries/TMP36-LM35/README @@ -0,0 +1,16 @@ +Servo - v0.1 + +Copyright 2014 Alaa Agwa +agwatic@gmail.com + +Library for controlling servo motors with the BeagleBone's PWM pins. + + +As well as the included example programs: + PyBBIO/examples/tmp36-lm35.py + + + +Servo is released as part of PyBBIO under its Apache 2.0 license. +See PyBBIO/LICENSE.txt + diff --git a/libraries/TMP36-LM35/TMP36LM35.py b/libraries/TMP36-LM35/TMP36LM35.py new file mode 100644 index 0000000..732c2d5 --- /dev/null +++ b/libraries/TMP36-LM35/TMP36LM35.py @@ -0,0 +1,25 @@ +""" + Servo - v0.1 + Copyright 2012 Alexander Hiam + + Library for reading the values of TMP36/LM35 temperature sensors. +""" + +from bbio import * + +class TMP36LM35(object): + def __init__(self, data_pin=None): + + self.data_pin = data_pin + + def readTempC(self): + """ Gets the sensor data in Celsius """ + return ((analogRead(self.data_pin)*3.3)/1024) # 3.3 for the gpio pin it's max volt are 3.3 V + + + def readTempF(self): + """ Return the sensor data in Fahrenheit """ + tempC = ((analogRead(self.data_pin)*3.3)/1024) # 3.3 for the gpio pin it's max volt are 3.3 V + return ((tempC * 9.0/5.0) + 32) + + \ No newline at end of file diff --git a/libraries/TMP36-LM35/__init__.py b/libraries/TMP36-LM35/__init__.py new file mode 100644 index 0000000..d2d843c --- /dev/null +++ b/libraries/TMP36-LM35/__init__.py @@ -0,0 +1,3 @@ +# __init__.py for TMP36LM35 + +from TMP36LM35 import *