Guru Meditation Error of type LoadProhibited occurred on core.
-
I think my issue might actaully be related to this post: https://forum.pycom.io/topic/1061/https-post-using-urequests-py-and-guru-mediation-error
the urequest class and nothing to do with the ultrasonic sensor.
-
@tobz Ah ok, you are using the urequests library? We're looking into this.
Thanks!
-
@bucknall Cool. I'll follow along with that thread & hopefully that IS my issue and it gets resolved :)
-
@tobz Did you manage to get the HC-SR04 working after all?
-
@RobTuDelft yeah the sensor works fine (once I worked out you need a resistor in the circuit - derp). The crash appears to be caused by the urequest library (see https://forum.pycom.io/topic/1061/https-post-using-urequests-py-and-guru-mediation-error).
-
@tobz That's nice, could you share your code perhaps? Got one of these sensors coming in soon and would help to have a starting point.
-
@RobTuDelft sorry - I've been head down in work - will hopefully get some time later this week & post my code if you're still interested in it.
-
@RobTuDelft Here's the code I was using for the HC-SR04.
I hope it makes sense & works for you.import machine import time import math from machine import Timer class Ultrasonic: 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) self.trigger.init(machine.Pin.OUT, None) self.trigger.value(False) # Init echo pin (in) self.echo = machine.Pin(self.echoPin) self.echo.init(machine.Pin.IN) def distance_in_inches(self): return (self.distance_in_cm() * 0.3937) def distance_in_cm(self): start = 0 end = 0 # Create a microseconds counter. micros = Timer.Chrono() micros.reset() micros.start() # Send a 10us pulse. self.trigger.value(True) Timer.sleep_us(10) self.trigger.value(False) # 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 micros.stop() # 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 return dist_in_cm def start(self, threshold, callback): print('Start reading Ultrasonic Sensor') while True: # 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 else: print("%s value: %s <-> %s at %s" % (self.name, self.last_distance, distance, time.time())) time.sleep(self.delay)useage:
// init sensor, reading every 60 seconds sensor = Ultrasonic('some-name', triggerPin, echoPin, 60) sensor.start(changeThreshold, callbackMethod) -
@tobz Thanks a lot for sharing the code. How did you connect the sensor to the board? You mentioned something about a resistor you had to use?
-
@tobru From memory I think it was a 10k resister - check the spec sheet for the HC-SR04. I probably just attached it straight onto the expansion board, maybe via a breadboard - I can't remember sorry.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login