Page 1 of 1

HCSR04 module usage

Posted: Thu Jun 08, 2017 10:32 am
by Del
I have put the hcsr04.py module from https://github.com/rsc1975/micropython-hcsr04 on my nodemcu v2 board with ampy and can see it but am unable to import hcsr04.

How should this be done?

Error message as follows

>>> from hcsr04 import HCSR04
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name HCSR04

Re: HCSR04 module usage

Posted: Thu Jun 08, 2017 4:44 pm
by jwissing
It is the reference to the class variable TIMEOUT_US in the __init__ method.

def __init__(self, trigger_pin, echo_pin, echo_timeout_us=HCSR04.TIMEOUT_US):

Delete the class name HCSR04 from the default value.

def __init__(self, trigger_pin, echo_pin, echo_timeout_us=TIMEOUT_US):

Re: HCSR04 module usage

Posted: Thu Jun 08, 2017 10:18 pm
by Del
Thanks will try that tonight and advise of outcome:)

Re: HCSR04 module usage

Posted: Fri Jun 09, 2017 2:46 pm
by pythoncoder
A common Python "gotcha". Assuming the driver works when changed, it might be worth raising an issue.