GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing learn.sparkfun.com — Graph Sensor Data with Python and Matplotlib - SparkFun Learn Graph Sensor Data with Python and Matplotlib
Contributors:
Share
Use this URL to share:
Plot Sensor DataIn the Python Programming Tutorial: Getting Started with the Raspberry Pi, the final example shows how to sample temperature data from the TMP102 once per second over 10 seconds and then save that information to a comma separated value (csv) file. To start plotting sensor data, let's modify that example to collect data over 10 seconds and then plot it (instead of saving it to a file). TMP102 ModuleIn order to simplify I2C reading and writing to the TMP102, we will create our own TMP102 Python module that we can load into each of our programs. Open a new file named tmp102.py:
Copy in the following Python code:
Save the code with ctrl + x, press y, and press enter. This allows us to call the Temperature Logging and GraphingIn the same directory as the tmp102.py file, create a new file (using your favorite editor), and paste in the following code:
Save (give it a name like tempgraph.py) and exit. Run the program with:
Wait while the program collects data (about 10 seconds). Feel free to breathe on or fan near the temperature sensor to change the ambient temperature (gives you some interesting data to look at). Once the collection has finished, you should be presented with a plot showing how the temperature changed over time. Code to NoteWe create the graph in a very similar manner to the Formatting example in Introduction to Matplotlib. The only difference is that we build the The
Share
Use this URL to share:
Pages
Introduction
Prepare Your Pi
Hardware Assembly
Introduction to Matplotlib
Plot Sensor Data
Update a Graph in Real Time
Speeding Up the Plot Animation
Resources and Going Further
Comments
1
Single Page
Print
|
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |