ugnen

git clone https://git.tarina.org/ugnen
Log | Files | Refs

temp_read_1_sensor.py (865B)


      1 # before import the max6675, you must save the max6675.py file at "/usr/lib/python2.7/dist-packages"
      2 
      3 # wiring
      4 # Raspberry         MAX6675
      5 #       GND   ------   GND
      6 #        5V     ------   VCC
      7 #   pin 18     ------   SCK
      8 #   pin 22     ------   CS
      9 #   pin 16     ------   SO
     10 
     11 # import max6675 module.
     12 import max6675
     13 
     14 # set the pin for communicate with MAX6675
     15 cs = 20
     16 sck = 26
     17 so = 16
     18 
     19 # max6675.set_pin(CS, SCK, SO, unit)   [unit : 0 - raw, 1 - Celsius, 2 - Fahrenheit]
     20 max6675.set_pin(cs, sck, so, 1)
     21 
     22 try:
     23     while 1:
     24         # read temperature connected at CS 22
     25         a = max6675.read_temp(cs)
     26 
     27         # print temperature
     28         print(a)
     29 
     30         # when there are some errors with sensor, it return "-" sign and CS pin number
     31         # in this case it returns "-22" 
     32         
     33         max6675.time.sleep(2)
     34         
     35 except KeyboardInterrupt:
     36     pass
     37 
     38 
     39