Closed vickash closed 1 year ago
ok heres what iv done.
git co hcsr04
gem build dino.gemspec
gem install dino-0.12.0.gem
then
dino generate-sketch serial
and installed the ino file
then run
ruby hc-sr04.rb
and i get
/Users/rosscdh/.rvm/gems/ruby-1.9.3-p392/gems/dino-0.12.0/lib/dino/components/hcsr04.rb:5:in `_read': undefined method `ulstrasonic_read' for #<Dino::Board:0x007fae3aad0c38> (NoMethodError)
from /Users/rosscdh/.rvm/gems/ruby-1.9.3-p392/gems/dino-0.12.0/lib/dino/components/core/base_input.rb:19:in `read'
from hc-sr04.rb:10:in `<main>'
That's a typo. Just pushed a fix so you can pull it down.
Make sure you build and upload the sketch from this branch. Installing the gem is not necessary if you run the example from the working copy.
On Tuesday, October 8, 2013 at 11:13 AM, rosscdh wrote:
ok heres what iv done. git co hcsr04 gem build dino.gemspec gem install dino-0.12.0.gem
then run ruby hc-sr04.rb
and i get /Users/rosscdh/.rvm/gems/ruby-1.9.3-p392/gems/dino-0.12.0/lib/dino/components/hcsr04.rb:5:in_read': undefined method
ulstrasonic_read' for #Dino::Board:0x007fae3aad0c38 (NoMethodError) from /Users/rosscdh/.rvm/gems/ruby-1.9.3-p392/gems/dino-0.12.0/lib/dino/components/core/base_input.rb:19:inread' from hc-sr04.rb:10:in
' — Reply to this email directly or view it on GitHub (https://github.com/austinbv/dino/pull/64#issuecomment-25898772).
Thanks seems to get some feedback now :) Ill faff around with it for a bit! and give you some feedback!
Thanks for your efforts!
It's printing the readings?
On Tuesday, October 8, 2013 at 11:19 AM, rosscdh wrote:
Thanks seems to get some feedback now :) Ill faff around with it for a bit! and give you some feedback! Thanks for your efforts!
— Reply to this email directly or view it on GitHub (https://github.com/austinbv/dino/pull/64#issuecomment-25899338).
Hey there, sorry i had to head home! I'll give you some feedback tomorrow.
The microseconds will be used in calculating distance:
long microsecondsToCentimeters(long microseconds)
{
// The speed of sound is 340 m/s or 29 microseconds per centimeter.
// The ping travels out and back, so to find the distance of the
// object we take half of the distance travelled.
return microseconds / 29 / 2;
}
I meant, does the example print the millisecond readings?
On Tuesday, October 8, 2013 at 1:37 PM, rosscdh wrote:
Hey there, sorry i had to head home! I'll give you some feedback tomorrow. The microseconds will be used in calculating distance: long microsecondsToCentimeters(long microseconds) { // The speed of sound is 340 m/s or 29 microseconds per centimeter. // The ping travels out and back, so to find the distance of the // object we take half of the distance travelled. return microseconds / 29 / 2; }
— Reply to this email directly or view it on GitHub (https://github.com/austinbv/dino/pull/64#issuecomment-25911075).
I have a couple of these sensors and am so glad there is active word to support them in dino! One question about this patch though - all the examples online for arduino and HC-SR04 show two digital pin connections to the aruduino; one for triggering and one for sensing the input. This patch assumes there is only one digital pin connected to the arduino. Is this a valid HC-SR04 circuit? If so, which pin on the SR04 gets the digital pin connection, Trig or Echo?
After a bit more research, I saw you can enable "single pin" mode of the HC-SR04 by putting a 1.8k resistor between Trig and Echo and connecting the arduino to the Trig pin, as documented here: http://letsmakerobots.com/node/36885
As it stands, this would be required for this patch, so I would highly recommend documenting that somewhere!
@machadolab thats a great tip and you are 100% right :+1: thanks
Sorry. The code is based on: http://arduino.cc/en/Tutorial/Ping?from=Tutorial.UltrasoundSensor, which looks like a version of this sensor designed to work with only one wire, probably has the resistor built into the PCB.
It's easy to add support for either type of connection, so I'll do that, but you can use it this way in the meantime. Is it putting out valid readings though?
Ah yes, I used to have a Ping)) but not anymore. I have the actual HC-SR04, which has 4 pins, instead of 3. I added a 2k resistor and its working and the readings seem pretty accurate.
I was having trouble using the sensor.poll method though, which looks like it creates it own thread. Does that mean if you have other devices, such as buttons, those would stop working?
I ended up starting my own thread just for the distance sensor and did sensor.read in an infinite loop.
I haven't tried to reproduce it lately though, so it might have just been a fluke.
Yes, #poll
creates a new thread to send commands to the board. This actually frees up the main thread so you can work with other components, not the other way around. It's meant to be a neat wrapper for what you ended up doing.
Can you post the code using #poll, and explain what the problem was?
@vickash is this good to merge or do you want more time on it?
Need to make it work with 2 pins instead of 1, or probably both ways.
I have a few other branches that need to go into 0.12 that have half finished work in them. Will try to wrap everything up as soon as possible and get that out. Too many good features in 0.12 that people using rubygems still don't have access to.
Can you gem push master in the meantime though? It's updated to 0.11.3 with some important bugs squashed.
@rosscdh, test as follows:
./bin/dino generate-sketch serial
.Not sure how you convert microseconds to distance for these, but that's just a matter of adding functionality to the Ruby class, so you can submit a pull against this one.