Closed cetchells closed 11 years ago
Solder the two middle pins together and it will behave like the 3 pin Ping module :)
@rwaldron with the hc-sr04 being so popular maybe it should have its own special example.
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.
To avoid further confusion I will draw a picture..
This example will work in the following way with the HC-SR04
@divanvisagie :clap:
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!
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.
@cetchells Have you read the docs for Ping devices? hc-sr04 requires special pulseIn support: https://github.com/rwaldron/johnny-five/wiki/Ping#setup
Totally missed that part. RTFD.
Aw, I didn't intend it that way!! Did it work for you? I'm just shooting for 100% success :)
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!
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
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".
@BrianKrohn Can you paste your code and the full text from the error
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.
@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.
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.
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?
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");
});
});
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");
});
});
FYI, I won't have a chance to try this until tomorrow morning.
No worries, I'm patient. I just want to help you solve this :)
The output was:
1424388317856 Connected COM4
1424388317857 Repl Initialized
>> 0
Object is undefinedinches away
Object is undefinedinches away
Object is undefinedinches away
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");
});
});
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?