Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proximity - HC-SR04 issue #896

Closed
carloscarcamo opened this issue Aug 28, 2015 · 35 comments
Closed

Proximity - HC-SR04 issue #896

carloscarcamo opened this issue Aug 28, 2015 · 35 comments

Comments

@carloscarcamo
Copy link

I'm getting this warning:

$ node app.js
1440742786705 Device(s) /dev/ttyACM0  
1440742786716 Connected /dev/ttyACM0  
1440742790038 Repl Initialized  
>> distance 4356.718
distance 33.505
distance 34.588
distance 4358.746
distance 4355.12
distance 4356.701
distance 4357.216
distance 4354.639
distance 0
distance 4356.22
distance 4354.931
distance 0
(node) warning: possible EventEmitter memory leak detected. 11 ping-read-7 listeners added. Use emitter.setMaxListeners() to increase limit.
Trace
    at addListener (events.js:179:15)
    at once (events.js:204:8)
    at Board.pingRead (/home/user/workspace/node/NodeBots/tests/node_modules/johnny-five/node_modules/firmata/lib/firmata.js:1334:8)
    at Proximity.<anonymous> (/home/user/workspace/node/NodeBots/tests/node_modules/johnny-five/lib/proximity.js:175:19)
    at wrapper [as _onTimeout] (timers.js:265:14)
    at Timer.listOnTimeout (timers.js:110:15)
distance 4356.151
distance 4355.137
distance 4355.653

I don't know if i'm doing something wrong, i'm using this simple code:

var five = require('johnny-five'),
  board = new five.Board(),
  proximity = undefined;

board.on('ready', function(){  
  proximity = new five.Proximity({
    controller: 'HCSR04',
    pin: 7
  });

  proximity.on('change', function(){
    console.log('distance', this.cm);    
  });
});

Is this normal or there is any problem?

Thanks in advance!

@topkoa
Copy link

topkoa commented Aug 28, 2015

I've had this issue before.

If it helps at all I did not experience this with the more expensive "Parallax Ping Ultrasonic Range Sensor 28015", I ordered the "WYPH Ultrasonic Module HC-SR04" and had the issue that is mentioned above...

I've got a whole mess of these things I'd like to use so I'm quite interested if there is any resolution to this as well!

@rwaldron
Copy link
Owner

Did you load the correct firmware onto the board? These sensor require the custom PingFirmata provided in the docs

@topkoa
Copy link

topkoa commented Aug 28, 2015

In my case; I tried re-uploading that firmata several times. I switched back and forth between the two models of ping sensors as well. I haven't had it on the test bench in a few weeks but I can fire it back up and try is again this weekend.

@rwaldron
Copy link
Owner

I have several models of this same sensor, which were used to test and confirm support and all of them work correctly.

@carloscarcamo @topkoa can you both post pictures of your actual hardware? Thanks!

@topkoa
Copy link

topkoa commented Aug 28, 2015

I sure will. I won't have an opportunity until tomorrow afternoon though.

@rwaldron
Copy link
Owner

Thanks! Be sure to @-ping me when you post :)

@carloscarcamo
Copy link
Author

@rwaldron yes, I've loaded the PingFirmata.
I'm using this model:

http://www.icstation.com/arduino-ultrasonic-module-sr04-distance-transducer-sensor-p-1389.html

Maybe the quality of the sensor is what cause the warning, maybe I need to buy a better sensor.

@topkoa
Copy link

topkoa commented Aug 28, 2015

I think I have the same model (looks identical, same pins).

