動機
スクリプト系がいいなぁ.
やったこと1.ruby-serialportのインストール
1.1 ruby-serialportのインストール(失敗$ sudo gem install ruby-serialport
Password:
Bulk updating Gem source index for: http://gems.rubyforge.org
ERROR: Error installing ruby-serialport:
echoe requires RubyGems version >= 1.2
$ gem --version
1.0.1
$
1.2 gemのupdate$ sudo gem install rubygems-update
Password:
Bulk updating Gem source index for: http://gems.rubyforge.org
Successfully installed rubygems-update-1.3.4
1 gem installed
Installing ri documentation for rubygems-update-1.3.4...
Installing RDoc documentation for rubygems-update-1.3.4...
$ sudo update_rubygems
Installing RubyGems 1.3.4
Installing RubyGems
Installing gem executable
Removing old source_cache files
Removing old RubyGems RDoc and ri
Installing rubygems-1.3.4 ri into /Library/Ruby/Gems/1.8/doc/rubygems-1.3.4/ri
Installing rubygems-1.3.4 rdoc into /Library/Ruby/Gems/1.8/doc/rubygems-1.3.4/rdoc
------------------------------------------------------------------------------
Oh-no! Unable to find release notes!
------------------------------------------------------------------------------
RubyGems installed the following executables:
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/gem
$
1.3 再度ruby-serialportのインストール$ sudo gem install ruby-serialport
Building native extensions. This could take a while...
Successfully installed ruby-serialport-0.7.0
1 gem installed
Installing ri documentation for ruby-serialport-0.7.0...
Installing RDoc documentation for ruby-serialport-0.7.0...
$
やったこと2. コード変更(arduino)と作成(ruby)
Arduino 送信側改行コードがgetsでの受信では必要なのでprintln(ってことだよなタブン).int sensorPin = 0;
int sensorValue = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
sensorValue = analogRead(sensorPin);
Serial.println(sensorValue);
delay(1000);
}
MacBook 受信側 (rx.rb)require 'rubygems'
require 'serialport'
port = "/dev/tty.usbserial-A6005t2E"
sp = SerialPort.new(port, 9600, 8, 1, SerialPort::NONE)
while (sp.gets) do
puts sp.gets
end
sp.close
結果
時間も出してみた.すげーバラバラ.
参考
Rails Agile Cooking - rubyでシリアル通信のテスト
gemが1.3.xにバージョンアップできない件 - func09
0 件のコメント:
コメントを投稿