In Chapter 5, Connecting Your Raspberry Pi to the Physical World, we discussed that by using PWM on a digital output pin, we can create a pseudo-analog output or the appearance of a variable output voltage. Furthermore, we also saw PWM in use back in Chapter 3, Networking with RESTful APIs and Web Sockets Using Flask, when we used this concept to control the brightness of an LED.
In this section, we'll explore the idea underlying PWM just a little further with a short exercise. Our example is similar to the one we performed for digital output previously, only this time, we are using PWM to produce a varying voltage on a GPIO pin. Here are the steps we need to follow:
- Connect your multimeter to your Raspberry Pi as we did for digital output in Figure 6.3.
- Run the following code, which you can find in the chapter06/analog_pwm_output_test.py file.
- As the code runs, your multimeter will step through a range of different voltages. They won't be...