#!/usr/bin/python
# -*- coding:utf-8 -*-
import smbus
import time
import matplotlib.pyplot as plt
start = time.time()
address = 0x48
A0 = 0x40
A1 = 0x41
A2 = 0x42
A3 = 0x43
bus = smbus.SMBus(1)
bus.write_byte_data(address,0,0b00010000)#control byte to tell ADC to act as a differential input
voltage_value = [ ]
time_value = [ ]
try:
while True:
bus.write_byte(address,A0)
value = bus.read_byte(address)
voltage_value.append(value)
time_value.append(time.time()-start)
#print("AOUT:%1.3f " %(value*3.3/255))
#print(value)
#time.sleep(0.1)
except KeyboardInterrupt:
voltage_value = [x*3.3/255 for x in voltage_value]
plt.plot(time_value,voltage_value)
plt.ylabel('Voltage')
plt.xlabel('Time')
plt.show()
with open('output.txt', 'w') as f:
for v,t in zip(voltage_value,time_value):
f.write(str(v)+' '+str(t)+'\n')