Skip to content
This repository

Dino 0.11.2 #22

Merged
merged 60 commits into from about 1 year ago

5 participants

Vickash Austin regedarek Nathan Lilienthal Nishant Modak
Vickash
Collaborator

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 Dino::TxRx::USBSerial.new` 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.

Fixes

  • 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
Closed

Ethernet Shield support #19

Austin
Owner

Awesome work man!

Vickash
Collaborator

@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
Collaborator

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 = Dino::Board.new(Dino::TxRx::TCP.new("192.168.0.77")) # Use your own IP here and in the du_ethernet sketch.
led = Dino::Components::Led.new(pin: 9, board: board)
sensor1 = Dino::Components::Sensor.new(pin: 'A1', board: board)
sensor2 = Dino::Components::Sensor.new(pin: 'A2', board: board)

show_reading = Proc.new do |reading|
  puts reading
end

sensor1.when_data_received(show_reading)
sensor2.when_data_received(show_reading)

[:on, :off].cycle do |switch|
  led.send(switch)
  puts switch
  sleep 0.5
end

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.

Austin
Owner

@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
Collaborator

@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
Collaborator

@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.

regedarek

Yeah, I am looking forward for merge :+1: Thanks @vickash !

Nathan Lilienthal

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. :smiley:

Nathan Lilienthal

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
Collaborator

@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.

Nathan Lilienthal

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

Vickash
Collaborator
vickash commented

@austinbv, resolved the conflicts. Merge when ready.

Austin austinbv merged commit e83155b into from
Austin austinbv closed this
Vickash vickash deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 60 unique commits by 1 author.

Jan 20, 2013
Vickash vickash Start rewriting du.ino to make it easier to work with non-serial inte…
…rfaces
9376954
Vickash vickash Only write to serial from within 'loop'. Debugging disabled. a80058e
Vickash vickash Refactor pin determination c4783cc
Jan 21, 2013
Vickash vickash Fix error where val and aux weren't being terminated properly. b53bccb
Vickash vickash Remove hack-ish aux, servo, and ping stuff we weren't using anyway 79bbcbf
Vickash vickash Forgot to remove aux declaration 3b6b1fb
Vickash vickash Remove unused servo lib. Localize some vars and pass pointers for oth…
…ers.
bc18299
Jan 22, 2013
Vickash vickash Move all the hardware interaction into a library 0bed566
Jan 23, 2013
Vickash vickash Add ethernet compatible Arduino sketch 160c411
Jan 24, 2013
Vickash vickash Use chomp instead of chop for lines in TxRx::Telnet 2b2649d
Vickash vickash First pass at TxRx::HTTP 8406c09
Jan 27, 2013
Vickash vickash Redo ethernet implementation in pure TCP ffc5b40
Jan 29, 2013
Vickash vickash Make sure the SD card gets disabled 7cb02b9
Feb 01, 2013
Vickash vickash Don't use String in sketches; put listener/heartbeat logic into Dino.cpp
Old API remains, but now we can tell the Arduino just once to listen to a pin and it'll send us the value every X ms instead of having to constantly ask for it.
2ff7782
Feb 04, 2013
Vickash vickash Refactor convertPin to handle arbitrarily high pin numbers b794a9b
Vickash vickash Use millis() instead of delay() to make Arduino heartbeat non-blocking. d0a49db
Vickash vickash Track # of listeners and skip Arduino heartbeat if none ede5ac9
Vickash vickash Refactor response handling into the Arduino Dino library de6dc8c
Vickash vickash Make ethernet shield work with last few changes b5ab141
Feb 05, 2013
Vickash vickash Only update digital listeners when value has changed 51dd96a
Vickash vickash Save RAM by writing responses immediately d7e62bd
Vickash vickash Update ethernet sketch to work with latest changes 6cc9ca9
Vickash vickash Remove a debugging line 59d6658
Vickash vickash Update digital listeners independent of heartbeat. Handle millis() ro…
…llover.
b229f89
Feb 06, 2013
Vickash vickash Refactor all request parsing into the library 8c65499
Feb 09, 2013
Vickash vickash Remove TxRx::Telnet in favor of TxRx::TCP for ser2net in raw mode eb2749d
Feb 10, 2013
Vickash vickash Handshake protocol. Dino::Board now uses Arduino-native listeners. 61f0f0c
Vickash vickash Fix broken tests 68a8b99
Feb 11, 2013
Vickash vickash Prevent @io.flush_read hanging TxRx::TCP#initialize d91f272
Vickash vickash Reduce response size by ~2/9. Consistent 200Hz polling of listeners. 5da7bfc
Vickash vickash Better handshake for TCP/ser2net. Fix Serial spec. ff746a0
Vickash vickash Minor ethernet sketch changes 090d383
Feb 12, 2013
Vickash vickash Allow configuration of built-in pull-up resistor on Arduino 7a6df8b
Vickash vickash Symlinks to ease Arduino development on *nix. CLI tool to generate sk…
…etch dirs.
c801e97
Vickash vickash Fix tests. Argument order consistent with Arduino messaging syntax. 18f4a41
Feb 15, 2013
Vickash vickash Convert pins from 'A0' format to raw integer and back in Ruby. 868ae33
Vickash vickash Refactor both TxRx to use IO#select 5e8ded0
Vickash vickash Move handshake into TxRx::Base d03e853
Feb 17, 2013
Vickash vickash Buffer TCP writes. Ethernet sketch is reliable now. 509db11
Feb 22, 2013
Vickash vickash Set heart rate and analog divider from Ruby. Arduino Mega support for…
… all pins using preprocessor directives to allocate enough listeners.

Remove all board-level debugging to be replaced by preprocessor directives.
4f7df9d
Vickash vickash Use port 3466 (DINO) by default. Added tests for TxRx::TCP. c346385
Feb 24, 2013
Vickash vickash Explicitly disable pull-up when not specified. f77cb31
Vickash vickash First pass at new debug messages. a1d12a9
Vickash vickash Tweak examples. Make sure debug messages are filtered out. 9526d4d
Feb 26, 2013
Vickash vickash Add some CLI configuration options and improve readme 2b86eb3
Feb 28, 2013
Vickash vickash Merge branch 'master' into ethernet-shield 9784361
Vickash vickash Simplify Serial TxRx. Configurable baud rate. Other minor fixes. 215043d
Mar 01, 2013
Vickash vickash Device should be part of options. Change TxRx::USBSerial to TxRx::Ser…
…ial. Update examples.
baba33f
Vickash vickash Version bump. Added a change log. 74924b8
Mar 02, 2013
Vickash vickash Trying to match nil to a regex was killing the read thread X_X d350df0
Mar 05, 2013
Vickash vickash Fix some markdown issues in changelog and readme df69fdc
Mar 23, 2013
Vickash vickash Use the Arduino Servo lib to make servos work better 8ce13b6
Vickash vickash Fix tests e7ff676
Apr 01, 2013
Vickash vickash Slower, but more reliable handshake for windows serial. Also closes #12 4c1bc25
Vickash vickash Servos use regular (non-PWM) pins on MEGA boards. Remove listener whe…
…n pin mode set to out.
d30e070
Apr 02, 2013
Vickash vickash Clean up some serial tests 1a84658
May 12, 2013
Vickash vickash Fix version number in read me 6c06bae
May 26, 2013
Vickash vickash Search up to COM256 on Windows 2eace63
Vickash vickash Merge branch 'master' into ethernet-shield
Conflicts:
	lib/dino/tx_rx/usb_serial.rb
29deae8
Vickash vickash Forgot to stage conflict fix... cdbf8ad
Something went wrong with that request. Please try again.