J’ai acheté un capteur de distance 4064 et j’utilise micro-python sur Pico de Raspberry. Je n’arrive pas à le faire fonctionner. Auriez vous un exemple de code simple disponible ?
La led du capteur s’allume bien quand un objet est détecté.
Unfortunately, we can only offer support in English, but from a quick internet translation of your post, it sounds like you are asking for an example program to read the pulse width output from item #4064. I posted a quick MicroPython program that does that below:
from machine import Pin
import time
# Change to match the Microcontroller pin connected to the sensor's OUT pin.
sensorPin = Pin(2, Pin.IN)
while (1):
t = machine.time_pulse_us(sensorPin, 1)
if (t < 0):
# machine.time_pulse_us did not detect the pulse within 1 second.
print("timeout")
elif (t > 1850):
# no detection
print(-1)
else:
# Valid pulse width reading. Convert pulse width in microseconds to
# distance in millimeters.
d = (t - 1000) * 3 / 4
# Limit minimum distance to 0.
if (d < 0):
d = 0
print(str(d) + ' mm')