I managed to find a USB-to-serial adapter and tried some things with that. My Windows machine won't recognize it, and on my mac I can't figure out what tty port it's on. I did however dig out a Raspberry Pi where it seem to work.
Unfortunately it didn't help, because the linux-version of the pycom updater just keeps saying "Something failed trying to connect to the device." and then gives no further info.
I also tried modifying the baud rate in the updater.py script as some thread suggested, but no luck.
@RobTuDelft Here's the code I was using for the HC-SR04.
I hope it makes sense & works for you.
from machine import Timer
def __init__(self, name, trigPin, echoPin, delay = 60):
self.name = name
self.triggerPin = trigPin
self.echoPin = echoPin
self.delay = delay
self.last_distance = 0
# Init trigger pin (out)
self.trigger = machine.Pin(self.triggerPin)
# Init echo pin (in)
self.echo = machine.Pin(self.echoPin)
return (self.distance_in_cm() * 0.3937)
start = 0
end = 0
# Create a microseconds counter.
micros = Timer.Chrono()
# Send a 10us pulse.
# Wait 'till whe pulse starts.
while self.echo.value() == 0:
start = micros.read_us()
# Wait 'till the pulse is gone.
while self.echo.value() == 1:
end = micros.read_us()
# Deinit the microseconds counter
# Calc the duration of the recieved pulse, divide the result by
# 2 (round-trip) and divide it by 29 (the speed of sound is
# 340 m/s and that is 29 us/cm).
dist_in_cm = ((end - start) / 2) / 29
def start(self, threshold, callback):
print('Start reading Ultrasonic Sensor')
# get the current distance
distance = self.distance_in_cm()
# if the distance between this reading and the previous one
# and the difference is greater than the threshold then
# run the callback method
if (math.fabs(self.last_distance - distance) > threshold):
print("%s value: %s -> %s at %s" % (self.name, self.last_distance, distance, time.time()))
if callback(self.name, distance) is True:
# set this readding as the previous reading for next run
self.last_distance = distance
print("%s value: %s <-> %s at %s" % (self.name, self.last_distance, distance, time.time()))