HCSR04 module usage

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
Del
Posts: 6
Joined: Sat Jun 03, 2017 10:41 am

HCSR04 module usage

Post by Del » Thu Jun 08, 2017 10:32 am

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

User avatar
jwissing
Posts: 29
Joined: Thu Jun 19, 2014 12:23 pm
Location: Germany

Re: HCSR04 module usage

Post by jwissing » Thu Jun 08, 2017 4:44 pm

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):

Del
Posts: 6
Joined: Sat Jun 03, 2017 10:41 am

Re: HCSR04 module usage

Post by Del » Thu Jun 08, 2017 10:18 pm

Thanks will try that tonight and advise of outcome:)

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: HCSR04 module usage

Post by pythoncoder » Fri Jun 09, 2017 2:46 pm

A common Python "gotcha". Assuming the driver works when changed, it might be worth raising an issue.
Peter Hinch
Index to my micropython libraries.

Post Reply