#! /usr/bin/env python3
#-*- coding: utf-8 -*-
#
#----------------------------------------------------------------------
# python3 /home/scripts_python_tests_capteurs/TC77/test_spi_tc77.py
#----------------------------------------------------------------------

import sys
import RPi.GPIO as GPIO
import time
import spidev

GPIO.setmode(GPIO.BOARD)

spi = spidev.SpiDev()
speed = 1000000
spi.open(0,1)
spi.max_speed_hz=speed

try:
	while True:
		response = spi.readbytes(2)
		data_can = (256*response[0] + 1*response[1])//8
		temperature = 0.0625 * data_can

		print("Temp1 : ")
		print(temperature)

		time.sleep(2.0)


except KeyboardInterrupt:
	spi.close()

GPIO.cleanup()    
 
