Drivers

Artoo has a extensible system for connecting to hardware devices.

Servo


Provides an interface for making servos easy to work and interact with from Artoo.

How To Connect

For Arduino:

require 'artoo'
connection :arduino, :adaptor => :firmata, :port => '127.0.0.1:8023'
device :servo, :driver => :servo, :pin => 3 # pin must be a PWM pin

For Digispark:

require 'artoo'
connection :digispark, :adaptor => :littlewire, :vendor => 0x1781, :product => 0x0c9f
device :servo, :driver => :servo, :pin => 3 # pin must be a PWM pin

How To Use

Example moves a servo from angle 0 to 90 to 180.

require 'artoo'

# Circuit and schematic here: http://arduino.cc/en/Tutorial/Sweep

#connection :arduino, :adaptor => :firmata, :port => '/dev/tty*'
connection :arduino, :adaptor => :firmata, :port => '127.0.0.1:8023'
device :board, :driver => :device_info
device :servo, :driver => :servo, :pin => 3 # pin must be a PWM pin

work do
  puts "Firmware name: #{board.firmware_name}"
  puts "Firmata version: #{board.version}"

  servo.move(0) # reset the position of the sweep (same as servo.min)

  every(2) do
    case servo.current_angle
    when 0 then servo.center
    when 90 then servo.max
    when 180 then servo.min
    end
  end
end

Commands

move(angle)

Moves the servo to the specified angle, angle must be an integer value between 0 and 180.

Params
  • ** angle ** - params
Returns

true or nil

min

Moves the servo to the angle = 0 position.

Params

no params

Returns

nil

max

Moves the servo to the angle = 180 position.

Params

no params

Returns

nil

center

Moves the servo to the angle = 90 position.

Params

no params

Returns

nil

current_angle

Returns the current angle of the servo, an integer value between 0 and 180.

Params

no params

Returns

integer (0 - 180)

Circuit

Compatibility

Important Note: You need to install pi-blaster in the raspberry-pi, this project enables PWM in the GPIO pins .