Skip to content

Dino 0.11.2 #22

merged 60 commits into from May 26, 2013

5 participants

vickash commented Jan 20, 2013

New Features

  • Support for the Arduino Ethernet shield and compatibles (Wiznet W5100 chipset).

  • Added adino command-line tool for generating and customizing the different Arduino sketches.

  • Instead of reading the value of a pin by repeatedly sending messages to ask for its value, we can now set up "listeners". We tell the board which pin we'd like to listen to, and it will periodically send us the pin's value.

    • By default, digital listeners are polled every ~4ms (~250Hz).
    • Analog listeners are on a 4x divider, so they update every ~16ms (~63Hz).
    • These can be changed with the Board#heart_rate= and Board#analog_divider= methods respectively.
    • Digital listeners only send a message if the value has changed since the last check.
    • Analog listeners always send a message.
    • Digital listeners can be set up on any pin, including analog pins. Analog listeners should only be set up on analog pins.
  • Registering a listener is now the default for read components such as Sensor and Button. No changes need to be made for existing or future components. Anything using Board#add_analog_hardware or Board#add_digital_hardware will set up a listener.

    NOTE: Because of these changes, you'll need to upload the newest version of the sketch to your board for this version of the gem to work properly.

  • Support for all 70 pins on the Arduino Mega boards.

  • Built-in pullup resistors on the Arduino are now configurable in Ruby. Disabled by default.

  • Baud rate for serial connections is now configurable. Use the --baud XXXXXX option for dino to set the rate before uploading the sketch. Set baud: XXXXXX in the options hash for` to set the rate when connecting. Both values need to match.

Major Changes

  • All Arduino code that interacts with components has been extracted into an Arduino library. The sketches now only handle communication between a Dino::TxRx:: class in Ruby and this library. Writing new sketches for arbitray protocols should be simpler.

  • Arduino-level debug messages now use preprocessor directives instead of if(debug) statements. The performance and memory usage of sketches with debugging disabled is improved.

  • As a result, enabling and disabling Arduino-level debug messages can no longer be done in Ruby. You'll need to enable debug messages before uploading a sketch by using the --debug option when generating the sketch with dino.

  • Removed TxRx::Telnet. TxRx::TCP, written for the Ethernet shield, works even better for ser2net.

Minor Changes

  • Handshake protocol: The first command sent to the Arduino resets the board to defaults. It acknowledges and responds with the raw pin number of its first analog pin, 'A0' (pin 14 on an UNO).

  • When sending messages between Ruby and the Arduino, all pins are now referenced by this numerical syntax. The value received in the handshake is used by Dino::Board to calculate values on the fly, so the more friendly 'A0' syntax may be used everywhere else in Ruby. This was done mostly to replace some complicated Arduino code and support > 10 analog pins.

  • The Arduino's read and write operations no longer implicitly set the mode of a pin. Calling board#set_pin_mode when initializing a component is now required. board#add_analog_hardware or board#add_digital_hardware for read components will take care of this as well.

  • The syntax of the messages sent from the Arduino to Ruby has changed slightly from "PP::VVVV\r\n" to "PP:VVVV\n" where PP and VVVV represent the pin and value respectively. The increase in (serial) throughput is usable when many analog listeners are set or polling at high rates.


  • Dino::Board#set_pin_mode works correctly now. Input and output were swapped previously and this error was being hidden by the implicit operations mentioned above.
@vickash vickash referenced this pull request Jan 21, 2013

Ethernet Shield support #19


Awesome work man!

vickash commented Jan 27, 2013

@austinbv Thanks man.

Even though this works, it's becoming clear that the ethernet shield simply can't handle the sheer number of HTTP requests Dino creates though. I'm running a test with 2 analog sensors and an LED blinking at a 500ms interval. It hangs for a second or two every 20 seconds or so.

I haven't looked at tcpdump or anything but I'm pretty sure this is the case, since reducing the number of components being read or increasing the heart beat interval improves things. I'm actually impressed that the ethernet shield handles the load so well in the first place, but this is gonna need some more work.

Time to figure out how to do this with websockets.

vickash commented Jan 31, 2013

Can someone sanity check me on this? I'm starting to think my ethernet shield is defective. It's a no name W5100 from eBay. The new TxRx works great, then just dies after a random amount of time. I have to press the reset button on the shield to get it working again. Killing the script and restarting doesn't work if it gets to this state. Here's the script I'm running to test:

board ="")) # Use your own IP here and in the du_ethernet sketch.
led = 9, board: board)
sensor1 = 'A1', board: board)
sensor2 = 'A2', board: board)

show_reading = do |reading|
  puts reading


[:on, :off].cycle do |switch|
  puts switch
  sleep 0.5

I tried adding some debugging lines to write the amount of free memory and used ethernet receive buffer to serial. Memory usage is constant, at ~1.4kB free, and I've seen it hang up with anything from 9 bytes to almost a full 2048 in the buffer. I'm using an UNO by the way. If anyone can recreate the error on different hardware, that would be helpful.

austinbv commented Feb 1, 2013

@vickash I will look over it tomorrow or later tonight, but my ethernet shield is actually fried so we may want to wait a couple days for a good one from sparkfun

vickash commented Feb 4, 2013

@austinbv You'll probably get one faster than I will. Outside the US right now.

I've been running the same UNO connected to one of the tiny WR703N routers I got instead. Using ser2net in raw mode and TxRx::TCP instead of TxRx::Telnet. This setup is fairly close to the Ethernet shield, but has been way more reliable. I'm using the same Arduino board, same machine to run the Ruby code, and same LAN in both cases.

Now I'm hoping it's my particular shield that's broken, or some silly mistake in the Ethernet sketch. If not, it's likely an issue with the Arduino TCP/IP stack.

vickash commented Mar 5, 2013

@austinbv This feels really solid now. I have a load test running on the same ethernet shield I thought was defective. 3 days so far without issue and still going.

The board was wrapping every response in its own IP packet. Buffering the responses for each loop and writing the buffer at the end of the loop seems to have solved the reliability issues.

I've updated the first message in this request with everything that this request changes, and added a changelog to the repo with all the changes since the last version number. Also updated the version number (to 0.11.1), and the readme accordingly.


Yeah, I am looking forward for merge 👍 Thanks @vickash !


Yea, I'm also looking forward to getting into this. I've been holding off a bit to wait and see how this came out. 😃


The CLI needs some love. I wouldn't hold off on merging this though, cause I'd love to help with that. The CLI actually could serve to make life amazingly easy with a little help from avrdude for uploading the compiled C to the arduino for you.

vickash commented Mar 26, 2013

@nathan Yeah, I slapped together the CLI when I realized the two sketches needed files from a different dir, not to mention configuring would be a hassle for users who don't want to mess with the Arduino IDE.

Just made #34 for version 0.12.0 with a couple suggestions for the CLI. Have at it. Also take a look at #35 where I'm working on WiFi shield support. There's some CLI changes in there too which you might need to update, just submit against that branch.

I like the avrdude idea. If we can get to the point where new users install the IDE but never need to open it, that would be good.


New users shouldn't even really be required to have the IDE, all the compilers are open source.

vickash commented May 26, 2013

@austinbv, resolved the conflicts. Merge when ready.

@austinbv austinbv merged commit e83155b into master May 26, 2013

1 check passed

Details default The Travis CI build passed


@vickash vickash deleted the ethernet-shield branch Jun 1, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.