# make sure that the extension is .py instead of 'txt' !!! import smbus from ctypes import c_short import numpy as np import matplotlib.pyplot as plt c = smbus.SMBus(1) bus = smbus.SMBus(1) # b.write_byte_data(0x48,0xff,0xff) # b.read_byte(0x48) #fid= open('file.txt', 'w') y=0 #for x in xrange(1,10): # b.write_byte_data(0x20,y,y) # print(s) # dat=s[0:len(s)-1] # T = time.strftime("%a, %d %b %Y %H:%M:%S") # fid.write(dat+'\t' + T+ '\n') # print(y) #fid.close() #e= b.read_byte(0x48) #print("yes %d"%e) #d=c.read_word_data(0x48,0x00) #for x in range (1,1): # d=c.read_word_data(0x48,0x00) # db="{0:b}".format(d) # print("yes %s"%db) ax=[] tmp=[] fid=open('file2.txt','w') for x in range(1,2000): (MSB, LSB)= bus.read_i2c_block_data(0x48,0x00,2) lsb="{0:b}".format(LSB>>5) #print("cb= %s %s"%(MSB,(LSB>>5)*0.125) ) #print("temp= %s" %(MSB+(LSB>>5)*0.125) ) y= ( MSB + (LSB>>5)*0.125) if (y >= 200): tmp.append(y-256) else: tmp.append(y) print("temp= %s %s" %(y, x) ) buf=("%s" %y ) fid.write(buf + '\n') ax.append(x) fid.flush() fid.close() plt.plot(ax,tmp) plt.show()