Discuss Scratch

jishiha
Scratcher
30 posts

Control Sphero 2.0 from Scratch

I created scratch2sphero.
With scratch2sphero, you can control Sphero 2.0 from Scratch 1.4. Tested on MacOS X(10.8.5).
It's really fun!

Some demo movies:
https://www.youtube.com/watch?v=aHL03UHULm0
https://www.youtube.com/watch?v=qCeJ6_UKnk4
abee
Scratcher
1000+ posts

Control Sphero 2.0 from Scratch

Wow. It's really awesome. I'd like to get one.
ke1235
Scratcher
100+ posts

Control Sphero 2.0 from Scratch


I tried this in Ubuntu, but I can't get it to work. It looks awesome though.

For installation, what you had wasn't , so I tried
sudo git clone https://github.com/champierre/scratch2sphero.git
and that looks like it works. Though the next part won't work.
gem install hybridgroup-serialport

ERROR: While executing gem … (Gem::FilePermissionError)
You don't have write permissions into the /var/lib/gems/1.9.1 directory.

Wait… I could use sudo. Though I think I tried that and there was an error… I'll check tomorrow.

Last edited by ke1235 (Jan. 6, 2014 03:42:13)



It's the interrobang‽Hey! You found the hidden text!
CODE:0110010001100111011010000110010001100110011001110111001101101001011100000111001100110101001101010011010101110000011001110110011001110011011001110110011000000011

Some of my projects:
———————————
Cloud Lists (230char and caps!) is letter () capital? Saving Platformer test Random question of the (usually) day! Voting Engine (limit 9 options) <You can only vote once!
technoboy10
Scratch Team
1000+ posts

Control Sphero 2.0 from Scratch

Will this work with Sphero 1.0? I recently recieved one for Christmas, and I'd love to mess with it.

my github | my blog | scratcharchive.cf
“I may not have gone where I intended to go, but I think I have ended up where I needed to be” -Douglas Adams
ke1235
Scratcher
100+ posts

Control Sphero 2.0 from Scratch

technoboy10 wrote:

Will this work with Sphero 1.0? I recently recieved one for Christmas, and I'd love to mess with it.
I don't see any reason why it wouldn't. Have fun with your sphero

Last edited by ke1235 (Jan. 6, 2014 03:38:24)



It's the interrobang‽Hey! You found the hidden text!
CODE:0110010001100111011010000110010001100110011001110111001101101001011100000111001100110101001101010011010101110000011001110110011001110011011001110110011000000011

Some of my projects:
———————————
Cloud Lists (230char and caps!) is letter () capital? Saving Platformer test Random question of the (usually) day! Voting Engine (limit 9 options) <You can only vote once!
jishiha
Scratcher
30 posts

Control Sphero 2.0 from Scratch

Thank you for your comment.
I rewrote the README.

ke1235 wrote:

I tried this in Ubuntu, but I can't get it to work. It looks awesome though.

For installation, what you had wasn't , so I tried
sudo git clone https://github.com/champierre/scratch2sphero.git
and that looks like it works. Though the next part won't work.
gem install hybridgroup-serialport

ERROR: While executing gem … (Gem::FilePermissionError)
You don't have write permissions into the /var/lib/gems/1.9.1 directory.

Wait… I could use sudo. Though I think I tried that and there was an error… I'll check tomorrow.
jishiha
Scratcher
30 posts

Control Sphero 2.0 from Scratch

I am not sure because I don't have Sphero 1.0.

technoboy10 wrote:

Will this work with Sphero 1.0? I recently recieved one for Christmas, and I'd love to mess with it.
chrisnolan
Scratcher
15 posts

Control Sphero 2.0 from Scratch

Fun stuff! Thank you for sharing. My son & I played around with it for a bit tonight. A few snags getting it up and running, and a couple of bugs once it was, but fun none the less.

I'll try to document some of the things we encountered later this weekend, and we might do a pull request thingy too if we get the color/rgb stuff in.
jishiha
Scratcher
30 posts

Control Sphero 2.0 from Scratch

Color/RGB stuff sounds great. I look forward to seeing the pull request.

chrisnolan wrote:

Fun stuff! Thank you for sharing. My son & I played around with it for a bit tonight. A few snags getting it up and running, and a couple of bugs once it was, but fun none the less.

