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 Sun Aug 18, 2019 11:51 am

All times are UTC+01:00

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

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


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


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

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