import spidev
import time
import os
 
spi = spidev.SpiDev()
spi.open(0,0)
 
def ReadChannel(channel):
  adc = spi.xfer2([1,(8+channel)<<4,0])
  data = ((adc[1]&3) << 8) + adc[2]
  return data
 
def ConvertVolts(data,places):
  volts = (data * 3.3) / float(1023)
  volts = round(volts,places)
  return volts
 
first_channel = 0
second_channel  = 1
 
delay = 5
print "------------------------------------------------------"
 
while True:
 
  
  first_level = ReadChannel(first_channel)
  first_channel_volts = ConvertVolts(first_level,2)
 
  
  second_level = ReadChannel(second_channel)
  second_channel_volts = ConvertVolts(second_level,2)
  
 
  
  print "------------------------------------------------------"
  print("First ADC channel: {} ({}V)".format(first_level,first_channel_volts))
  print("Second ADC channel : {} ({}V)".format(second_level,second_channel_volts))
 
  
  time.sleep(delay)