How it works...

We start by importing wiringpi2 so we can communicate with our I2C device later on. We will create a class to contain the required functionality to control the ADC. When we create the class, we can initialize wiringpi2 in such a way that it is ready to use the I2C bus (using wiringpi2.I2C()), and we will set up a generic I2C device with the chip's bus address (using self.i2c.setup(0x48)).

wiringpi2 also has a dedicated class to use with the PCF8591 chip; however, in this case, it is more useful to use the standard I2C functionality to illustrate how any I2C device can be controlled using wiringpi2. By referring to the device datasheet, you can use similar commands to communicate to any connected I2C device (whether it is directly ...

Get Raspberry Pi 3 Cookbook for Python Programmers - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.