Closed justinledwards closed 9 years ago
You're on the right track with trying to use the digital_read
command and set it up as an input hardware. The problem is that add_digital_hardware
automatically does some other stuff for you, including telling the board to set the pin mode to input.
I've already started abstracting the differences between digital and analog inputs in 0.12.0: https://github.com/austinbv/dino/blob/0.12.0-wip/lib/dino/board.rb#L55-64
Doing this for input and output hardware inside board.rb
is probably a good idea as well. That logic will get moved into the component classes. After doing that, what you're trying to do, which is the most logical way to do it, will just work.
Try submitting a PR if you understand what has to be changed. If not, I'll take care of it.
Since today is my first day with dino or any arduino interfaces, it may take me a bit to figure it out. I'm trying to follow the methods backwards and see what all is happening with add_digital_hardware
.
If I have time sometime I'll try to do a diff on the branches. I'm skimming through 0.12.0 right now and I don't understand fully a few of the functions like set_pullup
. It looks like set_pin_mode
probably needs a third option of in and out, and a new function will have to be created or add_digital_hardware
modified to allow output to be kept with an option.
Hopefully I will have more time in the future to contribute back in a meaningful way.
I was in a hurry to not have to go to my shop to turn the lights off at 10pm and back on at 6am, so I hurried up and wired up a tupperware box with a handybox attached with two controllable receptacles and hurriedly put this code together.
https://github.com/justinledwards/gardino
Still no ability to read the state yet, but I stored the state in sqlite for now.
Started working on this read functionality. It's actually trivial to do, but it turned into a refactoring of all the functionality in Components::Core
.
If digital outputs want to read their state, what's to stop future OneWire parts, or more complexly modeled parts, from wanting to use callbacks (currently limited to analog and digital inputs)? So I'm converting everything to modules instead of using inheritance. Should be up when I get an hour or two to finish it up.
I definitely appreciate the effort. I'm still scaling out my indoor and greenhouse gardening projects, so I haven't needed much complexity yet.
Here is a small timeline of my project so far. http://imgur.com/a/qte5p#44 and greenhouse here http://imgur.com/a/dsVlc#18
I have a couple more systems in the works that I should have going in a couple of days.
Hey Guys, has there been any movement on this?
I'm wanting to use dino with a "HC-SR04" sensor which also requires digital OUTPUT mode.
Thanks
I've written the code to make reading an output pin possible, but haven't had time to fix the tests. The refactoring that was necessary broke almost all the component tests.
However, that won't work for the HC-SR04 anyway. The timing required between switching from input to output is on the order of microseconds. This is something you want to handle inside the Arduino sketch, not in Ruby.
See these lines from the original du.ino sketch: https://github.com/ecto/duino/blob/master/src/du.ino#L174-L205
The dino sketch is a modified version of du.ino but that functionality was removed since I couldn't test it. It's pretty straightforward and I can put it back into dino in a few minutes, but I don't have one of these sensors to test with. Willing to download a WIP branch and sketch to test it out?
Hi there, hell yeah no problem :) let me know when its ready :)
@rosscdh, see #64
This is now possible if you make your own class by mashing together the Basic::DigitalInput
and Basic::DigitalOutput
classes. Just make sure to leave out the Setup::Input
module, since that would set the pin mode to INPUT and then writing would just affect the pullup resistor, which you don't want. Everything else should just work together.
I don't think this should be a standard feature though, since each component already caches it's state in a @state
variable. Since one of our basic assumptions is that we have complete control over the board, that value should be trusted and used instead.
Is this possible with dino? I have had my arduino less than 24 hours and went through the 12 chapter book it came with last night, and am trying to integrate it into a rails app today.
I am testing with just one LED across the room right now. I am looking to check the state of the LED (or later on relay). I know that I can set a variable on the state change and read that variable, but if possible I'd like to actually see the state from the hardware. When I try to add_digital_hardware the LED no longer functions, and when I try digital_read, it returns nil no matter what the state. Any help would be appreciated.
Wanting to do something like this.
http://forum.arduino.cc/index.php/topic,41954.0.html