Course materials · Microprocessor Applications

GPIO · Learning

English translation

Execution conditions

Use the recorded waveform for the baseline exercise. For the hardware extension, compare the BCM numbers and input/output settings in the original RPi.GPIO code with the board you use.

Topics covered

Use timestamped records to examine multiple signals from a single button press, and define input handling rules.

Overall workflow

Button signal → transition times → polling and debounce → press events

Physical button signals and events

A mechanical contact can change several times briefly after one press. Recorded transition times show why the number of presses differs from the number of signal changes.

Observation intervals and debounce

Polling is how often values are read; debounce is a rule for grouping closely spaced changes. Polling intervals that are too long can miss short inputs, while debounce intervals that are too long can merge actual successive inputs.

Convert time units to a common unit for comparison.

Worked example

(t_ms,level)=[(0,0),(10,1),(12,0),(14,1),(50,0),(80,1)]. Between records, the preceding level is maintained.

import numpy as np
import matplotlib.pyplot as plt
events=[(0,0),(10,1),(12,0),(14,1),(50,0),(80,1)]
rising=[t for (t,x),(_,previous) in zip(events[1:],events[:-1]) if previous==0 and x==1]
print('raw rising',rising)
raw rising [10, 14, 80]

Reference example

View more examples

Reference materials