Skip to content

Instantly share code, notes, and snippets.

@deadprogram
Last active December 20, 2015 07:29
Show Gist options
  • Select an option

  • Save deadprogram/6093272 to your computer and use it in GitHub Desktop.

Select an option

Save deadprogram/6093272 to your computer and use it in GitHub Desktop.
Artoo driving a Sphero using a Pebble

Artoo Uses A Pebble To Drive A Sphero

Install

bundle install
artoo install socat

Prepare Devices

Pair The Pebble and Sphero

Pair the Pebble and Sphero devices using the Bluetooth controls provided by your operating system.

Scan To Find Bluetooth Device Info

$ artoo connect scan
         run  hcitool scan from "."
Scanning ...
  00:06:66:4A:14:99 Sphero-WRW
  00:18:33:86:37:8B Pebble 378B

Bind The Devices To Unix Ports (Linux only)

Use the information displayed from the artoo connect scan command, to bind the Pebble and Sphero to unix ports, like this:

$ artoo connect bind 00:18:33:86:37:8B pebble
         run  rfcomm -i hci0 bind /dev/rfcomm0 00:18:33:86:37:8B 1 from "."
         run  sudo ln -s /dev/rfcomm0 /dev/pebble from "."

$ artoo connect bind 00:06:66:4A:14:99 Sphero-WRW --comm=1
         run  rfcomm -i hci0 bind /dev/rfcomm1 00:06:66:4A:14:99 1 from "."
         run  sudo ln -s /dev/rfcomm1 /dev/Sphero-WRW from "."

Connect

  • Edit the Procfile to match the info used when binding the bluetooth devices
  • Run foreman:
foreman start

Foreman should start up the socket to serial connections to the Pebble and Sphero devices, and then startup the Artoo robot code.

Have fun!

Once the code is running on your computer, and is connected to the devices, you can drive your Sphero around using the Pebble watch.

  • Navigate to the "Music" screen on the Pebble watch. It should display "Left", "Roll", and "Right" matching the three buttons.
  • Push the buttons, and the Sphero should move accordingly.
  • The "Roll" button changes to "Stop" while the Sphero is moving, just in case you need to come to a quick halt.
source "http://rubygems.org"
gem 'artoo', '~> 1.0.0.rc3'
gem 'artoo-sphero', '~> 1.0.0.rc2'
gem 'artoo-pebble', '~> 1.0.0.rc2'
gem 'foreman'
require 'artoo'
connection :pebble, :adaptor => :pebble, :port => '127.0.0.1:4567', :id => "378B"
device :watch, :driver => :pebble, :connection => :pebble
connection :sphero, :adaptor => :sphero, :port => '127.0.0.1:4568'
device :sphero, :driver => :sphero, :connection => :sphero
work do
on watch, :media_control => :button_push
stopped
end
def button_push(*data)
return if data[1].nil?
case data[1].button
when :previous
move(270)
when :next
move(90)
when :playpause
if @rolling
sphero.stop
stopped
else
move(0)
end
else
puts "WAT"
end
end
def move(heading)
sphero.roll 90, heading
@rolling = true
watch.set_nowplaying_metadata("Left", "Right", "Stop")
end
def stopped
@rolling = false
watch.set_nowplaying_metadata("Left", "Right", "Roll")
end
pebble: artoo connect socat 4567 pebble --retries=3
sphero: artoo connect socat 4568 Sphero-WRW --retries=3
robot: artoo start pebble_sphero.rb --delay=10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment