Drivers

Artoo has a extensible system for connecting to hardware devices.

Maxbotix


Provides tools to use maxbotix sonar (range finder).

How To Connect

For Arduino:

require 'artoo'
connection :arduino, :adaptor => :firmata, :port => '127.0.0.1:8023'
device :sonar, :driver => :maxbotix, :pin => 0, :interval => 0.5

For Digispark:

require 'artoo'
connection :digispark, :adaptor => :littlewire, :vendor => 0x1781, :product => 0x0c9f
device :sonar, :driver => :maxbotix, :pin => 0, :interval => 0.5

How To Use

How to use events and call them on your drivers

Pretty simple, when the connection and the driver have been setup (as explained above) you can call events on them as follows:

on sonar, :range => proc { puts "range #{ sonar.range }!" }

Example: Setups a maxbotix driver and range event, displays the range every :interval amount of time.

require 'artoo'

# Circuit and schematic here: http://www.electrojoystick.com/tutorial/?page_id=285

#connection :arduino, :adaptor => :firmata, :port => '/dev/ttyACM0'
connection :arduino, :adaptor => :firmata, :port => '127.0.0.1:4567'
device :sonar, :driver => :maxbotix, :pin => 0, :interval => 0.5
device :board, :driver => :device_info

work do
  on sonar, :range => :sonar_reading

  puts "Firmware name: #{board.firmware_name}"
  puts "Firmata version: #{board.version}"
  puts "starting sonar..."
end

def sonar_reading(*args)
  puts args
end

Commands

range

Returns the distance measured by the sonar in inches.

Params

no params

Returns

distance_in_inches(float)

range_cm

Returns the distance measured by the sonar in cm.

Params

no params

Returns

distance_in_cm(float)

Events

The events will be triggered when the amount of time specified by the param :interval, when setting up the driver, passes.

start_driver

Starts the driver.

:range

Gets triggered after :interval amount of time passes, everytime the range will be read and the event triggered.

Circuit

Compatibility