From owner-freebsd-arm@FreeBSD.ORG Tue Aug 26 19:27:14 2014 Return-Path: Delivered-To: freebsd-arm@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id E96A09C0 for ; Tue, 26 Aug 2014 19:27:14 +0000 (UTC) Received: from mail-wi0-x230.google.com (mail-wi0-x230.google.com [IPv6:2a00:1450:400c:c05::230]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 79D4D3F2C for ; Tue, 26 Aug 2014 19:27:14 +0000 (UTC) Received: by mail-wi0-f176.google.com with SMTP id bs8so4738983wib.15 for ; Tue, 26 Aug 2014 12:27:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=w+E+8gJiM7bETNFV/SM2Duw//IXWpsAZWD72kJA5764=; b=rHRy39mJ2mFE1s6BVBs0hUSEtnrGWavIyHDixEj8gK+X3AyPECqdSQTtPM2cg0edSB ITwKHa2UdneEDqJdxVJ0Qfil9zbTaj+EdtqB2gGPiRRcUkc8dfJHy1OnkYrwhQj04LkS xnenkWVUHPayTPwdQugtfSnqg4Kqf48oGO0GZHRhckmNFyF4YW6hKulupgc6EVxHTJZe 44nBko8YxAzuvOZyZGw9lew0t4XUhMwRKR4ed4WoZsOyBHZ447G6LUl1efo7MXGoXLbB RsGZHFaiZnDka/ety5Ct+FdqMl/z7WOt6fNZwDOs8HkwVOflUgWxrTGeleL8Lt5k1N6n 8Dqw== MIME-Version: 1.0 X-Received: by 10.180.92.73 with SMTP id ck9mr24031583wib.54.1409081232661; Tue, 26 Aug 2014 12:27:12 -0700 (PDT) Received: by 10.216.199.70 with HTTP; Tue, 26 Aug 2014 12:27:12 -0700 (PDT) In-Reply-To: <3949AF9C-B5BD-44E8-A049-21F26B8B6B9A@freebsdbrasil.com.br> References: <5D802942-2D0F-4324-8212-C2871EEB6327@FreeBSD.org> <01562FB1-32C6-45AF-AB77-5BB80526E18C@FreeBSD.org> <53F8FED8.6030409@freebsdbrasil.com.br> <3949AF9C-B5BD-44E8-A049-21F26B8B6B9A@freebsdbrasil.com.br> Date: Tue, 26 Aug 2014 16:27:12 -0300 Message-ID: Subject: Re: HC-SR04 and FreeBSD From: Luiz Otavio O Souza To: Patrick Tracanelli Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: "freebsd-arm@freebsd.org" , Rui Paulo X-BeenThere: freebsd-arm@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: "Porting FreeBSD to ARM processors." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 26 Aug 2014 19:27:15 -0000 On 25 August 2014 16:57, Patrick Tracanelli wrote: > On 24/08/2014, at 19:29, Evandro Nunes wrote: >>> On Sat, Aug 23, 2014 at 5:51 PM, Patrick Tracanelli wrote: >> Hello, >> >> As far as I know, for this specific ultrasonic sensor, you are missing >> to set the echo GPIO pin to high. This sonar sensor will bring it back >> to 0 when the triggered sound get back to the sensor (round-trip). >> >> So the correct sequence should be, in a loop: >> >> 1 - Set echo pin to HIGH >> 2 - Trigger the sensor for 10us (it means your 100ms is more than you >> need, but no, it won=E2=80=99t cause a problem) >> 3 - Wait until echo in is LOW >> >> When the sound come back to sensor, the device will LOW the GPIO pin aga= in. No, this is not correct, setting a value to an input is a noop and when you need this kind of cooperation from both sides, you usually will be using a pull-up and open colector outputs (they never drive the output to 'high' to avoid short-circuits). [...] > > What you wanna do is to measure how long HIGH takes. > > I just made a better test so you can actually "see" the sensor working. R= un this more simple loop: > > gpioctl -c 2 IN > gpioctl -c 3 OUT > gpioctl 3 0 > > while true ; do > gpioctl 3 1 ; sleep .10; gpioctl 3 0 > while [ $(gpioctl 2 | tail -1) -gt 0 ] ; do > echo "..." #nada > done > sleep 1 > done > > On a second shell, run this horrible cpu consuming loop: > > sh -c "while true ; do /root/date-precisao && gpioctl 2 ; done" This one is okay, > > And check for the date when PIN 2 becomes high and later when it becomes = low again. > > Speed of sound is 340 meters per second. Since this sensor measures round= -trip, you shall divide by two, so here is a simple measurement by hand: > > An object added 1 meter from sensor: > > (eksffa@localhost):~% echo "((999013225427212-999013225364525)/340)/2" | = bc > 92 > > An object added 2 meters from sensor: > > (eksffa@localhost):~% echo "((999013003943898-999013003811223)/340)/2" | = bc > 195 > > So, now you have a better precision, but insanely high CPU usage due to t= he second loop. > > Yes, you are right, I personally agree some library with basic electronic= functions would be very valuable to FreeBSD. > > Good to read you will try to write something, I believe Rui Paulo's libra= ry is a good start to hack, reading GPIO device, detecting when a PIN is HI= GH and measuring the time until it becomes LOW is probably a good starter c= hallenge ;-) What we need is interrupt support so you don't need to keep reading the GPIO pin in a busy loop and just get notified when the pin change its state. I hope i can get this sorted out soon (it is being worked on). > > One sensor I am trying to make work is DHT11 temperature and humidity, ac= cording to datasheet[1] on section 7, this "single-wire bi-directional" sen= sor seems to return a 32bit value which shall be calculated in 4 octets. I can help you with the DHT11. I have some DHT11 working with an AVR bridge which gives me the DHT11 data through I2C, this make the readings reliable. I hope GPIO eventually grow up so i can get rid of the AVR bridge. There are 5 octets with the Parity. > This is a kind of sensor that deserves a library for sure (and FreeBSD de= serves to have such a library) but hopefully not the kind of Arduino librar= y which is device specific. A more generic library that reads a selectable = 8/16/32bit value and returns it in different formats (decimal, hex, ...) wo= uld do the job for this sensor as well as other single-wire pin sensors. A generic library isn't always possible because each device encodes the data in its own format, the DHT11(/DHT22) is different than onewire and so on, but a good driver (if possible) for DHT11 would be useful. > > [1]http://akizukidenshi.com/download/ds/aosong/DHT11.pdf Luiz