Search icon
Subscription
0
Cart icon
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Python Programming for Arduino

You're reading from  Python Programming for Arduino

Product type Book
Published in Feb 2015
Publisher
ISBN-13 9781783285938
Pages 400 pages
Edition 1st Edition
Languages

Table of Contents (18) Chapters

Python Programming for Arduino
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
1. Getting Started with Python and Arduino 2. Working with the Firmata Protocol and the pySerial Library 3. The First Project – Motion-triggered LEDs 4. Diving into Python-Arduino Prototyping 5. Working with the Python GUI 6. Storing and Plotting Arduino Data 7. The Midterm Project – a Portable DIY Thermostat 8. Introduction to Arduino Networking 9. Arduino and the Internet of Things 10. The Final Project – a Remote Home Monitoring System 11. Tweet-a-PowerStrip Index

Plotting data from a CSV file


At the beginning of the chapter, we created a CSV file from Arduino data. We will be using that SensorDataStore.csv file for this section. If you recall, we used two different sensors to log the data. Hence, we have two arrays of values, one from a digital sensor and another from the analog one. Now, in the previous example, we just plotted one set of values for the y axis. So, how are we going to plot two arrays separately and in a meaningful way?

Let's start by creating a new Python program using the following lines of code or by opening the plotCSV.py file from this chapter's code folder:

import csv
from matplotlib import pyplot

i = []
mValues = []
pValues = []

with open('SensorDataStore.csv', 'r') as f:
    reader = csv.reader(f)
    header = next(reader, None)
    for row in reader:
        i.append(int(row[0]))
        pValues.append(float(row[1]))
        if row[2] == 'True':
            mValues.append(1)
        else:
            mValues.append(0)

pyplot...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}