module Aio
{github.com/jvalencia80/aio Aio} (Arduino Input/Output) is a robust library with built-in redundancy check for data integrity and command confirmation for remotely controlling {arduino.cc Arduino} boards using Ruby code and the serial port.
It implements lots of functions found in the {arduino.cc/en/Reference/HomePage Arduino Reference} and they even share the same names and parameters for an easier experience.
-
Currently, these boards are fully supported (and many others should work):
-
UNO, Duemilanove, Diecimila, Pro
-
Leonardo, Yun, Micro
-
Mega, Mega 2560, Mega ADK
-
Nano, Mini, Fio, Pro Mini
-
-
Supported functions implemented in the {Aio::Board
Aio::Board
} class:-
pinMode
-
digitalRead, digitalWrite
-
analogRead, analogWrite, analogReference
-
millis
-
-
Supported constants:
-
Other supported functions (see {Aio::Helpers
Aio::Helpers
} module):-
lowByte, highByte, bit, bitClear, bitSet, bitRead, bitWrite
-
min, max, abs, pow, sqrt, map, constrain
-
sin, cos, tan
-
random, randomSeed
-
Example¶ ↑
Blinking a LED:
require "aio" Aio::Board.new("/dev/ttyUSB0") do |board| sleep 0.1 until board.ready? board.pinMode(13, Aio::OUTPUT) 5.times do board.digitalWrite(13, Aio::HIGH) sleep 0.5 board.digitalWrite(13, Aio::LOW) sleep 0.5 end end
Check more examples at the {github.com/jvalencia80/aio/tree/master/examples Github} page.
Installation¶ ↑
-
Install the {rubygems.org/gems/aio Aio} gem:
$ gem install aio
-
Print the sketch required by the library:
$ aiosketch > sketch.ino
or
$ ruby -raio -e "Aio.print_sketch" > sketch.ino
-
Compile and burn the sketch using the {arduino.cc/en/Main/Software Arduino IDE}.
Limitations¶ ↑
-
As this library uses the Arduino serial port, digital pins 0 and 1 must not be used.
-
This library code isn’t executed in realtime as Arduino does, and the communication protocol is relatively slow, so trying to make code that requires exact timing is tricky.
-
Also take into account that this library does not check if PIN X is available in BOARD Z, or if the value supplied is valid or not for a specific command, so check your board’s documentation first.
-
This library is NOT thread safe.
Issues¶ ↑
Post any issues at the {github.com/jvalencia80/aio/issues Github issue tracker}.
Constants
- ACK
- BAUDRATE
Baud rate (shared with the sketch).
Changing it requires printing and burning the sketch again.
- DEFAULT
- EXTERNAL
- HIGH
- INPUT
- INPUT_PULLUP
- INTERNAL
- INTERNAL1V1
- INTERNAL2V56
- LOW
- NAK
- OUTPUT
- SKETCH
Arduino sketch written in C.
- SYNCBYTE
- TIMEOUT
Read timeout in milliseconds (shared with the sketch).
Changing it requires printing and burning the sketch again.
Public Class Methods
Prints the Arduino sketch to STDOUT.
@return [nil]
# File lib/aio.rb, line 103 def self.print_sketch STDOUT.puts SKETCH.gsub(/\t/,'') nil end