Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Python Programming for Arduino
  • Toc
  • feedback
Python Programming for Arduino

Python Programming for Arduino

By : Pratik Desai
4.6 (22)
close
Python Programming for Arduino

Python Programming for Arduino

4.6 (22)
By: Pratik Desai

Overview of this book

This is the book for you if you are a student, hobbyist, developer, or designer with little or no programming and hardware prototyping experience, and you want to develop IoT applications. If you are a software developer or a hardware designer and want to create connected devices applications, then this book will help you get started.
Table of Contents (13 chapters)
close
12
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...

Unlock full access

Continue reading for free

A Packt free trial gives you instant online access to our library of over 7000 practical eBooks and videos, constantly updated with the latest in tech
bookmark search playlist font-size

Change the font size

margin-width

Change margin width

day-mode

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Delete Bookmark

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete