From owner-freebsd-arm@FreeBSD.ORG Fri Aug 22 19:55:16 2014 Return-Path: Delivered-To: freebsd-arm@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 96DF1D69 for ; Fri, 22 Aug 2014 19:55:16 +0000 (UTC) Received: from mail-wg0-x22e.google.com (mail-wg0-x22e.google.com [IPv6:2a00:1450:400c:c00::22e]) (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 2BEBA3D33 for ; Fri, 22 Aug 2014 19:55:16 +0000 (UTC) Received: by mail-wg0-f46.google.com with SMTP id m15so10870494wgh.5 for ; Fri, 22 Aug 2014 12:55:14 -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; bh=+XRkNSiLM4SkOK8g6X+jGNfKmc40V6hf5IWSgRy1t6k=; b=ZTeLpliiFnk9Mhn37OxwE6XDMV5E5pmTsnGx9HbzuJsv45FxOEgfPJLi/3AawdWLO8 mLoOjWinyN21Eeyg4DyFABnJ4fvASgwp6buV2kZ+NoanvNRsLaVux+FZuaQbos1APPuu g9HiQblctoXbBOqqS1yGh+7EeZIKxypi068hM5e0tSn+IL4jtWQ0uJzdpl2NIPoZz194 jORnJzWrfok29m3xJBA6wY8/exqHtLIORr/Qwx1XS1r5lZlByA8/ZcNukjCNPh53fEQA MNq/2Sl4VSQkoPGDsjf+H6qQRGRZ7eaebOkaSa4maon47QuOEHgBNl79xtogHTCE/ELN LI9A== MIME-Version: 1.0 X-Received: by 10.180.106.8 with SMTP id gq8mr577618wib.56.1408737314327; Fri, 22 Aug 2014 12:55:14 -0700 (PDT) Received: by 10.216.199.70 with HTTP; Fri, 22 Aug 2014 12:55:14 -0700 (PDT) In-Reply-To: References: <5D802942-2D0F-4324-8212-C2871EEB6327@FreeBSD.org> <01562FB1-32C6-45AF-AB77-5BB80526E18C@FreeBSD.org> Date: Fri, 22 Aug 2014 16:55:14 -0300 Message-ID: Subject: Re: HC-SR04 and FreeBSD From: Luiz Otavio O Souza To: Evandro Nunes Content-Type: text/plain; charset=UTF-8 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: Fri, 22 Aug 2014 19:55:16 -0000 On 22 August 2014 00:43, Evandro Nunes wrote: > On Thu, Aug 21, 2014 at 4:13 PM, Rui Paulo wrote: > >> You can use an led instead of a multimeter. The point I'm trying to make >> is to make sure the gpio number really corresponds to that port number. >> > > still no success, but just an update... > > ok I added two led: > > pin 02: 0 gpio_2 ===> echo (orange LED) > pin 03: 0 gpio_3 ===> trigger (blue LED) > pin 49: 0 gpio_49 ===> previous echo > > and I have the two simple loops below. > > when I run loop1, BLUE LED blinks every second; > when I run loop2 while loop1 stills run, ORANGE LED won't blink, and loop2 > value still shows 0 value > > if I "gpioctl -c 2 OUT ; gpioctl -t 2", ORANGE LED will light, confirming > LED is OK; thoses leds will light with 2-5v input... however I have no idea > if the sonar output will range 2-5 or if it will be below 2 (i tried adding > my hand very close and far away from the sensor but led was never lit) Probably the echo output doesn't provide enough current to drive the LED (LEDs are driven by current and not by voltage). Be aware that you also need to limit the voltage on the sensor output to be within the 3.3V limit: https://www.modmypi.com/blog/hc-sr04-ultrasonic-range-sensor-on-the-raspberry-pi (you can can follow the explanation and the schematics) > > so I'd better use a multimeter for sure... You'd be better with a logic analyser, this kind of short pulses can't be seen on a multimeter. > > loop1: > while true ; do > gpioctl -t 3; sleep .200; gpioctl -t 3 > #gpioctl 3 > sleep 1 > done > > loop2: > while true ; do > gpioctl 2 > sleep .500 > done > The sensor output pulse will be active for a period of 116us ~ 23200us (2cm ~ 400cm, given the formula from data sheet: cm = us / 58). I'm not sure you can reliably measure such short periods from userland (but as the RPi link says it works... let's try it). You can try to remove the LED from the echo pin (to reduce its load) and reduce the sleep time on loop2 to see if you can read the sensor output. I'll see if i can get my hands on HC-SR04 so i can try it out. Luiz