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.
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.
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.
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.
Start rewriting du.ino to make it easier to work with non-serial inte…
Only write to serial from within 'loop'. Debugging disabled.
Refactor pin determination
Fix error where val and aux weren't being terminated properly.
Remove hack-ish aux, servo, and ping stuff we weren't using anyway
Forgot to remove aux declaration
Remove unused servo lib. Localize some vars and pass pointers for oth…
Move all the hardware interaction into a library
Awesome work man!
Add ethernet compatible Arduino sketch
Use chomp instead of chop for lines in TxRx::Telnet
First pass at TxRx::HTTP
@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.
Redo ethernet implementation in pure TCP
Make sure the SD card gets disabled
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|
[:on, :off].cycle do |switch|
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.
@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
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.
Refactor convertPin to handle arbitrarily high pin numbers
Use millis() instead of delay() to make Arduino heartbeat non-blocking.
Track # of listeners and skip Arduino heartbeat if none
Refactor response handling into the Arduino Dino library
Make ethernet shield work with last few changes
@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.
Only update digital listeners when value has changed
Save RAM by writing responses immediately
Update ethernet sketch to work with latest changes
Remove a debugging line
Update digital listeners independent of heartbeat. Handle millis() ro…
Refactor all request parsing into the library
Remove TxRx::Telnet in favor of TxRx::TCP for ser2net in raw mode
Handshake protocol. Dino::Board now uses Arduino-native listeners.
Fix broken tests
Prevent @io.flush_read hanging TxRx::TCP#initialize
Reduce response size by ~2/9. Consistent 200Hz polling of listeners.
Better handshake for TCP/ser2net. Fix Serial spec.
Minor ethernet sketch changes
Allow configuration of built-in pull-up resistor on Arduino
Symlinks to ease Arduino development on *nix. CLI tool to generate sk…
Fix tests. Argument order consistent with Arduino messaging syntax.
Convert pins from 'A0' format to raw integer and back in Ruby.
Refactor both TxRx to use IO#select
Move handshake into TxRx::Base
Buffer TCP writes. Ethernet sketch is reliable now.
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.
Use port 3466 (DINO) by default. Added tests for TxRx::TCP.
Explicitly disable pull-up when not specified.
First pass at new debug messages.
Tweak examples. Make sure debug messages are filtered out.
Add some CLI configuration options and improve readme
Merge branch 'master' into ethernet-shield
Simplify Serial TxRx. Configurable baud rate. Other minor fixes.
Device should be part of options. Change TxRx::USBSerial to TxRx::Ser…
…ial. Update examples.
Version bump. Added a change log.
Trying to match nil to a regex was killing the read thread X_X
Fix some markdown issues in changelog and readme
@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.
Use the Arduino Servo lib to make servos work better
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.
@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.
Slower, but more reliable handshake for windows serial. Also closes #12
Servos use regular (non-PWM) pins on MEGA boards. Remove listener whe…
…n pin mode set to out.
Clean up some serial tests
Fix version number in read me
Search up to COM256 on Windows
Forgot to stage conflict fix...
@austinbv, resolved the conflicts. Merge when ready.