You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to set up serial communication between a Ruby on Rails app and an Arduino Mega. In Ruby, I am writing an array of strings to the serial, which the Arduino is then supposed to read, process and write corresponding output back to the serial.
For some reason, when I use irb and run the script line by line, everything works and I get the desired result, but when I use ruby sample.rb or run the code from inside Rails, it just gets stuck in the while loop and never returns anything. Would love any guidance on how to get this working.
Update: with some desperation tweaks (I added sp.flush and sleep between the write/read blocks), I am now able to get the code somewhat working in Rails. It doesn't seem to work 100% of the time, though, will need to do some further testing.
This problem seems to be caused by the “auto reset on serial connection” feature of Arduino boards: Everytime a serial connection is opened, the board resets itself. Thus you need to wait a few seconds before you can start sending / receiving data.
I am trying to set up serial communication between a Ruby on Rails app and an Arduino Mega. In Ruby, I am writing an array of strings to the serial, which the Arduino is then supposed to read, process and write corresponding output back to the serial.
For some reason, when I use
irb
and run the script line by line, everything works and I get the desired result, but when I useruby sample.rb
or run the code from inside Rails, it just gets stuck in the while loop and never returns anything. Would love any guidance on how to get this working.For reference, I am running Ruby 2.1.2, Rails 4.1.4, and serialport 1.3.1.
The text was updated successfully, but these errors were encountered: