element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Personal Blogs
  • Community Hub
  • More
Personal Blogs
Legacy Personal Blogs HDC1000EVM Python code for Raspberry Pi
  • Blog
  • Documents
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: wymand
  • Date Created: 16 Apr 2015 12:08 AM Date Created
  • Views 944 views
  • Likes 1 like
  • Comments 4 comments
  • python
  • hdc1000evm
  • raspberry-pi
Related
Recommended

HDC1000EVM Python code for Raspberry Pi

wymand
wymand
16 Apr 2015

Here is a sample program that starts a stream from the HDC1000EVM, reads 100 returns and  stops the stream:

 

import serial

#sample program to read Texas Instruments HDC1000EVM

#initialization and open the port

#possible timeout values:

 

 

#    1. None: wait forever, block call

#    2. 0: non-blocking mode, return immediately

#    3. x, x is bigger than 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 for write

 

 

try:

    ser.open()

except Exception as e:

    print ("error open serial port: " + str(e))

    exit()

if ser.isOpen():

    try:

        ser.flushInput() #flush input buffer, discarding all its contents

        ser.flushOutput()#flush output buffer, aborting current output

                        #and discard all that is in buffer

        #write data

        #ser.write(bytes(43))

        ser.write(serial.to_bytes([0x33]))

        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("      Temperature: " + str(("{0:.2f}".format((((((float(int((str(response).split(',')[0]),16))/float(65536)) * 165) -40) * 9) / 5) + 32)))+ u"\u00B0" + "F")

                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))

                ser.write(bytes(52))

                response = ser.readline()

                print("read data: " + str(response))

                break

                ser.close()

    except Exception as e1:

        print ("error " + str(e1))

    ser.write(serial.to_bytes([0x34]))

    response = ser.readline()

    print("last data: " + str(response))

    ser.close()

else:

    print ("cannot open serial port ")

  • Sign in to reply
  • wymand
    wymand over 10 years ago

    July 11, 2015.  I have found that the TI chip varies quite a bit on a single read.

     

    So I have changed my home code that charts temperature to do 4 reads and average the four.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • wymand
    wymand over 10 years ago

    I have updated the code to better reflect how the pyserial writers wanted Serial to be used

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • wymand
    wymand over 10 years ago

    In case it hasn't been noticed, the RPi code uses byte(43) to initiate the stream and byte(44) to stop the stream.  Now I don't know why *yet* but the protocol for starting a stream is definitely a "3" or decimal character 51 (hex 0x33)  and stopping the stream is definitely a "4" decimal 52 (hex 0x34) I want to make this clear because my next blog entry is going to look at the communications protocol that is used to address the device. I will be doing this on my PC because that is where all my tools are located.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • dbwilliams
    dbwilliams over 10 years ago

    Thanks, I guess I'll have to try it out on the Pi too!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube