Hardware Reference
In-Depth Information
If the second flip-flop is used, simply ground unused pins 9 and 11. Otherwise,
unused pins 8 and 10 should also be grounded. With two flip-flops in the CD4013, you
could debounce two switches/buttons.
Testing the Flip-Flop
After wiring up the CD4013 circuit, you can do a preliminary test before hooking it up to
your Pi. Simply apply +3.3 V to the circuit and measure the voltage on pin 1 ( Q 1 ). When
you throw the switch from one position to the next, the output of Q 1 should follow.
Hooked up to the Pi, you can test the circuit with the evinput program that is
developed in Chapter 10 of Raspberry Pi Hardware Reference (Apress, 2014). You can
choose any suitable GPIO input, or one that you configured for input. Consult that book
also for a list of GPIOs that boot up in input mode. I chose to use GPIO 22 (GEN3):
$ ./evinput 22
Monitoring for GPIO input changes :
GPIO 22 changed : 0
GPIO 22 changed : 1
GPIO 22 changed : 0
GPIO 22 changed : 1
GPIO 22 changed : 0
^C
$
Here the switch was initially off ( Q 1 reads low). Then I threw the switch on, and then
off, on, and then off again. Notice that there are no intervening glitches or other contact
bounce events.
If you have a microswitch available with SPDT contacts, you can wire it as a push
button. Push it on, release it, push it on again, and release again. The Raspberry Pi
will read nice clean events without any contact bounce. That's how we like it on the
software side!
The LED
Figure 8-3 shows the wiring for the LED. The resistor R 1 was chosen to provide a red LED,
about 8 mA. If you're using a lower-powered LED, you can increase the resistance of R 1 .
Students may want to refer to Chapter 10 of Raspberry Pi Hardware Reference (Apress, 2014)
for the procedure on how to calculate the resistance for R 1 .
 
Search WWH ::




Custom Search