Sniff is a "Scratch-like" programming language that's designed to help Scratchers move gently from Scratch to more conventional languages. They can start writing programs, without having to learn a new language because Sniff is based on Scratch. They learn a little more about variables, compiling, syntax errors (!), and they can have fun controlling real hardware while they're doing it.

Monday, 1 September 2014

First Steps onto the Lego EV3

Admit it - you want a Lego EV3 kit. Of course its strictly for serious academic work related reasons... its not that a giant Lego robot is seriously cool.  The only thing that stands between you and world domination is the £300 cost. Lego sell the EV3 brick by itself in their online store, but that's £200 which actually seems even worse value. Your inner child says I WANT, but your outer adult just has to explain to your inner child how credit cards really work...

The EV3 has a lot of potential as a Sniff platform. Lego is instantly accessible, and familiar to pretty much everyone, so building machines from Lego and programming them in Sniff is pretty attractive. It's been on the radar for a while, but the up front cost meant it kept getting put off...

Then a few days ago I found a few EV3 bricks for £75 on Ebay... While the full EV3 robot kit would be nice, I do already have quite a lot of lego (I mean my kids have quite a lot of lego!), and I'm really interested in the programming side of the thing (honest!). I can pick up a few sensors and motors as I need them for about £20 each.

At £75 the brick is still pretty expensive compared to an arduino Uno clone, but about the same as a Yun. For your cash you get something that's designed to be dropped, has a nice screen, LEDs, and buttons, includes bluetooth (with iPhone support), runs Linux on a 300MHz ARM, and has LEGO written on it. The whole thing is really nice quality, so on balance (at that price!) its really good value for money if we can get it to play nice...

So having got my hands on an EV3, the first stage of getting Sniff running, is getting C programs running. While you'd think this is pretty easy, the resources out there can be pretty confusing (to be fair the EV3 is still pretty new, so a lot of users are transitioning form NXT, so there's jumble of info on the different systems). The best resource is However as setting this up is going to be a pre-requisite to any Sniff system, here's a walk through of setting up a Mac or Linux box as a dev platform for EV3.

Lets get the ARM tool chain up and running on a generic Linux.

The standard compiler that seems to be used with the EV3 Code Sourcery lite. You could build gcc from source, but CS is a free dowload:

wget -c

tar -jxvf arm-2009q1-203-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2

This puts the executables into a folder called arm-2009q1/bin so add that to your path:

export PATH=$PATH:[wherever you put it]/arm-2009q1/bin

One gotcha is that CS is a 32bit binary, so you might need to install the 32 bit compatabiltiy libs on your machine. On Centos the command to do that is:

sudo yum install compat-libstdc++-296.i686

Similar libs will exist on your preferred Linux. I used Centos for testing, not because its good, but because its so far behind Debian and Ubuntu that if it works on Centos it'll probably work anywhere!

Next we just need to compile a C program:

arm-none-linux-gnueabi-gcc hello.c -o hello

And On Mac!

Unfortunatly Code Sourcery isn't distributed officially for Mac, and its a pain to build yourself. However some nice people have done the work for you and you can download an unofficial package from here:

Install the package, and then add to your path:

export PATH=$PATH:/usr/local/carlson-minot/crosscompilers/bin

Get Networking ...erm... working?

While the EV3 supports communication over bluetooth and usb, the only way to get directly into the Linux side of the EV3 is to use WIFI. You'll need to get hold of a Netgear WNA1100 wifi dongle. Nothing else will work. You may or may not be able to get them officially from Lego (at Lego prices), but ebay will get you one for less than £10 (While you're on Ebay pick up a microSD card too). Plug in the dongle, and turn it on from the bricks settings menu. You'll also need to select the network, and enter any passwords. You can also configure and set it up from the Lego desktop software (having connected the brick via USB), which is probably easier.

From the Brick's "Brick Info" screen you should be able to find the IP address (something like Alternativly you can download my EV3 Finder. Run it on your computer and it should print out the addresses of any EV3's on the local network. This serves as a handy check that everything is working.

 Now from your desktop, you can log into the EV3 by typing:


(or whatever your number was).

 log in as root (no password!).  At this point you'll find a pretty generic, embedded Linux installation. Once you've got over the novelty of poking round Lego Unix(How cool is that!!) Then run "dropbear" which starts ssh services, so we'll be able to copy programs onto the EV3.

Transfer and Run

Back on the desktop machine we can copy the program we compiled earlier onto the EV's SD card by running:

scp hello root@

Then use telnet (or ssh) to access the EV3 again, and you can run the program by typing


And that's it - we've got a working development system which lets its compile C code, and run it on the EV3. From there its a few minor tweaks to take Sniff and get it running. The current state is that the Sniff core system is running fine, with support for the buttons, LED's and Screen. Bounce Out is running nicely! I'll post a release "real soon", so you can get started. Motors and Sensor support will follow after that.

No comments:

Post a Comment