View: 1545|Reply: 7

Issues with Ultrasonic Sensor

[Copy link]

1

Threads

4

Posts

18

Credits

Newbie

Rank: 1

Credits
18
Post time 2019-4-20 17:39:59 | Show all posts |Read mode


Hi there,

I'm trying to access the ultrasonic sensor, but with no luck. I'm just using the code in servers/ultra.py, but the GPIO.input(Ec) lines always returns 0. I've tried a different HC-SR04 from another kit and I'm having the same issue.

Can you give me some troubleshooting tips? Not sure how to proceed.

- Dave
Reply

Use magic Report

0

Threads

5

Posts

39

Credits

Newbie

Rank: 1

Credits
39
Post time 2019-4-22 12:34:12 | Show all posts
you need to set the Tr as HIGH again, or the Ec will continue to read the data from Tr.
------------
you can simply use the code below to get the distance information.

import ultra
distance = ultra.cheeckdist()
------------
if you don't want to keep read 0 from Ec, you can edit the ultra.py by adding 'GPIO.output(Tr, GPIO.HIGH)' after line 27 t2 = time.time()

like this:
def checkdist():       #Reading distance
    GPIO.setwarnings(False)
    GPIO.setmode(GPIO.BOARD)
    GPIO.setup(Tr, GPIO.OUT,initial=GPIO.LOW)
    GPIO.setup(Ec, GPIO.IN)
    GPIO.output(Tr, GPIO.HIGH)
    time.sleep(0.000015)
    GPIO.output(Tr, GPIO.LOW)
    while not GPIO.input(Ec):
        pass
    t1 = time.time()
    while GPIO.input(Ec):
        pass
    t2 = time.time()
    GPIO.output(Tr, GPIO.HIGH)     ###<<<add it here
    return (t2-t1)*340/2
Reply

Use magic Report

1

Threads

4

Posts

18

Credits

Newbie

Rank: 1

Credits
18
 Author| Post time 2019-4-22 13:14:12 | Show all posts
Thank you for the reply.

I'm still having trouble. Here's my code for checkdist():

def checkdist():       #Reading distance
    GPIO.setwarnings(False)
    GPIO.setmode(GPIO.BOARD)
    GPIO.setup(Tr, GPIO.OUT,initial=GPIO.LOW)
    GPIO.setup(Ec, GPIO.IN)
    GPIO.output(Tr, GPIO.HIGH)
    time.sleep(0.000015)
    GPIO.output(Tr, GPIO.LOW)
    print(1)
    while not GPIO.input(Ec):
        pass
    print(2)
    t1 = time.time()
    while GPIO.input(Ec):
        pass
    print(3)

    t2 = time.time()
    GPIO.output(Tr, GPIO.HIGH)     
    return (t2-t1)*340/2

And I invoke it like this:

import ultra
print(ultra.checkdist())  

which returns "0" and then hangs.

Any ideas?
Reply

Use magic Report

1

Threads

4

Posts

18

Credits

Newbie

Rank: 1

Credits
18
 Author| Post time 2019-4-26 09:39:43 | Show all posts
Is anyone from Adeept monitoring this forum? It would be good to get some ideas on how to proceed with this.
Reply

Use magic Report

23

Threads

223

Posts

814

Credits

Senior member

Rank: 4

Credits
814
Post time 2019-4-26 16:24:14 | Show all posts
107 replied at 2019-4-26 09:39 AM
Is anyone from Adeept monitoring this forum? It would be good to get some ideas on how to proceed wi ...

Hello,

Maybe the ultrasonic module is damaged, please contact our customer service team and provide your order number, we will send you a new sensor for free.

email: service@adeept.com

THX!
Reply

Use magic Report

7

Threads

47

Posts

661

Credits

Senior member

Rank: 4

Credits
661
Post time 2019-4-26 18:02:25 | Show all posts
107 replied at 2019-4-22 01:14 PM
Thank you for the reply.

I'm still having trouble. Here's my code for checkdist():

You can check if the wire connecting the ultrasonic module is loose, it is likely that the wire is loose, resulting in data reception error.
Reply

Use magic Report

1

Threads

4

Posts

18

Credits

Newbie

Rank: 1

Credits
18
 Author| Post time 2019-5-4 08:03:06 | Show all posts
1501915115 replied at 2019-4-26 06:02 PM
You can check if the wire connecting the ultrasonic module is loose, it is likely that the wire is ...

I've definitely checked all the wiring, it's not the problem.
Reply

Use magic Report

0

Threads

8

Posts

22

Credits

Newbie

Rank: 1

Credits
22
Post time 2021-6-17 09:42:33 | Show all posts
I thought I am the only one who is having some issues on running the Ultrasonic Sensor, replacing the HC-SR04 from another kit also doesn't work for me. Is there anyone out there who have experience this thing and fix it? We badly needed some help because this is my first time on using this kit. download here for free and start slashing your opponents using your sword, there are different skills of your characters that you can use to clear the wave of monsters!

emulatorpc.com/8-ball-pool/
Reply

Use magic Report

You have to log in before you can reply Login | Sign Up

Points Rules