If your ruby serial port doesn’t read what’ you’re sending…

2009 November 27

Some days ago I got my Novation launchpad an immediately started hacking with some Ruby and Arduino flavor. I wanted to port ccb23 Raindrops Project to launchpad.

For that, I needed Serial communication within ruby. Thanks to ruby-serialport first steps went quite well. I could write OR read from and to Arduino easily. But for some reasons, writing AND reading using the same instance didn’t work out.

I used a simple ‘send-input-back’ sketch on the Arduino side. So every byte I’m sending is returned back. I checked with the Arduino IDE Serialmonitor and a simple Processing script – everything worked alright. But using ruby it was different. Writing to serial port worked okay, but reading from it was just random. Sometimes I read the response, sometime I didn’t – really, really weird. Some headaches and a lot of time testing I finally found the solution: just open two instances of the serial port. One for sending, one for reading – and, surprise, surprise – it works perfect! Who would have guessed that!? Strange..

// To be completed
require 'serialport'
port_write = Serialport.new()
port_read = Serialport.new()

Ok, continuing hacking, more soon…

No comments yet

Leave a Reply

Note: You can use basic XHTML in your comments. Your email address will never be published.

Subscribe to this comment feed via RSS