nix666 post at 2018-6-1 15:24:57

HC-SR04 ultrasonic sensor 2G-IOT

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 ?


nopnop2002 post at 2018-6-5 18:58:23

'''
Pin#7:GPIO(56, "in/out")
Pin#16:GPIO(101,"in/out")
Pin#18:GPIO(121,"in/out")
Pin#19:GPIO(4, "in/out")
Pin#21:GPIO(3, "in/out")
Pin#23:GPIO(2, "in/out")
Pin#24:GPIO(5,"in/out")
Pin#26:GPIO(6,"in/out")
Pin#27:GPIO(1, "in/out")
Pin#28:GPIO(0,"in/out")
Pin#29:GPIO(122, "in/out")
Pin#31:GPIO(123, "in/out")
Pin#33:GPIO(124, "in/out")
Pin#35:GPIO(125, "in/out")
Pin#37:GPIO(126, "in/out")
'''

from periphery import GPIO
import time
import datetime


def getCM():
#Send trig pulse
gpio_trig.write(True)
time.sleep(20/1000000.0)
gpio_trig.write(False)
#time.sleep(10/1000000.0)

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

#Wait for echo end
now = datetime.datetime.now()
startTime = now.microsecond
while(gpio_echo.read() == 1):
    pass

now = datetime.datetime.now()
travelTime = now.microsecond- startTime;
distance = travelTime / 58;
return distance

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

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

while(1):

dist = getCM()
print dist
time.sleep(1.0)


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




nix666 post at 2018-6-5 21:52:24

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. ?

nopnop2002 post at 2018-6-5 22:20:56

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.

Morisa post at 2022-11-24 18:02:33

Dukane Seacom TS500 ULB Ultrasonic Test Set is a quality machine that is easy to use if you are an expert.

asstuctuc post at 2022-12-9 12:30:05

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

arrangedig post at 2023-9-19 13:00:25

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
page: [1]
View full version: HC-SR04 ultrasonic sensor 2G-IOT