This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2010-05-27 21:19:19

clintonb
Scratcher
Registered: 2010-05-27
Posts: 30

BYOB for Arduino and NXT

While it isn't as easy to use as the post title might suggest, I had some success creating custom blocks in BYOB for controlling an Arduino via Catenary, and for controlling a LEGO Mindstorms NXT robot via a custom Java program.  Here are the details.

Offline

 

#2 2010-05-28 04:59:50

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: BYOB for Arduino and NXT

Cool stuff!  I love to see Scratch being further extended into interactions with the real world.  Thanks for sharing your work - it looks very useful.


http://i39.tinypic.com/2nav6o7.gif

Offline

 

#3 2010-05-28 11:19:21

chalkmarrow
Scratcher
Registered: 2007-05-18
Posts: 100+

Re: BYOB for Arduino and NXT

Agree. I really like what you did with BYOB and Catenary. It will be interesting to see how this "external sensor" functionality is handled in the next version of Scratch, which I suspect may be Flash or Javascript/HTML5 based.

Offline

 

#4 2010-05-28 11:34:52

clintonb
Scratcher
Registered: 2010-05-27
Posts: 30

Re: BYOB for Arduino and NXT

Thank you, chalkmarrow.  My suspicion is that the analogue of the external sensor functionality in Scratch 2 will be all about getting data from other websites, such as Facebook and Twitter, which sure isn't as handy for dealing directly with things in the physical world.  It will be interesting to see.

Offline

 

#5 2010-05-28 11:50:25

chalkmarrow
Scratcher
Registered: 2007-05-18
Posts: 100+

Re: BYOB for Arduino and NXT

HTML5 uses websockets, so if they go that route there may be way to use a serial proxy (maybe a version of serproxy tailored to the websocket protocol rather than TCP sockets). We'll have to see. I know that the Scratch folks are really interested in interfacing with the outside world (the room with the giant blue ceiling) so I'm confident they have something in mind  smile

Offline

 

#6 2010-05-28 12:12:37

clintonb
Scratcher
Registered: 2010-05-27
Posts: 30

Re: BYOB for Arduino and NXT

Interesting.  That is the first I've heard of websockets.  Boy, if they can pull that off ... it'll really be something.

Offline

 

#7 2010-05-28 14:30:44

chalkmarrow
Scratcher
Registered: 2007-05-18
Posts: 100+

Re: BYOB for Arduino and NXT

I'm just speculating, though. Just thinking about that as one way to do it.

Offline

 

#8 2010-05-29 23:06:30

krackers
Scratcher
Registered: 2010-05-08
Posts: 61

Re: BYOB for Arduino and NXT

YAY! I've been trying to make this with python but this is WAY easier...

And can you make a usb version? I tried changing all instances of bluetooth and bt to usb and checked the lejos site for the right commands, but it couldn't connect to nxt.

I already have a python version, but it is still unfinished and somehow doesn't connect to my computer.

I could also help you test things out and to expand the nxt version.

(I have a nxt 2.0 if it makes any difference)

Last edited by krackers (2010-05-29 23:25:16)

Offline

 

#9 2010-05-30 00:56:16

clintonb
Scratcher
Registered: 2010-05-27
Posts: 30

Re: BYOB for Arduino and NXT

Hi Krackers.

My current vision on using a Scratch-like interface with the NXT is here.

The two extremes of possible approaches are as follows:

- create custom blocks with BYOB and create a more comprehensive, and easier-to-use interface program in leJOS that stands between Scratch and the NXT.

all the way up to:

- create a custom variant of Scratch that uses a Squeak VM plugin to interface with the NXT, and do so directly without the aid of a helper program, while also allowing one to export the program for uploading onto the robot so it can run it without the computer's help.

My preferences is to go more toward the second route.  Making sure you can use USB is important to me, as it is quicker and more reliable than Bluetooth.  (Unfortunately, just using Bluetooth would be easier, as you can tell the OS to make the bluetooth connection appear as a serial port, and Scratch is already capable of sending commands over a serial port.)