I'll try to document some of the things we encountered later this weekend, and we might do a pull request thingy too if we get the color/rgb stuff in.
jishiha
Scratcher
30 posts

Control Sphero 2.0 from Scratch

I merged your pull request.

Scratch2Sphero now supports the color change. Very nice.

jishiha wrote:

Color/RGB stuff sounds great. I look forward to seeing the pull request.

chrisnolan wrote:

Fun stuff! Thank you for sharing. My son & I played around with it for a bit tonight. A few snags getting it up and running, and a couple of bugs once it was, but fun none the less.

I'll try to document some of the things we encountered later this weekend, and we might do a pull request thingy too if we get the color/rgb stuff in.
chrisnolan
Scratcher
15 posts

Control Sphero 2.0 from Scratch

jishiha wrote:

I merged your pull request.
Scratch2Sphero now supports the color change. Very nice.

I've sent another – for RGB support this time.

For those following the thread, here are two demo movies of the new color support added – where using Scratch you can control the colors of the lovely little robot ball Sphero.


My son used the colors to help him debug as he was programming the robot to go through a maze, he made each turn and direction change a different color so he'd know which step was going wrong.
technoboy10
Scratch Team
1000+ posts

Control Sphero 2.0 from Scratch

I'm curious, how do you detect when/where a Sphero is connected? I'm having some trouble with automatically detecting a Sphero's bluetooth serial port. Also, how did you get Sphero bluetooth connection to work on OS X?

my github | my blog | scratcharchive.cf
“I may not have gone where I intended to go, but I think I have ended up where I needed to be” -Douglas Adams
chrisnolan
Scratcher
15 posts

Control Sphero 2.0 from Scratch

technoboy10 wrote:

I'm curious, how do you detect when/where a Sphero is connected? I'm having some trouble with automatically detecting a Sphero's bluetooth serial port. Also, how did you get Sphero bluetooth connection to work on OS X?

The problem we encountered with getting it linked to the OS X machine was it was already paired with another device. It just wouldn't show up in the bluetooth list at all. We had turned off bluetooth on the ipad, and still nada. Turns out we forgot we had once paired the sphero with an iphone in the basement and it was still picking up that link. Once we turned that off it showed up in the bluetooth config list right away and paired no problem.

The program doesn't handle when it is connected and when it isn't atm. The sphero has to be on, and paired before you start the scratch2sphero script or else it won't initialize. It'll throw a ‘resource busy error’, or a ‘unknown name’ type error and you just have to restart the script a couple of times until the sphero is free. I find this when we are changing the source of the ruby program and need to frequently restart the script (I think there might be some smoother way to handle the Ctrl-C?) or if we are busy with the scratch side and the sphero goes into powersaving mode.

Scratch's remote connection seems fine between restarts of the other script, if it isn't there to receive the broadcasts they just go away, but on a new connection any global variables will be resent.

Last edited by chrisnolan (Feb. 26, 2014 14:41:31)

technoboy10
Scratch Team
1000+ posts

Control Sphero 2.0 from Scratch

I've got a Sphero extension for Scratch 2.0 if anyone wants to take a look. (Thanks to @chrisnolan for the inspiration!)
http://github.com/blockext/sphero

it's still a fairly early alpha, but most of the basics work

my github | my blog | scratcharchive.cf
“I may not have gone where I intended to go, but I think I have ended up where I needed to be” -Douglas Adams
rgodinez
New to Scratch
1 post

Control Sphero 2.0 from Scratch

Hi,

I've tested scratch2sphero on Fedora 19 (Linux), and this is what I needed to do to make it work:

These are the steps equivalent to “xcode-select –install” in OSX
Install the basic development environment for ruby-build
$ sudo yum install gcc-c++ glibc-headers openssl-devel readline libyaml-devel readline-devel zlib zlib-devel
Install the development environment for Ruby, and its dependencies
$ sudo yum install ruby-devel

$ git clone https://github.com/champierre/scratch2sphero.git
$ gem install hybridgroup-serialport
$ gem install sphero

