Sample program to read TI HDC1000EVM - Raspberry Pi Forums
here sample program in python2.x read texas instruments hdc1000evm
code: select all
import serial #sample program read texas instruments hdc1000evm #initialization , open port #possible timeout values: # 1. none: wait forever, block call # 2. 0: non-blocking mode, return # 3. x, x bigger 0, float allowed, timeout block call ser = serial.serial() #ser.port = "/dev/ttyusb0" #ser.port = "com4:" #ser.port = "/dev/ttyacm1" ser.port = "/dev/serial/by-path/platform-bcm2708_usb-usb-0:1.2:1.0" ser.baudrate = 115200 ser.bytesize = serial.eightbits #number of bits per bytes ser.parity = serial.parity_none #set parity check: no parity ser.stopbits = serial.stopbits_one #number of stop bits #ser.timeout = none #block read #ser.timeout = 1 #non-block read ser.timeout = 2 #timeout block read ser.xonxoff = false #disable software flow control ser.rtscts = false #disable hardware (rts/cts) flow control ser.dsrdtr = false #disable hardware (dsr/dtr) flow control ser.writetimeout = 2 #timeout write try: ser.open() except exception e: print ("error open serial port: " + str(e)) exit() if ser.isopen(): try: ser.flushinput() #flush input buffer, discarding contents ser.flushoutput()#flush output buffer, aborting current output #and discard in buffer #write data ser.write(bytes(43)) numoflines = 0 while true: response = ser.readline() if (str(response).find(",") == -1): print("start data: " + str(response)) else: print(" temperature: " + str(("{0:.2f}".format(((float(int((str(response).split(',')[0]),16))/float(65536)) * 165) -40)))+ u"\u00b0" + "c") print("relative humidity: " + str(("{0:.2f}".format((float(int((str(response).split(',')[1]),16))/float(65536)) * 100)))+ "%") numoflines = numoflines + 1 if (numoflines >= 100): ser.write(bytes(44)) response = ser.readline() print("read data: " + str(response)) break ser.close() except exception e1: print ("error " + str(e1)) ser.write(bytes(44)) response = ser.readline() print("last data: " + str(response)) ser.close() else: print ("cannot open serial port ")
raspberrypi
Comments
Post a Comment