I have a fair bit of learning to do first.  I'm still reading the book "Squeak By Example."  While I am a good programmer, Squeak (the language Scratch is written in) is unfamiliar to me, which makes it really hard to guess how long it'll take to do things.  My goal is to have something usable by the end of August.

I do want whatever I make to work with all the NXT sets -- The educational set, the 1.0 set, or the 2.0 set.  Most likely people will have to put a custom or updated firmware onto their NXT.

I'll be quite happy to enlist your aid in testing.

What does your Python version do, and how far did you get with it?

Offline

 

#10 2010-05-30 14:30:55

krackers
Scratcher
Registered: 2010-05-08
Posts: 61

Re: BYOB for Arduino and NXT

Ok...

The python version I made can connect with nxt over bluetooth and usb, and it acts as a relayer between byob and the nxt.

It does something similar to yours.
It allows you to get sensor data, and to send motor commands.

It utilizes a custom byob block to send sound, display, and motor commands.

For example...

The custom block "move _ seconds with _ power" does this.

The seconds variable simply repeats the command for _ seconds. The power variable sends a broadcast telling the power needed. After both those variables are set, it repeats a broadcast telling the motor to move.

It can do this for motor a,b, and c.

Same thing for a tone, except the power variable is a frequency variable, and it sends a command telling it to play the tone at _ frequency.

And the best part is that you don't need any custom firmware. All you need is python installed on your computer. Then simply install the python addons "nxt python" and "pyusb". Sometimes you may need libusb. (all of these are python addons)s

I have got one problem though. Somehow it doesn't interface with my computer over usb, and I can't test over bluetooth. It may just be my computer though. I know the usb connection is fine though. Maybe we could collaborate to achieve the ultimate goal of doing this natively in scratch/byob/whatever...

Here would be an approximate guideline for the finished product.

Use native nxt firmware.
Natively support scratch without a forwarder.
Usb and bluetooth.
And some other things I haven't thought of.

There may be a way to merge my python version with your java and integrate it into squeak...

Look into this:

http://pypysqueak.blogspot.com/

If we're going to integrate this into scratch though, we need someone from the panther team who has experience in making blocks. We can provide them with the backend, and they can just create a block that accesses that.

And for the bluetooth/ usb...

It shouldn't be that hard considering that squeak "does" have support for usb.
I would say that usb is 50% of the nxt userbase.

I give you the python file and instructions on setting it up if you want.

Last edited by krackers (2010-05-30 14:35:11)

Offline

 

#11 2010-05-31 18:01:36

clintonb
Scratcher
Registered: 2010-05-27
Posts: 30

Re: BYOB for Arduino and NXT

Krackers,

That is really cool where you go to with your python version.  Python is one of my favourite languages.  I've tried one of the Python-to-NXT libraries in the past, but had trouble getting libusb to compile and pyusb to work on my Mac.  It seems that the Bluetooth worked OK, but it was slow getting a connection.

I glanced at that PyPySqueak page.  I'm not quite sure what it is -- are they using PyPy to build a Squeak image with python bindings?  It doesn't look like it is under active development.

I'd be happy to have your help, and, if you think you can persuade a Panther developer to help out, that'd be great!  I think building custom blocks really isn't all that difficult, and is the sort of thing I'll need to be able to do to have sufficient knowledge to meet my other objectives with Enchanting.

I'm not sure what you mean about Squeak having support for USB.  Lego ships a device driver for connecting with the NXT (from Mac or Windows) that is written in C++ and called fantom.  Other people have used LibUSB under Linux to talk to an NXT over USB.  Anyways, I believe that Squeak can be extended with plugins written in C, which, in turn, can access a wrapper to code in C++ ... ultimately making it possible to add support for connecting to an NXT from Squeak.

How would you like to e-mail me?  I'd love to discuss things further with you, and find out more about what skills and passion you can bring to bear on this project.

Offline

 

#12 2010-06-01 20:02:26

krackers
Scratcher
Registered: 2010-05-08
Posts: 61

Re: BYOB for Arduino and NXT

Sent the email

Offline

 

Board footer