Skip to Content
Raspberry Pi 3 Cookbook for Python Programmers - Third Edition
book

Raspberry Pi 3 Cookbook for Python Programmers - Third Edition

by Steven Lawrence Fernandes, Tim Cox
April 2018
Beginner content levelBeginner
552 pages
13h 58m
English
Packt Publishing
Content preview from Raspberry Pi 3 Cookbook for Python Programmers - Third Edition

Gathering analog data without hardware

If you don't have an ADC module available, there is a wealth of data available from within Raspberry Pi that you can use instead.

Create the data_local.py script as follows:

#!/usr/bin/env python3 #data_local.py import subprocess from random import randint import time MEM_TOTAL=0 MEM_USED=1 MEM_FREE=2 MEM_OFFSET=7 DRIVE_USED=0 DRIVE_FREE=1 DRIVE_OFFSET=9 DEBUG=False DATANAME=["CPU_Load","System_Temp","CPU_Frequency", "Random","RAM_Total","RAM_Used","RAM_Free", "Drive_Used","Drive_Free"] def read_loadavg(): # function to read 1 minute load average from system uptime value = subprocess.check_output( ["awk '{print $1}' /proc/loadavg"], shell=True) return float(value) def read_systemp(): # function to read ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Raspberry Pi for Python Programmers Cookbook - Second Edition

Raspberry Pi for Python Programmers Cookbook - Second Edition

Tim Cox

Publisher Resources

ISBN: 9781788629874Supplemental Content