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

How to do it...

In the next section, we shall write a script to allow us to gather data that we will then use later on in this chapter.

Create the following script, data_adc.py, as follows:

  1. First, import the modules and create the variables we will use, as follows:
#!/usr/bin/env python3 
#data_adc.py 
import wiringpi2 
import time 
 
DEBUG=False 
LIGHT=0;TEMP=1;EXT=2;POT=3 
ADC_CH=[LIGHT,TEMP,EXT,POT] 
ADC_ADR=0x48 
ADC_CYCLE=0x04 
BUS_GAP=0.25 
DATANAME=["0:Light","1:Temperature", 
          "2:External","3:Potentiometer"] 
  1. Create the device class with a constructor to initialize it, as follows:
class device: # Constructor: def __init__(self,addr=ADC_ADR): self.NAME = DATANAME self.i2c = wiringpi2.I2C() self.devADC=self.i2c.setup(addr) pwrup = self.i2c.read(self.devADC) ...
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