We have previously measured distance using the HC-SR04 ultrasonic sensor using sleep and loops to send the pulse and measure the time it takes for the pulse to bounce back. This works but means the microcontroller cannot do anything while getting the distance measurement. There is another way to run the ultrasonic sensor without using up all the microcontrollers CPU time … interrupts
New Concepts:

The HC-SR04 runs on 5V, not 3.3V — make sure VCC is wired to the 5V rail.
Disconnect all power before building the circuit. Reconnect once verified.

Connections:

File: 05_advanced/code/Ultrasonic_Ranging.py
03_sensors/code/.Ultrasonic_Ranging.py.
Holds Trig HIGH for about 10 microseconds, telling the HC-SR04 to send an ultrasonic pulse.
Constructs an interrupt that is triggered when Echo to goes from LOW to HIGH (the pulse has been sent), and when it goes from HIGH to LOW (the echo was received). On each trigger it runs the callback function.
When called on the rising edge (pin.value() == 1) the start ticks are saved. When called on the falling eduge (pin.value() == 0) the end ticks are saved and distance is calculated.
Adapted from Python_Tutorial.pdf Project 21.1