• [ultrasonic] strange values

hi all, i have noticed that the ultrasonic olugin gives me sometimes high/low peaks. After that i have tried it with this script:

``````#!/usr/bin/python
#+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
#|R|a|s|p|b|e|r|r|y|P|i|-|S|p|y|.|c|o|.|u|k|
#+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
#
# Orginal-Script von Author : Matt Hawkins ultrasonic_2.py
# Measure distance using an ultrasonic module
#
# --------------------------------------------------------
#           Import required Python libraries
# --------------------------------------------------------
#
# Veraendert von Ollir (FHEM-Forum) fuer die Rueckgabe an
# FHEM per Telnet: Port 7072
#

import time
import RPi.GPIO as GPIO
import os
GPIO.setwarnings(False)
# --------------------------------------------------------
#                  Define some functions
# --------------------------------------------------------

def measure():
time.sleep(0.2)
GPIO.output(GPIO_TRIGGER, True)
time.sleep(0.0001)
GPIO.output(GPIO_TRIGGER, False)
while GPIO.input(GPIO_ECHO)==0:
start = time.time()
while GPIO.input(GPIO_ECHO)==1:
stop = time.time()
elapsed = stop - start
distance = elapsed * 17150
if float(distance) >= 400:
distance = measure()
return distance

def measure_average():
# This function takes 3 measurements and
# returns the average.
distance1 = measure()
distance2 = measure()
distance3 = measure()
distance_sum = distance1 + distance2 + distance3
distance = distance_sum / (3*100)
return distance

# --------------------------------------------------------
#                        Main Script
# --------------------------------------------------------
# Use BCM GPIO references
# instead of physical pin numbers

GPIO.setmode(GPIO.BCM)
GPIO_TRIGGER = 15   ####  evtl. GPIO anpassen
GPIO_ECHO    = 14   ####  evtl. GPIO anpassen
GPIO.setup(GPIO_TRIGGER,GPIO.OUT)  # Trigger
GPIO.setup(GPIO_ECHO,GPIO.IN)      # Echo
GPIO.output(GPIO_TRIGGER, False)

# --------------------------------------------------------
#                Rueckgabe an pimatic
# --------------------------------------------------------

distanceRet = "%.2f" % measure_average() # fuer Mittelwert Messung
print distanceRet
#distanceRet = "%.1f" % measure()        # fuer einmalige Messung

GPIO.cleanup()
``````

and the values are very stable. what goes wrong with the plugin? does anyone else have this problems?

sometimes the values go from 0,40 up to 0,74.

maybe someone has an idea to fix this or has an idea what goes wrong.

could someone explain what delay, sample makes if i increase/decrease the values?

this is my pimatic-ultrasonic device:

``````    {
"id": "wasser-hoehe",
"name": "Wasserhöhe",
"class": "Ultrasonic",
"echo": 14,
"trigger": 15,
"timeout": 750,
"delay": 60,
"sample": 5,
"interval": 60000
}``````
• could someone explain what delay, sample makes if i increase/decrease the values?

Hi p4co86,
samples - number of measurements for calculation
delay - delay between these measurements

Plugin uses this module https://github.com/clebert/r-pi-usonic.
Unfortunately, it is deprecated, I have to find a replacement or to write the entire measuring routine.
Looking at it as soon as possible.

Pimatic = Smart Home

• ok thanks for that!

• Pimatic = Smart Home

Posts 4Views 1867

Looks like your connection to pimatic forum was lost, please wait while we try to reconnect.