CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum by 3S-Smart Software Solutions GmbH | A member of the CODESYS Group
Deutsche Version English version russian version 
It is currently Sat Feb 16, 2019 10:21 pm

All times are UTC+01:00




Post new topic  Reply to topic  [ 1 post ] 
Author Message
PostPosted: Sat Apr 14, 2018 9:58 pm 
Offline

Joined: Sun Mar 04, 2018 11:12 pm
Posts: 15
Hello everyone, I’ve made a sensor for my Robot to detect obstacles. Here is my schematic connexion, and python code. But does someone knows how to make it work with Codesys in ST langage? Thank’s a lot. I’ll be very grateful for your help.

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)

print "+-----------------------------------------------------------+"
print "| Mesure de distance par le capteur ultrasonore HC-SR04 |"
print "+-----------------------------------------------------------+"

Trig = 23 # Entree Trig du HC-SR04 branchee au GPIO 23 #trig input
Echo = 24 # Sortie Echo du HC-SR04 branchee au GPIO 24 #echo output

GPIO.setup(Trig,GPIO.OUT)
GPIO.setup(Echo,GPIO.IN)

GPIO.output(Trig, False)

repet = input("Entrez un nombre de repetitions de mesure : ") #Enter a number of repetition

for x in range(repet): # On prend la mesure "repet" fois #we take mesure « repet » time

time.sleep(1) # On la prend toute les 1 seconde #we take it each 1sec

GPIO.output(Trig, True)
time.sleep(0.00001)
GPIO.output(Trig, False)

while GPIO.input(Echo)==0: ## Emission de l'ultrason #Emits Ultrasonic
debutImpulsion = time.time()

while GPIO.input(Echo)==1: ## Retour de l'Echo # Return Echo
finImpulsion = time.time()

distance = round((finImpulsion - debutImpulsion) * 340 * 100 / 2, 1) ## Vitesse du son (sound speed)= 340 m/s

print "La distance est de : ",distance," cm" #the distance is

GPIO.cleanup()


You do not have the required permissions to view the files attached to this post.


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 1 post ] 

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited