artoo-raspi
artoo-raspi copied to clipboard
raspi + servo motor
Is it possible to run servo motor with raspi adapter? Artoo documentation (http://artoo.io/documentation/platforms/raspberry-pi/#Drivers) says it is. However I've got error running next code
require 'artoo'
# Circuit and schematic here: http://arduino.cc/en/Tutorial/Sweep
connection :raspi, :adaptor => :raspi
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
Error
I, [2015-11-13T07:28:30.949952 #2363] INFO -- : Registering connection 'raspi'...
I, [2015-11-13T07:28:30.952048 #2363] INFO -- : Registering device 'board'...
I, [2015-11-13T07:28:30.953788 #2363] INFO -- : Registering device 'servo'...
I, [2015-11-13T07:28:30.955761 #2363] INFO -- : Preparing work...
I, [2015-11-13T07:28:30.969973 #2363] INFO -- : Initializing artoo::connection raspi...
I, [2015-11-13T07:28:31.114995 #2363] INFO -- : Initializing artoo::device board...
I, [2015-11-13T07:28:31.152516 #2363] INFO -- : Initializing artoo::device servo...
I, [2015-11-13T07:28:31.210104 #2363] INFO -- : Starting work...
I, [2015-11-13T07:28:31.216927 #2363] INFO -- : Connecting to 'raspi' on port 'none'...
I, [2015-11-13T07:28:31.267642 #2363] INFO -- : Starting driver 'Artoo::Drivers::DeviceInfo'...
I, [2015-11-13T07:28:31.269770 #2363] INFO -- : Starting driver 'Artoo::Drivers::Servo'...
Firmware name: Raspberry Pi
Firmata version: 0.6.1
E, [2015-11-13T07:28:31.374009 #2363] ERROR -- : Actor crashed!
NoMethodError: undefined method `servo_write' for nil:NilClass
/home/pi/.rvm/gems/ruby-head/gems/artoo-raspi-0.6.1/lib/artoo/adaptors/raspi.rb:109:in `method_missing'
/home/pi/.rvm/gems/ruby-head/gems/celluloid-0.16.0/lib/celluloid/calls.rb:26:in `public_send'
/home/pi/.rvm/gems/ruby-head/gems/celluloid-0.16.0/lib/celluloid/calls.rb:26:in `dispatch'
/home/pi/.rvm/gems/ruby-head/gems/celluloid-0.16.0/lib/celluloid/calls.rb:63:in `dispatch'
/home/pi/.rvm/gems/ruby-head/gems/celluloid-0.16.0/lib/celluloid/cell.rb:60:in `block in invoke'
/home/pi/.rvm/gems/ruby-head/gems/celluloid-0.16.0/lib/celluloid/cell.rb:71:in `block in task'
/home/pi/.rvm/gems/ruby-head/gems/celluloid-0.16.0/lib/celluloid/actor.rb:357:in `block in task'
/home/pi/.rvm/gems/ruby-head/gems/celluloid-0.16.0/lib/celluloid/tasks.rb:57:in `block in initialize'
/home/pi/.rvm/gems/ruby-head/gems/celluloid-0.16.0/lib/celluloid/tasks/task_fiber.rb:15:in `block in create'
Disconnecting all PWM pins...E, [2015-11-13T07:28:31.377007 #2363] ERROR -- : undefined method `servo_write' for nil:NilClass
What have I done wrong?
P.S. Thank you for the great gem!
Hi, @forme
To use PWM with the Raspi, you need to install/run Pi Blaster https://github.com/sarfata/pi-blaster
In addition, you still can only use certain pins for PWM, as documented in Pi Blaster.
Hope that helps!