rwaldron / johnny-five

JavaScript Robotics and IoT programming framework, developed at Bocoup.
http://johnny-five.io
Other
13.28k stars 1.76k forks source link

Sonar 4pin moudule #235

Closed cetchells closed 11 years ago

cetchells commented 11 years ago

I have a 4pin sonic module - hc-sr04. The pins are marked vcc,trig,echo,grd. I get a signal on echo, but its constant 0.5 inches. I guess I need the trig wired up. Any ideas, or can we add support for this module?

rwaldron commented 11 years ago

Solder the two middle pins together and it will behave like the 3 pin Ping module :)

divanvisagie commented 11 years ago

@rwaldron with the hc-sr04 being so popular maybe it should have its own special example.

cetchells commented 11 years ago

I couldn't get your suggestion to work. Rather than solder, I wired the middle 2 to 1 on a breadboard.Should that work too? (my soldering skills are zero) This did: http://arduinobasics.blogspot.co.uk/2012/11/arduinobasics-hc-sr04-ultrasonic-sensor.html If that helps.

divanvisagie commented 11 years ago

To avoid further confusion I will draw a picture..

This example will work in the following way with the HC-SR04 untitled sketch_bb

rwaldron commented 11 years ago

@divanvisagie :clap:

rwaldron commented 11 years ago

Add a file: eg/hc-sr04.js that contains the same JavaScript shown in the hc-sr04.md file and then add an entry to programs.json here: https://github.com/rwaldron/johnny-five/blob/master/programs.json#L47-L50 then land it!

cetchells commented 11 years ago

Still can't get this to work. data is 'undefined'. Anyone else confirm working? I've ordered another hc-sr04. Could me mines a dud.

rwaldron commented 11 years ago

@cetchells Have you read the docs for Ping devices? hc-sr04 requires special pulseIn support: https://github.com/rwaldron/johnny-five/wiki/Ping#setup

cetchells commented 11 years ago

Totally missed that part. RTFD.

rwaldron commented 11 years ago

Aw, I didn't intend it that way!! Did it work for you? I'm just shooting for 100% success :)

cetchells commented 11 years ago

It 100% works. Loving your work btw, thanks. C3PO can kinda see now, he'd say thanks too, but he has no mouth, just 2 eyes not much else...for now!

rwaldron commented 11 years ago

Awesome!! I just added support for several new IR Distance sensors you might want to check out https://github.com/rwaldron/johnny-five/commit/65b913fcb261e3633bf4a3ef07fc3550c4fc4ef8#diff-1

BrianKrohn commented 9 years ago

I just followed the instructions on the Ping page to enable ping using the copy/paste of the code listed there and uploading. The sensor returns "Object is undefined".

dtex commented 9 years ago

@BrianKrohn Can you paste your code and the full text from the error

BrianKrohn commented 9 years ago

I am using the nodejs code from the Usage section: https://github.com/rwaldron/johnny-five/wiki/Ping I am using the Firmata modifications at the bottom of that page (from the section titled "Or..."). Everything runs, but the code outputs "Object is undefinedinches away". I am using an HC-SR04 module wired as described on the page.

rwaldron commented 9 years ago

@BrianKrohn I just followed your steps and can't reproduce. The thing that's bugging me is that there is no way that this.in or this.inches would be undefined, because they are always defined. Even if the internal value is null, the value returned by those accessors would be 0. Any other information you can provide would helpful.

BrianKrohn commented 9 years ago

Sorry, but that's it. Being relatively new to this, I tried to stick to your instructions. Could it be an issue with the Firmata code on that page? I pasted it as-is into the Arduino IDE, and it uploaded without error. After uploading I was able to run simple nodejs scripts to strobe an LED and read from a pot.

rwaldron commented 9 years ago

Could it be an issue with the Firmata code on that page?

No, I just used the same code with no issues

...

Can you paste your exact JS code that's running when this issue is encountered?

BrianKrohn commented 9 years ago
var five = require("johnny-five");
var board = new five.Board({port:"COM4"});

board.on("ready", function() {

  var ping = new five.Ping(7);

  // ping.in
  //
  // Calculated distance to obstruction in inches
  //

  // ping.cm
  //
  // Calculated distance to obstruction in centimeters
  //

  ping.on("change", function(err, value) {
    console.log("Object is " + this.in + "inches away");
  });

});
rwaldron commented 9 years ago

Run this and paste the output:

var five = require("johnny-five");
var board = new five.Board({port:"COM4"});

board.on("ready", function() {

  var ping = new five.Ping(7);

  console.log(ping.inches);

  ping.on("change", function(err, value) {
    console.log("Object is " + this.in + "inches away");
  });

});
BrianKrohn commented 9 years ago

FYI, I won't have a chance to try this until tomorrow morning.

rwaldron commented 9 years ago

No worries, I'm patient. I just want to help you solve this :)

BrianKrohn commented 9 years ago

The output was:

1424388317856 Connected COM4
1424388317857 Repl Initialized
>> 0
Object is undefinedinches away
Object is undefinedinches away
Object is undefinedinches away
rwaldron commented 9 years ago

Ok, try this then:

var five = require("johnny-five");
var board = new five.Board({port:"COM4"});

board.on("ready", function() {
  var ping = new five.Ping(7);

  ping.on("change", function(err, value) {
    console.log("Object is " + this.inches + "inches away");
  });
});