April 2018
Beginner
552 pages
13h 58m
English
The servo code is based on the PWM driver that Adafruit uses for their module; however, it is not Python 3 friendly, so we need to create our own version. We will use wiringpi2 I2C driver to initialize and control the I2C PWM controller. We define the registers that we will need to use (see the datasheet for the PCA9685 device), as well as its default bus address, 0x40 (PWMADR), and a PWM frequency of 50 Hz (PWMHZ).
Within our servo class, we initialize the I2C driver in wiringpi2 and set up our devPWM device on the bus. Next, we initialize the PWM device itself (using pwmInit()). We have to calculate the prescaler required for the device to convert the onboard 25 MHz clock to a 50 Hz signal to generate the PWM frequency we ...