I did buy that model for a couple reasons:

  1. J5 is documented to support it, and:
  2. Super cheap! (as opposed to the Parallax version (~$30 bux!)

I had the same feeling as you.. Maybe too cheap to be true? I guess we will see though.

I have a feeling Rick will know what's up. :)

@rwaldron
Copy link
Owner

Have you both included a jumper that connects the Echo and Trigger pins?

@topkoa
Copy link

topkoa commented Aug 28, 2015

I'll have to check my test rig; however I believe it was indeed jumped.

@carloscarcamo
Copy link
Author

yes! I did it!, as this diagram suggests:

http://johnny-five.io/api/proximity/#hcsr04parallax-ping-

@topkoa
Copy link

topkoa commented Aug 28, 2015

Nice! -- I'll still give it a check on my bench too when I get home tomorrow.

@topkoa
Copy link

topkoa commented Aug 28, 2015

Welp; I got home early. Just tried it and am getting the same problem...

I have it wired exactly as the diagram indicates and with the correct PingFirmata installed.

I have both ping sensors hooked up as well; (both the Parallax and the Generic).

Here's a PIC:
img_0818

When I run the program, the generic ping sensor works for a few seconds then I get the same error as above. When I change the pin to use the Parallax ping it works flawlessly.

Let me know if there is anything I can try.

@topkoa
Copy link

topkoa commented Aug 28, 2015

Here is the wiring for both:

img_0819
img_0820

@topkoa
Copy link

topkoa commented Aug 28, 2015

Another update: I swapped out the Generic ping sensor with another with the same results. Ruling out a faulty sensor. (I got a pack of 10 of them).. I only have one of the Parallax ping sensors, but that one seems to work just fine as stated above.

@rwaldron
Copy link
Owner

Thanks for the follow up. Historically, the error you're seeing has been the result of insufficient power flow to the connected component. Let's try to reduce this as much as possible.

  • Remove everything from your Arduino
  • Connect only the 4 pin HCSR04 (as shown in that diagram)
  • Do not jump the 5V and GND from breadboard rails, plug those in directly to 5V and GND

If this doesn't correct the problem, then please take another picture of the complete circuit, which should show:

  • Arduino
    • Power jumpers
    • Signal jumper
  • Breadboard + Ping sensor

@rwaldron
Copy link
Owner

Also, this is an interesting read: https://forum.sparkfun.com/viewtopic.php?f=42&t=40513

@carloscarcamo
Copy link
Author

Ok. I will try later and post my results.
I think this time will work correctly :)
Yesterday I tested the ultrasonic sensor with pure C code with the arduino IDE and it worked perfectly, this was the diagram:

hc_sr04 sketch2

And the C code:

https://gist.github.com/carloscarcamo/2d2bf6a22ef8c7f081a1

@rwaldron
Copy link
Owner

@carloscarcamo can you try exactly as I describe here #896 (comment) Thanks!

@carloscarcamo
Copy link
Author

Sure, I will do it when I get home in a couple of hours :)

@topkoa
Copy link

topkoa commented Aug 29, 2015

So I did what you said, wired exactly as you indicated. I also used a multimeter and the voltage us a steady 4.92.

I'll post some pics soon for you to verify.

From reading that thread it looks like they are just garbage. Hah.

Maybe put a warning in the wiki?

Want me to mail you one so you can see for yourself?

@rwaldron
Copy link
Owner

Maybe put a warning in the wiki?

Probably a good idea.

Want me to mail you one so you can see for yourself?

I have soooo many of these—but all of mine work correctly. Where are you located?

@topkoa
Copy link

topkoa commented Aug 29, 2015

Coventry, Rhode Island

@rwaldron
Copy link
Owner

Oh, that's not bad. Send me an email to waldron.rick@gmail.com and we can arrange this

@carloscarcamo
Copy link
Author

The same issue!
I think that the quality of the sensor is what cause the problem!

sensor

@rwaldron
Copy link
Owner

Duuuuude, is there anything between the bottom of your arduino and that metal table??

@topkoa
Copy link

topkoa commented Aug 29, 2015

img_0825

Here's my test; and mine is on a static sheet! (sorry! had to digg!)

@carloscarcamo
Copy link
Author

@rwaldron it seems like a metal table but it is not, it's hard to explain jajaja!

@rwaldron
Copy link
Owner

rwaldron commented Sep 2, 2015

@topkoa I received the two devices today and just set up some tests, compared them with several of my own and I'll be damned if I can't figure out what's going on with these. I can modify the read handler loop so that it only requests another measurement after the last measurement has been received. There are other controllers that do this, so it's not an issue. This will guarantee that it's impossible for another event handler to be added before the last one has cleared—this will fix the error that we're all now seeing.

@rwaldron
Copy link
Owner

rwaldron commented Sep 2, 2015

Just to make sure it's documented: this fix is working around faulty hardware that's not implementing the trigger/echo timeout correctly.

@topkoa
Copy link

topkoa commented Sep 2, 2015

Awesome; glad I could help!

@topkoa
Copy link

topkoa commented Sep 2, 2015

Just confirming the fix worked! I'm no longer getting that error on your latest code.

A side note, these defective sensors are still effectively not good for a production application in my opinion-- with it running on my bench it occasionally just stops reading distance (returns 0) and sits idle for a good 30 seconds then seems to reset. I presume this is the condition where it caused J5 to crash before the fix.

@rwaldron
Copy link
Owner

rwaldron commented Sep 3, 2015

with it running on my bench it occasionally just stops reading distance (returns 0) and sits idle for a good 30 seconds then seems to reset. I presume this is the condition where it caused J5 to crash before the fix. I presume this is the condition where it caused J5 to crash before the fix.

Yep, thats what I'm referring here:

this fix is working around faulty hardware that's not implementing the trigger/echo timeout correctly.

Basically, we're just being more graceful about how the flaw is handled.

@carloscarcamo
Copy link
Author

@rwaldron thanks for taking some time and fix the problem :)

@rwaldron
Copy link
Owner

rwaldron commented Sep 4, 2015

No problem!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants