# Show value of readings from distance sensor on the display
# Uses CircuitPython
# learn more:
# https://learn.adafruit.com/ultrasonic-sonar-distance-sensors/python-circuitpython

import time
import board
import busio
import adafruit_hcsr04
import displayio
import terminalio
from adafruit_display_text import label
import adafruit_displayio_ssd1306

sonar = adafruit_hcsr04.HCSR04(trigger_pin=board.GP17, echo_pin=board.GP16)

displayio.release_displays()

i2c = busio.I2C(board.GP3, board.GP2)
display_bus = displayio.I2CDisplay(i2c, device_address=0x3C)
display = adafruit_displayio_ssd1306.SSD1306(display_bus, width=128, height=32)

# Make the display context
splash = displayio.Group()
display.root_group = splash

# Draw a label
text = "Initializing..."
text_area = label.Label(terminalio.FONT, text=text, color=0xFFFF00, x=5, y=5)
splash.append(text_area)

while True:
    try:
        text = str(sonar.distance)
        text_area.text = text
        print(text)
    except RuntimeError:
        print("Retrying...")
    time.sleep(1)
$abcdeabcde151015202530354045505560fghijfghij
BOOTSELLED1239USBRaspberryPiPico©2020RP2-8020/21P64M15.00TTT
pico:GP0
pico:GP1
pico:GND.1
pico:GP2
pico:GP3
pico:GP4
pico:GP5
pico:GND.2
pico:GP6
pico:GP7
pico:GP8
pico:GP9
pico:GND.3
pico:GP10
pico:GP11
pico:GP12
pico:GP13
pico:GND.4
pico:GP14
pico:GP15
pico:GP16
pico:GP17
pico:GND.5
pico:GP18
pico:GP19
pico:GP20
pico:GP21
pico:GND.6
pico:GP22
pico:RUN
pico:GP26
pico:GP27
pico:GND.7
pico:GP28
pico:ADC_VREF
pico:3V3
pico:3V3_EN
pico:GND.8
pico:VSYS
pico:VBUS
oled1:GND
oled1:VCC
oled1:SCL
oled1:SDA
ultrasonic1:VCC
ultrasonic1:TRIG
ultrasonic1:ECHO
ultrasonic1:GND
r1:1
r1:2
Voltage divider and VBUS for 5V to HC-SR04
r2:1
r2:2