Raspberry Pi GPIO Analogue ExercisesFollow article
The aim of this exercise is to show students how to program the Raspberry Pi to “measure” the state of one of its GPIO pins as a digital input, how the Raspberry Pi may be used in conjunction with an Analogue to Digital Converter (ADC) to measure an analogue voltage, and how the Raspberry Pi may be used in conjunction with a Digital to Analogue Converter (DAC) to generate an analogue signal.
The exercise is split in to three “Steps” of increasing complexity
Step 1 introduces the student to the IDLE integrated development environment and to the Python programming language by asking them to enter commands directly at the Python prompt. The concept of a single digital input representing a single “bit” of data in introduced.
Step 2 introduces the concept of creating a file containing a series of Python commands, saving this file as a “computer program”, and “running” the program. The difference between a digital and an analogue signal is discussed and it is shown how an Analogue to Digital Converter (ADC) may be used to enable analogue signals to be measured. The concept of serial and parallel data interfaces is introduced and the Raspberry Pi is configured to use the I2C protocol. Students will also use the “apt-get” command to download and install software packages from the Debian repository. Basic data transfer between the Raspberry Pi and peripheral hardware is demonstrated by reading data from the ADC chip, and in Python, the “while” loop is introduced.
Step 3 introduces the student to the concept of a Digital to Analogue Converter (DAC) and shows how a DAC may be used to generate an analogue signal. The difference between an analogue and a digital signal is further discussed, and data transfer between the Raspberry Pi and peripheral hardware is demonstrated by sending data to the DAC. This introduces the concept of using hexadecimal notation to represent of binary data. In Python, the “for” loop is introduced and the concept of reusing and adapting code is demonstrated by asking the student to load and edit the code from the previous step.
Note- These exercises were created using a Raspberry Pi Model B with a 26 Way GPIO Pin header. Newer models have a 40 Way GPIO header, but the first 26 pins ae the same.
Please see attached files for exercises and Raspberry Pi Setup guides