View: 10829|Reply: 6

HC-SR04 ultrasonic sensor 2G-IOT

[Copy link]

2

threads

4

posts

26

credits

Novice

Rank: 1

credits
26
Published in 2018-6-1 15:24:57 | Show all floors |Read mode
Using an OPi 2G-IOT,running Ubuntu 2G-IOT GSM OS.
Struggling to get any form of reading on this sensor, I followed this : https://www.piprojects.xyz/ultrasonic-distance-sensor/
and changed the the Trigger pin to Pin 12, but when I run the program , all I get is a distance of 0 cm.
I used a 1Kohm and 2Kohm resistor as mentioned in the thread.

Has any one got this sensor to work with the 2G-IOT ?


10

threads

218

posts

2040

credits

Gold member

Rank: 6Rank: 6

credits
2040
Published in 2018-6-5 18:58:23 | Show all floors
  1. '''
  2. Pin#7:GPIO(56, "in/out")
  3. Pin#16:GPIO(101,"in/out")
  4. Pin#18:GPIO(121,"in/out")
  5. Pin#19:GPIO(4, "in/out")
  6. Pin#21:GPIO(3, "in/out")
  7. Pin#23:GPIO(2, "in/out")
  8. Pin#24:GPIO(5,"in/out")
  9. Pin#26:GPIO(6,"in/out")
  10. Pin#27:GPIO(1, "in/out")
  11. Pin#28:GPIO(0,"in/out")
  12. Pin#29:GPIO(122, "in/out")
  13. Pin#31:GPIO(123, "in/out")
  14. Pin#33:GPIO(124, "in/out")
  15. Pin#35:GPIO(125, "in/out")
  16. Pin#37:GPIO(126, "in/out")
  17. '''

  18. from periphery import GPIO
  19. import time
  20. import datetime


  21. def getCM():
  22.   #Send trig pulse
  23.   gpio_trig.write(True)
  24.   time.sleep(20/1000000.0)
  25.   gpio_trig.write(False)
  26. #  time.sleep(10/1000000.0)

  27.   #Wait for echo start
  28.   while(gpio_echo.read() == 0):
  29.     pass

  30.   #Wait for echo end
  31.   now = datetime.datetime.now()
  32.   startTime = now.microsecond
  33.   while(gpio_echo.read() == 1):
  34.     pass

  35.   now = datetime.datetime.now()
  36.   travelTime = now.microsecond- startTime;
  37.   distance = travelTime / 58;
  38.   return distance

  39. gpio_echo = GPIO(125, "in")
  40. gpio_trig = GPIO(126, "out")

  41. gpio_trig.write(False)
  42. time.sleep(0.03)

  43. while(1):

  44.   dist = getCM()
  45.   print dist
  46.   time.sleep(1.0)
Copy code


orangepi@OrangePi:~/test$ sudo python ./hc-sr04.py
12
14
16
18
19
21
21
23
23
23




2

threads

4

posts

26

credits

Novice

Rank: 1

credits
26
 Author| Published in 2018-6-5 21:52:24 | Show all floors
Hi nopnop2002, Thanks for your input.
I assume youv'e installed periphery python ? I currently have WiringOpi installed.
Do you think I should remove it. ?

10

threads

218

posts

2040

credits

Gold member

Rank: 6Rank: 6

credits
2040
Published in 2018-6-5 22:20:56 | Show all floors
nix666 replied at 2018-6-5 21:52
Hi nopnop2002, Thanks for your input.
I assume youv'e installed periphery python ? I currently have ...



No
You don't have to remove WiringOP.

2

threads

5

posts

30

credits

Novice

Rank: 1

credits
30
Published in 2022-11-24 18:02:33 | Show all floors
Dukane Seacom TS500 ULB Ultrasonic Test Set is a quality machine that is easy to use if you are an expert.

0

threads

4

posts

12

credits

Novice

Rank: 1

credits
12
Published in 2022-12-9 12:30:05 | Show all floors
Why couldn't I have the same or similar opinions as you?   T^T I hope you also visit my blog and give us a good opinion.  safetoto

0

threads

9

posts

28

credits

Novice

Rank: 1

credits
28
Published in 2023-9-19 13:00:25 | Show all floors
geometry dash world is a 2D platform game in which you control a square that has to get to the end of each level while avoiding a lot of hazards. Your little square keeps moving forward, so all you have to do to avoid the different hazards is jump at the right time
You need to log in before you can reply login | Register

Points Rule

Quick reply Top Return list