Using Python to retrieve data from an Arduino board (sample code for a DHT)

Project description:

- On one side, an Arduino Uno board, with a DHT sensor to measure Humidity and Temperature
– ref. Overview | DHT11, DHT22 and AM2302 Sensors | Adafruit Learning System
– attached the code (.ino) to run on the board side

- On the other side, a computer with a Python script running, to get then to draw the temperature and humidity data
– Personally, I use the “Anaconda” Python redistribution (ref. http://www.continuum.io)
– In addition I installed the “pyserial” package for communicating with the Arduino (ref. http://pyserial.sourceforge.net)
– For drawing the data, I use the matplotlib package (ref. http://matplotlib.org/1.3.1/index.html)
– See screenshot

Enjoy :slight_smile:
AL.

TempHumidityPython.py (3.43 KB)

TempHumidityArduino.ino (977 Bytes)

thanks for sharing!

Updated version: now the Python code send parameters to the Arduino program to modify the sampling rate parameter, and to start/stop the logging of data.

My next step: wrapping up the command communication in a utility class (Python and Arduino side). Same to receiving data among a period of time.

AL.

TempHumidityPython2.py (4.25 KB)

TempHumidityArduino2.ino (1.38 KB)

The .ino file attached is empty ...

Sorry about that. I just re-updated the document. Thank you!

alina:
Updated version: now the Python code send parameters to the Arduino program to modify the sampling rate parameter, and to start/stop the logging of data.

My next step: wrapping up the command communication in a utility class (Python and Arduino side). Same to receiving data among a period of time.

AL.

Thank you very much for your code. I get the error :

print str(Inc)+" “+str(ArduinoSerial.isOpen())+” "+str(time.time()-InitTime)
^
SyntaxError: invalid syntax

Did you get it to run ?