Writing a Program

Exit the Python Console by typing:
>>> exit()
This should take you back to the Linux prompt.

Enter the following command to create a new files called tmp36.py
nano tmp36.py
Now paste the code below into the editor window.
import Adafruit_BBIO.ADC as ADC
import time

sensor_pin = 'P9_40'


while True:
    reading = ADC.read(sensor_pin)
    millivolts = reading * 1800  # 1.8V reference = 1800 mV
    temp_c = (millivolts - 500) / 10
    temp_f = (temp_c * 9/5) + 32
    print('mv=%d C=%d F=%d' % (millivolts, temp_c, temp_f))
Save and exit the editor using CTRL-x and the Y to confirm.

To start the program, enter the command:
python tmp36.py
You will then see a series of readings.
mv=757 C=25 F=78
mv=760 C=26 F=78
mv=762 C=26 F=79
mv=765 C=26 F=79
mv=763 C=26 F=79
mv=763 C=26 F=79
mv=766 C=26 F=79
mv=768 C=26 F=80
When you want to stop the readings, use CTRL-c.
Warning: The analog inputs of the BBB operate at 1.8V. Since the TMP36 has a theoretical maximum output of 3.3V, there is a potential for the BBB to be damaged if the voltage in millivolts exceeds 1.8V. This will only happen on a TMP36 if the temperature exceeds 130 degrees C (266 degrees F).
Last updated on May 04, 2015 Published on Jun 27, 2013