Then, to pair and connect with the Sphero:
(from https://gist.github.com/parshap/7570754)

$ hcitool scan
Scanning …
00:06:66:49:A7:9D Sphero-OYR
$ hcitool dev
Devices:
hci0 7C:E93:B4F:39

This creates a device file as /dev/rfcomm0 for the Sphero
$ sudo rfcomm bind hci0 00:06:66:49:A7:9D

The default permissions does not allow the script scratch2sphero.rb access to the device
$ ls -l /dev/rfcomm0
crw-rw—-. 1 root dialout 216, 0 Apr 27 07:25 /dev/rfcomm0

As a workaround, change the permissions (this is dirty, and we should take care of this in a different, cleaner way) to allow anyone to access de device
$ sudo chmod 666 /dev/rfcomm0

Then I needed to introduce some changes into the scratch2sphero.rb file:
- change /dev/tty.Sphero for /dev/rfcomm0 in line 9
- add delays to allow connection for settling down and have the right bluetooth parameters available, otherwise the device is connected, but reported as “–unknown–” and the commands are not sent to the Sphero.
The values for the delays are empyrical and not always work, but most of the times are OK.

$ diff scratch2sphero.rb.orig scratch2sphero.rb
9c9,13
< sphero_tty = Dir.glob(“/dev/tty.Sphero*”).first

> # sphero_tty = Dir.glob(“/dev/tty.Sphero*”).first
> sphero_tty = Dir.glob(“/dev/rfcomm*”).first
> ##
> sleep 10
> ##
10a15,17
> ##
> sleep 15
> ##

Thanks for your work!!

Regards,
Rafa.
robertojulior
New to Scratch
2 posts

Control Sphero 2.0 from Scratch

how install it??
robertojulior
New to Scratch
2 posts

Control Sphero 2.0 from Scratch

how install it on windows??
alaindu22
Scratcher
100+ posts

Control Sphero 2.0 from Scratch

Hi
thanks for your job ( specially jishiha chrisnolan and rgodinez )
I am with puppy linux


ruby is installed
it is ok with scratch 1.4
sensor is enable and i can see (in external window with command ruby scratch2sphero.rb ) what is asked by scratch
I see the bluetooth connection (I have two bluetooth device )
hci0 and hci1
hci0 is for blueZ
hci1 is for sphero

when i use the normal scratch2sphero.rb, I see unknown

when i use rgodinez 's method and special script scrach2sphero with rfcomm0
I have the message connection reset by peer
can you help me?


if you want test puppy linux with scratch you can download packages here
http://www.murga-linux.com/puppy/viewtopic.php?t=75950

you can download bluetooth package here http://9giga.sfr.fr/n/50-17/share/LNK26994efb218fce971/
it is this package that i used for connect a wiimote by bluetooth

if you speak french, it will be easier for me
thanks

Alain


Last edited by alaindu22 (May 21, 2014 18:40:08)

alaindu22
Scratcher
100+ posts

Control Sphero 2.0 from Scratch

hi
my problem is solved
i have tested on another computer and i have only one hci device
sphero is on (light blinking) , scratch is open with a sb. file test loaded
I run scratch2sphero.rb in console after a few seconds the lights of the sphero are always on

I can move the sphero with puppy linux and scratch1.4 (light is always on )

but after a few moves (generally 7 or 8 )my sphero stopped and it is impossible to send another message to its
I have to close the console with scratch2sphero.rb
light become again blinking

and open a new console and retype scratch2sphero.rb
after this it is possible to move again the sphero but only for 7 or 8 moves

any idea to have no limit in the moves ?
thanks
Alain

ke1235
Scratcher
100+ posts

Control Sphero 2.0 from Scratch

I started trying this again, and there is just one problem I believe. It doesn't know Sphero's name, and like you said in the code, it doesn't have communication with it. Is there any temporary fix? If not, can you let me know if it gets fixed? (I'm following this topic)


It's the interrobang‽Hey! You found the hidden text!
CODE:0110010001100111011010000110010001100110011001110111001101101001011100000111001100110101001101010011010101110000011001110110011001110011011001110110011000000011

Some of my projects:
———————————
Cloud Lists (230char and caps!) is letter () capital? Saving Platformer test Random question of the (usually) day! Voting Engine (limit 9 options) <You can only vote once!

Powered by DjangoBB

Standard | Mobile