shokai / arduino_firmata Goto Github PK
View Code? Open in Web Editor NEWArduino Firmata protocol implementation on Ruby
Home Page: http://shokai.github.io/arduino_firmata
License: MIT License
Arduino Firmata protocol implementation on Ruby
Home Page: http://shokai.github.io/arduino_firmata
License: MIT License
pin_mode(pin, mode)
digital_write(pin, value)
analog_write(pin, value)
servo_write(pin, angle)
これをwriteする関数を作る
SYSTEM_RESET = 0xFF # reset from MIDI
When attempting to connect, if the nonblock_io
option is not passed, it does not connect, and ends up hanging instead.
The code by default sets @read_byte_size = 9600
, then in the read
method, it blocks trying to read 9600 bytes. During connect, when it waits for the version report, it hangs because the version report is only 8 bytes.
Because it is sitting there sending the "version report" command over and over, the responses will eventually fill the buffer and cause the loop to end, but it takes a very long time.
I have loaded SysexLedBlinkFirmata onto my Arduino and set ARDUINO
variable on my env correctly. bundle install
succeeded although I had to bump version of serialport
(see #44).
arduino_firmata$ rake test
/Users/lukemcfarlane/.rvm/gems/ruby-2.2.2/gems/backports-3.3.4/lib/backports/1.9.1/io/open.rb:2:in `close': Bad file descriptor @ fptr_finalize - /Users/lukemcfarlane/.rvm/gems/ruby-2.2.2/gems/backports-3.3.4/lib/backports/1.9.1/io/open.rb (Errno::EBADF)
from /Users/lukemcfarlane/.rvm/gems/ruby-2.2.2/gems/backports-3.3.4/lib/backports/1.9.1/io/open.rb:2:in `open'
from /Users/lukemcfarlane/.rvm/gems/ruby-2.2.2/gems/backports-3.3.4/lib/backports/1.9.1/io/open.rb:2:in `<top (required)>'
from /Users/lukemcfarlane/.rvm/gems/ruby-2.2.2/gems/backports-3.3.4/lib/backports/tools.rb:328:in `require'
from /Users/lukemcfarlane/.rvm/gems/ruby-2.2.2/gems/backports-3.3.4/lib/backports/tools.rb:328:in `require_with_backports'
from /Users/lukemcfarlane/.rvm/gems/ruby-2.2.2/gems/backports-3.3.4/lib/backports/tools.rb:22:in `block in require_relative_dir'
from /Users/lukemcfarlane/.rvm/gems/ruby-2.2.2/gems/backports-3.3.4/lib/backports/tools.rb:21:in `each'
from /Users/lukemcfarlane/.rvm/gems/ruby-2.2.2/gems/backports-3.3.4/lib/backports/tools.rb:21:in `require_relative_dir'
from /Users/lukemcfarlane/.rvm/gems/ruby-2.2.2/gems/backports-3.3.4/lib/backports/1.9.1/io.rb:3:in `<top (required)>'
from /Users/lukemcfarlane/.rvm/gems/ruby-2.2.2/gems/backports-3.3.4/lib/backports/tools.rb:328:in `require'
from /Users/lukemcfarlane/.rvm/gems/ruby-2.2.2/gems/backports-3.3.4/lib/backports/tools.rb:328:in `require_with_backports'
from /Users/lukemcfarlane/.rvm/gems/ruby-2.2.2/gems/backports-3.3.4/lib/backports/tools.rb:22:in `block in require_relative_dir'
from /Users/lukemcfarlane/.rvm/gems/ruby-2.2.2/gems/backports-3.3.4/lib/backports/tools.rb:21:in `each'
from /Users/lukemcfarlane/.rvm/gems/ruby-2.2.2/gems/backports-3.3.4/lib/backports/tools.rb:21:in `require_relative_dir'
from /Users/lukemcfarlane/.rvm/gems/ruby-2.2.2/gems/backports-3.3.4/lib/backports/1.9.1.rb:3:in `<top (required)>'
from /Users/lukemcfarlane/.rvm/gems/ruby-2.2.2/gems/backports-3.3.4/lib/backports/tools.rb:328:in `require'
from /Users/lukemcfarlane/.rvm/gems/ruby-2.2.2/gems/backports-3.3.4/lib/backports/tools.rb:328:in `require_with_backports'
from /Users/lukemcfarlane/.rvm/gems/ruby-2.2.2/gems/backports-3.3.4/lib/backports/1.9.2.rb:2:in `<top (required)>'
from /Users/lukemcfarlane/.rvm/gems/ruby-2.2.2/gems/backports-3.3.4/lib/backports/tools.rb:328:in `require'
from /Users/lukemcfarlane/.rvm/gems/ruby-2.2.2/gems/backports-3.3.4/lib/backports/tools.rb:328:in `require_with_backports'
from /Users/lukemcfarlane/.rvm/gems/ruby-2.2.2/gems/backports-3.3.4/lib/backports/1.9.3.rb:2:in `<top (required)>'
from /Users/lukemcfarlane/.rvm/gems/ruby-2.2.2/gems/backports-3.3.4/lib/backports/tools.rb:328:in `require'
from /Users/lukemcfarlane/.rvm/gems/ruby-2.2.2/gems/backports-3.3.4/lib/backports/tools.rb:328:in `require_with_backports'
from /Users/lukemcfarlane/.rvm/gems/ruby-2.2.2/gems/backports-3.3.4/lib/backports/1.9.rb:2:in `<top (required)>'
from /Users/lukemcfarlane/.rvm/gems/ruby-2.2.2/gems/backports-3.3.4/lib/backports/tools.rb:328:in `require'
from /Users/lukemcfarlane/.rvm/gems/ruby-2.2.2/gems/backports-3.3.4/lib/backports/tools.rb:328:in `require_with_backports'
from /Users/lukemcfarlane/.rvm/gems/ruby-2.2.2/gems/backports-3.3.4/lib/backports/2.0.0.rb:2:in `<top (required)>'
from /Users/lukemcfarlane/.rvm/gems/ruby-2.2.2/gems/backports-3.3.4/lib/backports/tools.rb:328:in `require'
from /Users/lukemcfarlane/.rvm/gems/ruby-2.2.2/gems/backports-3.3.4/lib/backports/tools.rb:328:in `require_with_backports'
from /Users/lukemcfarlane/.rvm/gems/ruby-2.2.2/gems/backports-3.3.4/lib/backports/2.0.rb:2:in `<top (required)>'
from /Users/lukemcfarlane/.rvm/gems/ruby-2.2.2/gems/backports-3.3.4/lib/backports/tools.rb:328:in `require'
from /Users/lukemcfarlane/.rvm/gems/ruby-2.2.2/gems/backports-3.3.4/lib/backports/tools.rb:328:in `require_with_backports'
from /Users/lukemcfarlane/.rvm/gems/ruby-2.2.2/gems/backports-3.3.4/lib/backports.rb:3:in `<top (required)>'
from /Users/lukemcfarlane/Workspaces/Personal/arduino_firmata/test/test_helper.rb:4:in `require'
from /Users/lukemcfarlane/Workspaces/Personal/arduino_firmata/test/test_helper.rb:4:in `<top (required)>'
from /Users/lukemcfarlane/Workspaces/Personal/arduino_firmata/test/test_arduino_firmata.rb:1:in `require'
from /Users/lukemcfarlane/Workspaces/Personal/arduino_firmata/test/test_arduino_firmata.rb:1:in `<top (required)>'
from /Users/lukemcfarlane/.rvm/gems/ruby-2.2.2/gems/rake-10.1.0/lib/rake/rake_test_loader.rb:10:in `require'
from /Users/lukemcfarlane/.rvm/gems/ruby-2.2.2/gems/rake-10.1.0/lib/rake/rake_test_loader.rb:10:in `block (2 levels) in <main>'
from /Users/lukemcfarlane/.rvm/gems/ruby-2.2.2/gems/rake-10.1.0/lib/rake/rake_test_loader.rb:9:in `each'
from /Users/lukemcfarlane/.rvm/gems/ruby-2.2.2/gems/rake-10.1.0/lib/rake/rake_test_loader.rb:9:in `block in <main>'
from /Users/lukemcfarlane/.rvm/gems/ruby-2.2.2/gems/rake-10.1.0/lib/rake/rake_test_loader.rb:4:in `select'
from /Users/lukemcfarlane/.rvm/gems/ruby-2.2.2/gems/rake-10.1.0/lib/rake/rake_test_loader.rb:4:in `<main>'
rake aborted!
Command failed with status (1): [ruby -I"lib" -I"/Users/lukemcfarlane/.rvm/gems/ruby-2.2.2/gems/rake-10.1.0/lib" "/Users/lukemcfarlane/.rvm/gems/ruby-2.2.2/gems/rake-10.1.0/lib/rake/rake_test_loader.rb" "test/test_*.rb" ]
/Users/lukemcfarlane/.rvm/gems/ruby-2.2.2/bin/ruby_executable_hooks:15:in `eval'
/Users/lukemcfarlane/.rvm/gems/ruby-2.2.2/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => test
(See full trace by running task with --trace)
add default name "/dev/ttyACM0" into ArduinoFirmata.list
Hi,
I'm trying to get the value of a sensor on regular intervals. I try running this simple code
require "arduino_firmata"
arduino = ArduinoFirmata.connect "/dev/ttyACM0"
5.times do
puts arduino.analog_read(1)
sleep 5
end
arduino.close
but I get the same value regardless how the conditions for the sensor change.
If I put the arduino initialisation and close within the loop it works, but this is far from optimal way of doing it. I'd like to be able to initialise the object and work with it for a while before closing.
I'm running it with Firmata 2.4.0 on a raspberry pi.
Any ideas?
Thanks,
Kamen
arduino.pin_mode 0, ArduinoFirmata::ANALOG
arduino.analog_read 0
arduino.on :analog_read do |pin, value|
puts "analog pin #{pin} changed #{value}"
arduino.analog_write 11, value if pin == 0
end
implements "on_analog_change" and "on_digital_change" methods.
pin = 0
arduino.on_analog_changed pin do |value|
puts "#{pin} => #{value}"
end
control arduino via HTTP
http://shokai.github.com/event_emitter
current
arduino.on_analog_changed 0 do |value|
puts value # => 0 ~ 1023
end
new
arduino.on :analog_read do |pin, value|
puts "#{pin} -> #{value}"
end
current
arduino.on_sysex_received(0x01) do |data|
puts "command : 0x01"
puts "data : #{data.inspect}"
end
new
arduino.on :sysex do |command, data|
puts "command : #{command}"
puts "data : #{data.inspect}"
end
PC-Firmata間で2byte以上のデータをやりとりする時に使う。StandardFirmataではArduino→PCへのDIGITAL_MESSAGE, ANALOG_MESSAGE, REPORT_VERSIONで使われている。
自作のコマンドを実行させるのにも使われる。
[START_SYSEX, コマンド名, 7bitを32個分のデータ, END_SYSEX] を1セットとして送信する。
http://firmata.org/wiki/V2.1ProtocolDetails#Sysex_Message_Format
/* Generic Sysex Message
* 0 START_SYSEX (0xF0)
* 1 sysex command (0x00-0x7F)
* x between 0 and MAX_DATA_BYTES 7-bit bytes of arbitrary data
* last END_SYSEX (0xF7)
*/
MAX_DATA_BYTESは /Applications/Arduino.app/Contents/Resources/Java/libraries/Firmata/Firmata.h で定義されている。
デフォルトで7bitのデータを最大32個送れる。
#define MAX_DATA_BYTES 32 // max number of data bytes in non-Sysex messages
既に定義されているsysex command。0x00-0x0Fはユーザが自分のアプリ内で定義していいらしい。
// extended command set using sysex (0-127/0x00-0x7F)
/* 0x00-0x0F reserved for user-defined commands */
#define SERVO_CONFIG 0x70 // set max angle, minPulse, maxPulse, freq
#define STRING_DATA 0x71 // a string message with 14-bits per char
#define SHIFT_DATA 0x75 // a bitstream to/from a shift register
#define I2C_REQUEST 0x76 // send an I2C read/write request
#define I2C_REPLY 0x77 // a reply to an I2C read request
#define I2C_CONFIG 0x78 // config I2C settings such as delay times and power pins
#define EXTENDED_ANALOG 0x6F // analog write (PWM, Servo, etc) to any pin
#define PIN_STATE_QUERY 0x6D // ask for a pin's current mode and value
#define PIN_STATE_RESPONSE 0x6E // reply with pin's current mode and value
#define CAPABILITY_QUERY 0x6B // ask for supported modes and resolution of all pins
#define CAPABILITY_RESPONSE 0x6C // reply with supported modes and resolution
#define ANALOG_MAPPING_QUERY 0x69 // ask for mapping of analog to pin numbers
#define ANALOG_MAPPING_RESPONSE 0x6A // reply with mapping info
#define REPORT_FIRMWARE 0x79 // report name and version of the firmware
#define SAMPLING_INTERVAL 0x7A // set the poll rate of the main loop
#define SYSEX_NON_REALTIME 0x7E // MIDI Reserved for non-realtime messages
#define SYSEX_REALTIME 0x7F // MIDI Reserved for realtime messages
// these are DEPRECATED to make the naming more consistent
#define FIRMATA_STRING 0x71 // same as STRING_DATA
#define SYSEX_I2C_REQUEST 0x76 // same as I2C_REQUEST
#define SYSEX_I2C_REPLY 0x77 // same as I2C_REPLY
#define SYSEX_SAMPLING_INTERVAL 0x7A // same as SAMPLING_INTERVAL
arduino_firmata gemでは、START_SYSEXとEND_SYSEXが const.rbで定義されてる
https://github.com/shokai/arduino_firmata/blob/master/lib/arduino_firmata/const.rb
module ArduinoFirmata
START_SYSEX = 0xF0 # start a MIDI SysEx message
END_SYSEX = 0xF7 # end a MIDI SysEx message
end
ArduinoFirmata::Arduino::write関数はprivateにしてある。
PC→Arduinoへsysexコマンドを送る関数を作る必要アリ。
Arduino→PCにコマンドが来た時のイベントも登録できるようにしたい。
/Applications/Arduino.app/Contents/Resources/Java/libraries/Firmata/Firmata.cpp にあるattach関数にsysex command (0x00-0x7F)を引数として、コールバックを登録する。
http://firmata.org/wiki/V2.1ProtocolDetails#Sysex_Message_Format を見ると、0x00~0x0Fはユーザが自由に使って良い様に予約されているんだけど、登録しても現在Arduino IDEに付属しているFirmata.cpp内では呼び出されるように実装されてない。
方法は2つで、
のどちらか。
STRING_DATAは自作アプリで使える。
STRING_DATA (0x71)はFirmata.cpp内でコールバックとして登録できるようになっているが、Arduino IDE付属のStandardFirmata.inoからは使われていない。
スケッチ例のEchoStringで使ってる。
#include <Firmata.h>
byte analogPin;
void stringCallback(char *myString)
{
Firmata.sendString(myString);
}
void sysexCallback(byte command, byte argc, byte*argv)
{
Firmata.sendSysex(command, argc, argv);
}
void setup()
{
Firmata.setFirmwareVersion(0, 1);
Firmata.attach(STRING_DATA, stringCallback);
Firmata.attach(START_SYSEX, sysexCallback);
Firmata.begin(57600);
}
void loop()
{
while(Firmata.available()) {
Firmata.processInput();
}
}
StandardFirmataの void sysexCallback(byte command, byte argc, byte *argv) 関数内のswitch文に書き足すといい。
I2C関係はここで定義されている。
Whenever my process which is using ArduinoFirmata tries to exit gracefully, it never exits because ArduinoFirmata is stuck.
When I do a CTRL+C, the last few lines of the trace are:
/usr/local/firmata-server/vendor/bundle/ruby/1.9.1/gems/arduino_firmata-0.3.7/lib/arduino_firmata/arduino.rb:85:in `sleep': Interrupt
from /usr/local/firmata-server/vendor/bundle/ruby/1.9.1/gems/arduino_firmata-0.3.7/lib/arduino_firmata/arduino.rb:85:in `block in close'
from /usr/local/firmata-server/vendor/bundle/ruby/1.9.1/gems/arduino_firmata-0.3.7/lib/arduino_firmata/arduino.rb:81:in `loop'
from /usr/local/firmata-server/vendor/bundle/ruby/1.9.1/gems/arduino_firmata-0.3.7/lib/arduino_firmata/arduino.rb:81:in `close'
from /usr/local/firmata-server/vendor/bundle/ruby/1.9.1/gems/arduino_firmata-0.3.7/lib/arduino_firmata/arduino.rb:34:in `block in initialize'
When I add some debugging code to arduino.rb:82, it shows that @serial.closed? == true
and @thread_status == true
.
Looking through the code I would guess that the process_input
thread is stuck on line 195 doing a blocking read. So it it never returns from line 41 to see that @status
has been change to Status::CLOSE
.
I personally don't see why it needs the at_exit do close end
. It'll get closed automatically when the process exits. So perhaps the solution would be to remove that.
/home/sho/src/ruby/arduino_firmata/lib/arduino_firmata/arduino.rb:65:in `close': closed stream (IOError)
from /home/sho/src/ruby/arduino_firmata/lib/arduino_firmata/arduino.rb:65:in `close'
from /home/sho/src/ruby/arduino_firmata/lib/arduino_firmata/arduino.rb:31:in `initialize'
from /home/sho/src/ruby/arduino_firmata/lib/arduino_firmata/arduino.rb:58:in `call'
from /home/sho/src/ruby/arduino_firmata/lib/arduino_firmata/arduino.rb:58:in `sleep'
from /home/sho/src/ruby/arduino_firmata/lib/arduino_firmata/arduino.rb:58:in `initialize'
from /home/sho/src/ruby/arduino_firmata/lib/arduino_firmata/arduino.rb:56:in `loop'
from /home/sho/src/ruby/arduino_firmata/lib/arduino_firmata/arduino.rb:56:in `initialize'
from /home/sho/src/ruby/arduino_firmata/lib/arduino_firmata/main.rb:14:in `new'
from /home/sho/src/ruby/arduino_firmata/lib/arduino_firmata/main.rb:14:in `connect'
from samples/led_blink.rb:6
more performance
led_stat = false
ArduinoFirmata.connect do
10.times do
digital_write 13, led_stat
end
When I run a simple script:
require 'rubygems'
require 'arduino_firmata'
arduino = ArduinoFirmata.connect
arduino.digital_write 13, true
sleep
I get:
/var/lib/gems/1.9.1/gems/arduino_firmata-0.2.3/lib/arduino_firmata/arduino.rb:163:in `write_nonblock': Resource temporarily unavailable - write would block (Errno::EAGAIN)
Somehow if I execute the scripts too quickly i get the error, but if I wait then the error vanishes and works, how can I fix this?
Im using your library with the nonblocking turned on and eventmachine. I faced a problem with this part of the process input interval:
@process_input_interval = eventmachine ? 0.0001 : 0.01
Since the interval in a eventmachine setup is very high my machine (linux) produces an annoying high freq. sound. Also it uses one core at 80% cpu (without doing anything). I manually tried this:
@process_input_interval = 0.01
And it removed the sound and made the process use 2% cpu, when nothing happens.
Im not sure why the value is set the way it is currently. So maybe you can tell.
Thx & Kind regards
Hi,
I need some help. I want to read sensor values from a I2C sensor.
I think I need the sysex commands. I tried this:
arduino.pinMode(3, firmata.PIN_MODE_I2C);
arduino.pinMode(2, firmata.PIN_MODE_I2C);
console.log("I2C activated");
arduino.sysex('I2C_CONFIG');
arduino.sysex('I2C_REQUEST, [0x58, 'I2C_READ'], function(x){
arduino.on('sysex', function(e){
console.log("Data: ", e.command);
console.log("data : " + JSON.stringify(e.data));
});
It is not working and I have no idea how to realise the reading.
Thanks
some functions will crash ruby process when got negative values
newgem -> bundler
Ruby2.0.0でエラーがでる
lib/arduino_firmata/arduino.rb:172: warning: StringIO#bytes is deprecated; use #each_byte instead
String#each_byte を使えばいいらしい
It seems that the sysex command is not properly handled.
$ rake test TEST=/home/paolo/projects/contrib/arduino_firmata/test/test_sysex.rb
Run options: --seed 14609
# Running:
F
Finished in 11.043371s, 0.0906 runs/s, 0.0906 assertions/s.
1) Failure:
TestSysex#test_sysex_command [/home/paolo/projects/contrib/arduino_firmata/test/test_sysex.rb:30]:
Failed assertion, no message given.
1 runs, 1 assertions, 1 failures, 0 errors, 0 skips
rake aborted!
Command failed with status (1): [ruby -I"lib" -I"/home/paolo/.rvm/gems/ruby-2.3.0@arduino/gems/rake-10.1.0/lib" "/home/paolo/.rvm/gems/ruby-2.3.0@arduino/gems/rake-10.1.0/lib/rake/rake_test_loader.rb" "/home/paolo/projects/contrib/arduino_firmata/test/test_sysex.rb" ]
/home/paolo/.rvm/gems/ruby-2.3.0@arduino/bin/ruby_executable_hooks:15:in `eval'
/home/paolo/.rvm/gems/ruby-2.3.0@arduino/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => test
(See full trace by running task with --trace)
I am running Firmata 2.5.
I had to update both serialport
and backports
to get things working, I don't know if it is related to this issue.
arduino.pin_mode 8, ArduinoFirmata::INPUT
arduino.on :digital_read do |pin, status|
puts "digital pin #{pin} changed : #{status}" # => "pin 0 changed"
end
not sleep, check connection.
I use an Arduino UNO version 2.3. When I do:
require 'arduino_firmata'
arduino = ArduinoFirmata.connect
puts "firmata version #{arduino.version}"
arduino.pin_mode 8, ArduinoFirmata::INPUT
puts arduino.digital_read(8)
loop do
arduino.on(:digital_read) do |pin, status|
#if pin == 8
puts "digital pin #{pin} changed : #{status}"
#end
end
sleep(0.1)
end
I always get a pin value of 0 (digital pin 0 changed : true
). Consequently the if
block doesn't execute correctly either, so I've commented it out here.
Is this a feature (and I'm just doing something wrong) or a bug?
set :eventmachine option on ArduinoFirmata#connect
arduino = ArduinoFirmata.connect, '/dev/tty.device-name', :eventmachine => true
use EM::defer instead of Thread.
current
(0...6).each do |i|
write(REPORT_ANALOG | i)
write 1
end
set number of Analog ports when connect.
everytime returns 0
i use arduino & node-red and
error message was broke out.
5 Sep 13:51:45 - [red] Version: 0.8.1
5 Sep 13:51:45 - [red] Loading palette nodes
js-bson: Failed to load c++ bson extension, using pure JS version
5 Sep 13:51:46 - ------------------------------------------
5 Sep 13:51:46 - [red] Failed to register 1 node type
5 Sep 13:51:46 - [red] Run with -v for details
5 Sep 13:51:46 - ------------------------------------------
5 Sep 13:51:46 - [red] Server now running at http://127.0.0.1:1880/
5 Sep 13:51:46 - [red] Loading flows : ardu.json
5 Sep 13:51:46 - [red] Starting flows
5 Sep 13:51:46 - [log] [inject:tick] repeat = 500
5 Sep 13:51:59 - [red] Stopping flows
5 Sep 13:51:59 - [log] [inject:tick] inject: repeat stopped
5 Sep 13:51:59 - [red] Starting flows
5 Sep 13:51:59 - [log] [inject:tick] repeat = 500
5 Sep 13:51:59 - [log] [arduino-board:2b3d7067.ab8f5] port closed
5 Sep 13:51:59 - [red] Uncaught Exception:
5 Sep 13:51:59 - Error: Serialport not open.
at SerialPortFactory.SerialPort.write (/home/yuby/node-red-0.8.1/node_modules/arduino-firmata/node_modules/serialport/serialport.js:202:17)
at ArduinoFirmata.module.exports.ArduinoFirmata.write (/home/yuby/node-red-0.8.1/node_modules/arduino-firmata/lib/arduino-firmata.js:165:30)
at null. (/home/yuby/node-red-0.8.1/node_modules/arduino-firmata/lib/arduino-firmata.js:131:24)
at wrapper as _onTimeout
at Timer.listOnTimeout as ontimeout
How can i solve this problem?
I have an Arduino Mega 2560 and whenever using this library, I have to wait 10 seconds after connecting before sending any commands.
I've been testing with a simple LED on pin 10 and using digital_write(10, true)
. If I write within the first 10 seconds after connect
, nothing happens. Also If I write at the 9th second, I have to wait 10 more seconds before it will respond. Basically it requires 10 seconds of silence after connect
before it will start working.
However by removing the following code in arduino.rb
line 54, it only requires a 1 second delay.
(0...6).each do |i|
write(REPORT_ANALOG | i)
write 1
end
(0...2).each do |i|
write(REPORT_DIGITAL | i)
write 1
end
I'm not sure exactly why this occurring, or why that code is there, but if it's causing such a huge delay, perhaps it should be removed, or at least made optional.
this code should throw "device not found" error
arduino = ArduinoFirmata.connect
/Users/sho/.rvm/gems/ruby-1.9.2-p320/gems/serialport-1.1.0/lib/serialport.rb:16:in `create': wrong argument type (TypeError)
from /Users/sho/.rvm/gems/ruby-1.9.2-p320/gems/serialport-1.1.0/lib/serialport.rb:16:in `new'
from /Users/sho/.rvm/gems/ruby-1.9.2-p320/gems/arduino_firmata-0.2.3/lib/arduino_firmata/arduino.rb:23:in `initialize'
from /Users/sho/.rvm/gems/ruby-1.9.2-p320/gems/arduino_firmata-0.2.3/lib/arduino_firmata/main.rb:14:in `new'
from /Users/sho/.rvm/gems/ruby-1.9.2-p320/gems/arduino_firmata-0.2.3/lib/arduino_firmata/main.rb:14:in `connect'
led_stat = false
ArduinoFirmata.connect do
10.times do
digital_write 13, led_stat
led_stat = !led_stat
sleep 0.5
end
end
it makes too many callbacks.
arduino.on :analog_read do |pin, value|
if pin == 0
puts "analog pin #{pin} changed : #{value}"
end
end
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.