bbcmicrobit / micropython

Port of MicroPython for the BBC micro:bit
https://microbit-micropython.readthedocs.io
Other
603 stars 284 forks source link

Micro:Bit v2 unresponsive on machine.time_pulse_us #704

Closed tbeattyISB closed 3 years ago

tbeattyISB commented 3 years ago

Trying to get an ultrasonic (HC-SR04( sensor up and running the following script works well on my V1 board. but not V2, any ideas?


class UltrasonicSensor:
    def __init__(self):
        pin1.write_digital(0)
        pin2.read_digital()
        pin2.set_pull(pin2.NO_PULL)
    def distance(self):
        pin1.write_digital(0)
        utime.sleep_us(2)
        pin1.write_digital(1)
        utime.sleep_us(10)
        pin1.write_digital(0)             
        d = time_pulse_us(pin2,1,11600)
        if d>0:
            return d/58
        else:
            return d

sleep(100)

ultraSonic = UltrasonicSensor()

while True:
    print(ultraSonic.distance())
    sleep(100)
microbit-carlos commented 3 years ago

Thanks for the report @tbeattyISB, we are currently tracking this issue in the MicroPython for micro:bit V2 repository here: https://github.com/microbit-foundation/micropython-microbit-v2/issues/26