More than just bricks... LEGO MINDSTORMS EV3 robots, LEGO projects, building instructions and programming cool robots. Wed, 08 Jul 2015 05:01:21 +0000 en-GB hourly 1 Time-lapse video using EV3 and webcam Tue, 07 Jul 2015 13:33:01 +0000

I wanted to try making a home surveillance project using my webcam and EV3 sending images into Dropbox. But how to put the obvious time and date stamp on the images? It turns out this is really easy to do using the Graphics2D Java class! A short tutorial on how to do this…

Java provides the Graphics2D class to do simple image manipulation natively. The nice thing about working with leJOS is that you can take advantage of all the existing Java classes in your code that runs on the EV3.

I used my previous code and added a call to the Graphics2D library to overlay the date and time. The thing to remember here is that you have to account for the font size when choosing the x,y location to place the text.

    * Add overlay text with the current UTC date and battery voltage level onto the image
    * Text colour, font and size can be adjusted below
    * @param old Original image captured from the camera
    * @return new BufferedImage that contains the original image with text overlay
   private BufferedImage addTextOverlay(BufferedImage old) {
       int w = old.getWidth();
       int h = old.getHeight();
       BufferedImage img = new BufferedImage(
               w, h, BufferedImage.TYPE_INT_RGB);
       Graphics2D g2d = img.createGraphics();
       g2d.drawImage(old, 0, 0, null);
       g2d.setFont(new Font("Serif", Font.BOLD, 15));
       // Get the current system date and time in UTC
       Date d = new Date(System.currentTimeMillis());
       String s = "" + d.toString();
       FontMetrics fm = g2d.getFontMetrics();
       int x = img.getWidth() - fm.stringWidth(s) - 5;
       int y = fm.getHeight();
       g2d.drawString(s, x, y);

       // Get the current battery level in mV
       s = "B: " + Battery.getVoltageMilliVolt() + " mV";
       x = img.getWidth() - fm.stringWidth(s) - 5;
       g2d.drawString(s, x, h - y - 5);
       return img;


The full code is here:

I pointed the webcam out of a window in the morning and left the EV3 running on battery power for the day. I was curious how long the battery would last for! It turns out about 7 hours is the answer. After running for that long I had over 2500 images in my Dropbox directory, which I then stitched together into a timelapse video. Cool!

]]> 0
Webcam + leJOS + Dropbox = wow! Sat, 25 Apr 2015 15:29:43 +0000

Now that we have my EV3 connected to Dropbox, let’s have some fun. In this project I use a cheap webcam connected to the EV3 to take a photo and upload it into my Dropbox account. It’s a wireless digital camera using the EV3 and Dropbox!

2015-04-25 16.08.27

I recently bought a cheap webcam and USB hub at Frys electronics. This particular webcam (it cost me about $6) uses the RealTek chipset. leJOS 0.9.0 adds webcam support, and you can read more about it in Lawrie’s tutorial here:

I figured I could do one better, and capture files from the webcam, convert them to JPG and then use the Dropbox Core API to upload them into my Dropbox account. Let’s see how to do it!

I’m assuming you’ve connected your EV3 to your Dropbox as I explained in this tutorial.

Accessing the webcam

LeJOS 0.9.0 release added basic webcam support; only one webcam is supported and the images are returned in YUYV format. But that’s enough to have some fun with.  This little program will capture an image from the webcam and convert it to JPG format and then save it into the directory snapshots/with an incrementing filename. For fun you’ll also get a live image preview (in black and white) on the EV3 screen as well!


Here I ran the Snapshot.jar from the command line. It reads the access-token.json file we created in the previous tutorial and uses that to authorise access to my Dropbox folder. When I press the ENTER button the code converts the YUYV format into JPG format, saves it to the EV3 SDcard and then uploads to Dropbox using the Dropbox API. The basics of uploading files in Dropbox is explained here:


The picture above shows what the output is – as you capture images they are uploaded into Dropbox and appear in Finder on my Mac always instantly. The images are at a 160×120 resolution as that is the size of the EV3 screen, but the camera supports much higher res images. Behold The Power of the Cloud!

The Code

The Java code is a combination of the leJOS webcam streaming tutorial code and the Dropbox Java tutorial code. Not the prettiest I’ll admit…

import java.awt.image.BufferedImage;
import java.util.Locale;

import javax.imageio.ImageIO;

import lejos.hardware.BrickFinder;
import lejos.hardware.Button;
import lejos.hardware.Sound;
import lejos.hardware.ev3.EV3;
import lejos.hardware.lcd.GraphicsLCD;
import lejos.hardware.lcd.LCD;

import com.dropbox.core.*;
import com.dropbox.core.json.JsonReader;
import com.dropbox.core.util.IOUtil;

 * Use a cheap webcam to take a snapshot and send the image to Dropbox.
 * Requires a Dropbox authorisation token to be created
 * EV3 needs to be connected to the wifi and the webcam connected too.
 * Requires leJOS 0.9.0 release and some setup. 
 * See for Dropbox-leJOS setup
 * Press ENTER button to take a photo. You should see it appear in your Dropbox folder
 * @author mcrosbie
 * April 2015

public class Snapshot {
   private static final int WIDTH = 160;
   private static final int HEIGHT = 120;
   private static int NUM_PIXELS = WIDTH * HEIGHT;
   private static int FRAME_SIZE = NUM_PIXELS * 2;
   private static final String AUTHFILENAME = "./access-token.json";
   private static final String FILENAME = "snapshots/snapshot_";

   public static void main(String args[]) throws IOException, DbxException {
	   int ret = _main(args);
   public static int _main(String[] args) throws IOException, DbxException  {
       int frames = 0;
       int threshold;
       // Default to access token file if not on cmd line
       String argAuthFile;
	   if (args.length != 1) {
		   argAuthFile = AUTHFILENAME;
	   } else {
		   argAuthFile = args[0];

       System.out.println("Reading auth info file " + argAuthFile);
       // Read auth info file.
       DbxAuthInfo authInfo;
       try {
           authInfo = DbxAuthInfo.Reader.readFromFile(argAuthFile);
       } catch (JsonReader.FileLoadException ex) {
         System.err.println("Error loading <auth-file>: " + ex.getMessage());
         return 1;
       System.out.println("Creating Dropbox client...");

       // Create a DbxClient to make API calls.
       String userLocale = Locale.getDefault().toString();
       DbxRequestConfig requestConfig = new DbxRequestConfig("Snapshot", userLocale);
       DbxClient dbxClient = new DbxClient(requestConfig, authInfo.accessToken,;
       System.out.println("Open video camera...");
       // Get the video device and open the stream
       Video video = BrickFinder.getDefault().getVideo();, HEIGHT);
       // Create the frame buffer to hold the image in
       byte[] frame = video.createFrame();
       BufferedImage img = new BufferedImage(WIDTH, HEIGHT,BufferedImage.TYPE_INT_RGB);
       YUYVImage yuyvImg = new YUYVImage(frame, video.getWidth(), video.getHeight());

       GraphicsLCD g = BrickFinder.getDefault().getGraphicsLCD();

       // Keep displaying an image. 
       // Save a file to storage when enter is pressed
       // Escape to exit
       System.out.println("Starting main capture loop...");
       while (!Button.ESCAPE.isDown()) {
    	   try {
               // Display on the EV3 screen
               threshold = yuyvImg.getMeanY();
               yuyvImg.display(g, 0, 0, threshold);
              if (Button.ENTER.isDown()) {
            	  Sound.playTone(500, 100);
                  for(int i=0;i<FRAME_SIZE;i+=4) {
                      int y1 = frame[i] & 0xFF;
                      int y2 = frame[i+2] & 0xFF;
                      int u = frame[i+1] & 0xFF;
                      int v = frame[i+3] & 0xFF;
                      int rgb1 = convertYUVtoARGB(y1,u,v);
                      int rgb2 = convertYUVtoARGB(y2,u,v);
                      img.setRGB((i % (WIDTH * 2)) / 2, i / (WIDTH * 2), rgb1);
                      img.setRGB((i % (WIDTH * 2)) / 2 + 1, i / (WIDTH * 2), rgb2);
                  // Convert the RGB image into a jpg format
                  ByteArrayOutputStream baos = new ByteArrayOutputStream();
                  ImageIO.write(img, "jpg", baos);
                  byte[] jpgImageBytes = baos.toByteArray();

                  String filename = FILENAME+frames+".jpg";
                  System.out.println("Saving image to " + filename);
                  saveImageToFile(baos.toByteArray(), filename);
                  System.out.println("Saving to Dropbox");
                  writeImageToDropbox(dbxClient, baos.toByteArray(), "/"+filename);
    	   } catch (IOException ioe) {
	           System.out.println("Driver exception: " + ioe.getMessage());
	           return 1;
      return 0;
    * Save an image file from the webcam to disk
    * @param img - image byte buffer
    * @param filename - file to store to
   public static void saveImageToFile(byte[] img, String filename) {
	   try {
		   FileOutputStream fos = new FileOutputStream(filename);
	   } catch(IOException ioe) {
           System.out.println("Driver exception: " + ioe.getMessage());		   
   private static void writeImageToDropbox(DbxClient dbxClient, byte[] img, String dbFilename) 
		   throws DbxException, IOException {
       // Make the API call to upload the file.
       DbxEntry.File metadata;
       try {
    	   metadata = dbxClient.uploadFile(dbFilename, DbxWriteMode.add(), img.length, 
    			   new ByteArrayInputStream(img));
    	   System.out.println("Metadata: " + metadata.toStringMultiline());
       } catch (DbxException ex) {
               System.out.println("Error uploading to Dropbox: " + ex.getMessage());
   private static int convertYUVtoARGB(int y, int u, int v) {
       int c = y - 16;
       int d = u - 128;
       int e = v - 128;
       int r = (298*c+409*e+128)/256;
       int g = (298*c-100*d-208*e+128)/256;
       int b = (298*c+516*d+128)/256;
       r = r>255? 255 : r<0 ? 0 : r;
       g = g>255? 255 : g<0 ? 0 : g;
       b = b>255? 255 : b<0 ? 0 : b;
       return 0xff000000 | (r<<16) | (g<<8) | b;

]]> 0
Set up Dropbox in leJOS on the EV3 Sat, 25 Apr 2015 14:34:25 +0000

NewImage.pngHere’s a quick tutorial to add Dropbox support into a Java program in leJOS 0.9.0. It turned out to be far easier than I thought! Read on to discover how you can easily upload and download files to and from your Dropbox account from the EV3 in leJOS.

Dropbox? On the EV3?

The first thing to realise is that I’m not going to show you how to install the Dropbox helper on your EV3. Instead we’re going to use the Dropbox Core Java SDK to connect our EV3 to your existing Dropbox account (free or pro, doesn’t matter) and then upload and download files into the account.

Dropbox is well known as a cloud file-sync service that ‘just works’. I’ve been using it for years, both as a pro and business user, and the software runs in the background, never complains and just gets on with the business of keeping all of your files in sync. Luckily Dropbox have extended the same simplicity to their SDK; I was amazing at just how easy it is to use the Java SDK in leJOs 0.9.0 to upload images captured from a webcam to my Dropbox account.

The Dropbox team have done a great job explaining how to use the Java SDK in a series of tutorials here:
Getting ready
There are a few steps to get everything set up, but once you’ve done the setup you won’t have to repeat it. I’m assuming that these things are in place:
  1. You have a Dropbox account
  2. You have Eclipse installed and leJOS plugin installed
  3. You have a wifi equipped EV3 connected onto your home wifi
  4. You are comfortable logging into your EV3 using ssh in the terminal; you’ll need to run a program on the command line to authorise your EV3 to talk to Dropbox.
The basic flow is to import the Dropbox Java SDK into Eclipse, and then use the Dropbox API to creation an authorisation key that allows the EV3 to talk to your Dropbox account.

Step 1: Download the Dropbox Core API

The Java SDK is here: Download the Zip file and extract it into a folder on your laptop.

Step 2: Create a new leJOS project in Eclipse

I’m assuming you have a working leJOS installation and the leJOS Eclipse plugin installed. If not, go to the leJOS website and follow the instructions on the wiki to get everything set up. Let’s call it DropboxSetup for now.

Step 3: Import the Dropbox Jar files from the SDK into your project

Right click on the DropboxDigitalCamera project, select Properties and then choose ‘Java Build Path’. Click ‘Add External JARs…” and navigate to the two JAR files in the dropbox-sdk/lib folder. Import them into the project and your build path should look something like this:

Step 4: Create a new Dropbox app

Log into your Dropbox account and then go to the page and create a new Dropbox app. Make sure you create a Dropbox API app, and give it a name. The name you choose here will be used in your Dropbox/Apps folder when the EV3 uploads and downloads files. This is safer than giving your EV3 access to the all of the files in your Dropbox account.

Step 5: Get the app key and app secret

Dropbox uses an app key and secret assigned to your app to create an access token. The access token is what you need to store on the EV3 so that it can authenticate itself to Dropbox and get access to files in your account.
If you click on the app from Step 4 in the App Console, you’ll see the App key and App secret displayed. Copy these values (obviously I’ve blurred the App key for my Dropbox account here).

Step 6: Copy the Dropbox JARs onto the EV3

The Dropbox JARs need to be copied onto the EV3. The easiest way to do this is with your file browser, or scp them from your computer to the EV3. I placed the JARs in /home/lejos/programs/lib.

Step 7: Authorise the EV3 to Dropbox, get the auth token

The last step is to log into the EV3 and run a small Java program to connect the EV3 to your Dropbox account and get the authorisation token. The auth token is saved locally on the SDcard in the EV3 and used by all subsequent programs that need to talk to Dropbox.
The code you need to run is based off the Dropbox tutorial. Copy the App key and secret into the code below and then upload it from Eclipse onto the EV3. ssh into your EV3 and run the code below on the command line as follows:
jrun -cp /home/lejos/programs/lib/dropbox-core-sdk-1.7.7.jar:/home/lejos/programs/lib/jackson-core-2.2.4.jar:GetAccessToken.jar GetAccessToken


Here is a screenshot of me running the code on my EV3. I’ve blurred out the app key and secret, and the returned authorisation code!

Step 8: You’re done!

That’s it – your EV3 is now authorised to talk to your Dropbox account, and the authorisation token is stored in the file access-token.json on the  EV3. If you lose this file it’s easy to run this program again and re-create it. But don’t share it with anyone, otherwise they can access your Dropbox account!

The code

Here's the code you need.

import com.dropbox.core.*;
import com.dropbox.core.json.JsonReader;

import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger;

import lejos.hardware.lcd.LCD;

 * An example command-line application that runs through the web-based OAuth
 * flow (using {@link DbxWebAuth}).
 * By Mark Crosbie
 * Modified from the Dropbox tutorial code
public class GetAccessToken {
	// The access token is saved in this file on the EV3 SDcard
	public static final String accessTokenFilename = "./access-token.json";
    public static void main(String[] args) throws IOException {
    	System.out.println("-- Get Dropbox auth token --");
    	System.out.println("1. Log into Dropbox and go to the App Console in your account");
    	System.out.println("2. Click on the app you created for the EV3");
    	System.out.print("3. Enter the App key value here: ");
        String appKey = new BufferedReader(new InputStreamReader(;
        if (appKey == null) {
            System.exit(1); return;
        appKey = appKey.trim();
        System.out.print("4. Enter the App secret value here: ");
        String appSecret = new BufferedReader(new InputStreamReader(;
        if (appSecret == null) {
            System.exit(1); return;
        appSecret = appSecret.trim();
    	System.out.println("5. Starting Dropbox auth flow");
    	DbxAppInfo appInfo = new DbxAppInfo(appKey, appSecret);

        String userLocale = Locale.getDefault().toString();
        DbxRequestConfig config = new DbxRequestConfig("JavaTutorial/1.0", userLocale);
        DbxWebAuthNoRedirect webAuth = new DbxWebAuthNoRedirect(config, appInfo);

        // Run through Dropbox API authorization process
        String authorizeUrl = webAuth.start();
        System.out.println("6. Go to " + authorizeUrl);
        System.out.println("7. Click \"Allow\" (you might have to log in first).");
        System.out.println("8. Copy the authorization code.");
        System.out.print("9. Enter the authorization code here: ");

        String code = new BufferedReader(new InputStreamReader(;
        if (code == null) {
            System.exit(1); return;
        code = code.trim();

        DbxAuthFinish authFinish;
        try {
            authFinish = webAuth.finish(code);
        catch (DbxException ex) {
            System.err.println("Error in DbxWebAuth.start: " + ex.getMessage());
            System.exit(1); return;

        System.out.println("10. Authorization complete.");
        System.out.println("- User ID: " + authFinish.userId);
        System.out.println("- Access Token: " + authFinish.accessToken);

        // Save auth information to output file.
        DbxAuthInfo authInfo = new DbxAuthInfo(authFinish.accessToken,;
        try {
            DbxAuthInfo.Writer.writeToFile(authInfo, accessTokenFilename);
            System.out.println("Saved authorization information to \"" + accessTokenFilename + "\".");
        catch (IOException ex) {
            System.err.println("Error saving to : " + ex.getMessage());
            System.err.println("Dumping to stderr instead:");
            DbxAuthInfo.Writer.writeToStream(authInfo, System.err);
            System.exit(1); return;
]]> 0
Book review: Lego Mindstorms EV3 Essentials eBook Wed, 21 Jan 2015 14:38:20 +0000

I received a review electronic copy of Packt Publishing’s ‘Lego Mindstorms EV3 Essentials’ book. This book covers Java and leJOS programming on the EV3, so it differs from most other books on the market in that it choose a 3rd party environment rather than relying on the Lego-supplied one. It also requires a Linux environment as you will be typing a lot of commands in the terminal. The review copy I received is in electronic format so I can’t comment on the final print quality.

The challenge with writing a book based on an evolving open-source program is that you will be forever behind the curve. Despite being a relatively new publication this book is based on the 0.8.1 release of leJOS, which has been superseded by the 0.9.0 release. The leJOS team are constantly improving the platform and making it easier to install and program, so this book has already fallen out-of-date.

Chapter 2 of the ebook opens with coverage of the Lego Mindstorms EV3, and a survey of the sensors, motors and EV3 programmable brick. While it is welcome to have this in the book the content is nothing new; multiple pictures of the major pieces with some descriptive text. You can get this from Lego’s official website, and spending the first 40 pages of the book covering it again was not needed.

In Chapter 3 the on-brick programming functions of the EV3 brick area covered. Now this is where I started to get confused; wasn’t this book meant to be about leJOS programming and more advanced topics? Chapter 3 spends 30 pages covering on-brick programming, before finally we get to…

Chapter 4: leJOS – at last! This chapter introduces the leJOS Java environment for the EV3. Now the first problem is that the instructions given here are very Linux specific, so if you have a Windows or Mac then you are out of luck. Don’t worry though; Windows users have a graphical installer available to them from the official website.

Chapter 5 discusses various ways to connect to the EV3. If you have a wifi dongle your EV3 can connect to your wifi hub and then you can simply ssh into it (or better yet, connect via the Eclipse plugin). If you don’t have a wifi dongle then you can use the USB cable and ssh to, which is the address the EV3 appears as to your PC or Mac.

This chapter spends a lot of time discussing how to configure the wifi password on the EV3 by editing the /etc/wpa_supplicant.conf file. Now this is certainly the hard-core Linux way to solve this problem, but by far the easier approach is to use the built-in wifi configuration screen on the EV3 to type in your wifi passphrase and connect automatically. This is covered in better detail at the leJOS website.

Chapter 6: this chapter covers programming the EV3 in Java, and it’s where I have a big issues with the book. It leaps into a discussion of the Gradle Java build environment. However all of the guidance on the website is around using Eclipse to do your development, with ant build files. There’s no problem in choosing an alternate build environment but I think that an introductory book should have just stuck to the standard IDE suggested by the leJOS project. Another problem in the text is that once you have compiled your program the book suggests that you remove the SDcard from the EV3 and insert it into the computer to manually copy the .class files over. But we just spent the whole last chapter configuring our wifi and setting up ssh keys to avoid this! Very confusing.

Chapter 7 covers the basic operation of moving the motor and using the touch sensor. This is so basic that it really doesn’t require a whole chapter; one program to make the motor go forwards and another to wait for a press of the touch sensor.

Chapter 8, 9 and 10 discuss building a line-follower robot (your read that right; three chapters to cover one of the most basic robots). I was disappointed to find that the code in this chapter re-invented the wheel. It built a very simple differential-drive line follower robot that used simple rotations to try and find the line. The logic of the line-follower program uses a narrow sweep to find the line and if that fails it performs a wider sweep. This is the classic single sensor approach to line-following.

The author spends 60 pages over three chapters creating the line-follower code. This is the longest treatment of a line-follower robot I have ever read. I would suggest instead presenting the final program first and then explaining the parts step-by-step. I found it very difficult to follow all of the modifications made to the source code over three chapters.

Avoiding re-inventing code is critical to bug-free programming, but the sample line-follower robot reinvents the DifferentialPilot class from leJOS. There is little point in choosing the leJOS environment if you are not going to show users how to get the most advantage from using the class library!

The code also failed to perform one of the most basic tasks of a line-following robot; calibrating the colour sensor to the line and non-line parts of the floor! It assumes that you can specify the colour of the line absolutely in the code, and there will be no interference from ambient light or noise. As anyone who has built a line-follower knows this is far from true!

So now we’ve built a basic line-follower robot and…the book is complete! Appendix A explains how to use Make in great detail (why?) and Appendix B gives two pages over to the various IDEs available for Java (again, why?)

This book does not contain building instructions, and it contains one programming project; a very simple line-following robot.

Conclusion: I’d avoid buying this book and instead use the tutorials available for free on the website. It was very disappointing, spending more time on introductory concepts instead of creating advanced projects in Java and leJOS.

]]> 0
Red Racer – a power functions racing car Sun, 21 Dec 2014 17:53:15 +0000

Sometimes it’s fun to just build something different for a change. Red Racer is my version of Sunsky’s lovely Snow White Racing Machine  which I updated to use the new power functions servo for steering and medium motor for drive. I also styled it in red.

I came across the Show White racing machine a few years ago and had saved it for a future date to build. I really liked the clean and simple lines and compact design of the original, and decided to take advantage of the Christmas holiday to build my own version.

My first challenge was that I didn’t have any of the steering parts used in the original racer! Time for some thinking…if I was going to change how the steering worked I may as well upgrade the steering to use the new power functions servo motor.

Luckily Sunsky’s post on the original design had presented detailed disassembly instructions so I was able to build an initial version of the racer, and then modify it to use the new Power Functions motor and servo. I had to widen the chassis by one stud so that everything would fit, and increase the length too so the servo would fit.

The original car was styled in white, but I chose red as I did not have enough white pieces. One thing I learned from this build; I’ve a lot to learn about designing bodies for cars!

2014-12-20 23.39.36 HDR 2014-12-20 23.46.19 HDR 2014-12-20 23.46.08 HDR 2014-12-20 23.45.55 HDR 2014-12-20 23.45.35 HDR 2014-12-20 23.45.17 HDR 2014-12-20 23.45.05 HDR 2014-12-20 23.45.00 HDR 2014-12-20 23.44.43

]]> 0
Review: The Lego Mindstorms EV3 Idea Book Sat, 13 Dec 2014 23:20:27 +0000 EV3-IB_cover-front_newYoshihito Isogawa is well known for his excellent Technic Idea book series, and now he is back with an idea book targeted for the EV3. The ideas are as imaginative as ever, captured in Isogawa-san’s signature style of close-up images. Read on for my review of The Lego Mindstorms EV3 Idea Book from NoStarch Press…

The first thing to note about this book, unlike many other Mindstorms EV3 publications, is that it is not about building robots. In a way this makes Yoshihito’s book unique in that it focuses on techniques you can incorporate into your own creations instead of presenting you with amazing fully realised robots. The book is also not about EV3 programming, in fact most of the designs in the book require nothing more than a motor and an on-off switch!

Who is this book for?

It’s for anyone who wants to move beyond the models in the EV3 Home set and try to build their own robots. You may be frustrated at how complex it is to build using studless Lego beams. Or you may wonder how some of the advanced robots you see on other websites work. Those builders have mastered the art of taking simple building techniques and using them at scale. Once you learn the same basic building techniques you can apply them over and over again in your creations. This book will start you on the road to learning those building techniques.


So what is in the book? Well you are in for a treat; 181 different builds ranging from simple gear ratios to walking robots using only the parts in the retail Lego Mindstorms EV3 31313 set.

The book is broken into 6 broad topic areas:

  1. Basic mechanisms: gets you up and running with gear ratios, worm drives, changing the angle of rotation, reciprocating mechanisms and other techniques.
  2. Vehicles: now we start to move with various ways of building wheeled and tracked vehicles.
  3. Moving without wheels: ditch the wheel and walk using legs!
  4. Arms, Wing and other Movements: if you want to adorn your robot with droppers, flapping wings or interesting movements this section presents some ideas. I particularly like the ‘lifting things’ section that presents designs for simple forklift and scissor jack lifting mechanisms that could be built into any robot.
  5. Using sensors: this section is specific to the EV3 sensors and shows how to trigger them using different mechanisms. If you ever had the original Constructopedia from the first Mindstorms RIS set then this will bring back memories!
  6. Something extra: this section shows how to join beams at an angle using the Pythagorean theorem, and how to build a stand for an iPad.

Some sample images

These images give you a sense for the quality of the artwork in the book. Each of these models is constructed in multiple steps, but the book does not give traditional Lego step-by-step building instructions. You will need to do a little detective work to figure out how to build each model from the parts in the EV3 kit, but don’t worry, each model is shown from multiple angles and tricky steps are explained clearly.


The production quality of the book is very high. I really like the new wide-format and glossy colours that NoStarch are using for this book, and the previous two books from Sariel.

2014-12-07 10.55.40


This is a must-have book for any aspiring robot-builder to have on their bookshelf. You will find yourself returning to it over and again to look up building techniques. I have only had my copy for a week and it’s already very well thumbed!

]]> 0
‘Incredible Lego Technic’ book review Wed, 19 Nov 2014 16:07:46 +0000

I was fortunate enough to receive a review copy of Sariel’s latest book titled Incredible Lego Technic and published by NoStarch Press. Unlike Sariel’s previous book this is a compendium of amazing and inspiring Lego Technic models by builders around the world. You won’t find detailed building instructions here, instead each model is presented in stunning colour with a description of the model and some history behind the original design.

One thing I really liked about this book was the lay-flat binding allowed the book to stay open on the desk as I read. This is a book where you can dip in and out and read about models that interest you, or pick a specific model and spend some time studying it. The production values are very high, with the technical advisor Eric Albrecht (aka Blackbird) ensuring that each model is well presented.

2014-11-15 14.33.06

Cover of book

Lay-flat binding makes reading easy

Lay-flat binding makes reading easy


The models are split into sections by theme. There’s something here for everyone, whether you like earth movers or supercars!

  1. Agricultural – tractors and other farm equipment
  2. Aircraft
  3. Automotive
  4. Construction equipment
  5. Miscellaneous
  6. Motorbikes
  7. Supercars
  8. Tracked Vehicles
  9. Trucks
  10. Watercraft

One improvement I would suggest is to include a link to a webpage or Brickshelf gallery for each model so that you can read more once you find something that interests you.

High resolution images

Here are some samples from the book in high-resolution so you can see the details of each model.

]]> 0
Photos of EV3 Space Invaders model build Sun, 13 Jul 2014 15:49:21 +0000

A blog reader asked if I had created building instructions for my Lego EV3 Space Invaders model. Unfortunately I never did create them before taking the model apart. But I did the next best thing; I took pictures as I took it apart! The Space Invaders model is broken down into 3 modules; the coin reader, the frame holding the EV3 and the joystick module. They snap together into the final assembly.

Take a look at these pictures and see what improvements you can come up with – I’m sure there are many!

Apologies for the pictures – I snapped these with my phone so the quality is so-so.

2014-06-13 20.02.29 HDR 2014-06-13 20.02.19 HDR 2014-06-13 20.02.10 HDR 2014-06-13 20.01.59 HDR 2014-06-13 20.01.53 HDR 2014-06-13 20.01.52 2014-06-13 20.01.44 HDR 2014-06-13 20.01.32 HDR 2014-06-13 20.01.31 2014-06-13 20.01.19 HDR 2014-06-13 20.01.07 2014-06-13 20.00.55 HDR 2014-06-13 20.00.38 HDR 2014-06-13 20.00.14 2014-06-13 20.00.04 2014-06-13 19.59.51 2014-06-13 20.00.29 HDR
]]> 0
Review: Lego Mindstorms EV3 discovery book Mon, 07 Jul 2014 19:40:10 +0000

I was very excited to receive a copy of Laurens Valk’s latest book; The Lego Mindstorms EV3 Discovery Book published by NoStarch Press. You may know Laurens from his previous Lego Mindstorms titles, and if you own any of his previous works you’ll know he puts considerable time and attention into his books . This edition is targeted at the new Mindstorms EV3 kit, and is of the same high quality.

I decided to jump in at the end and build one of the more advanced models; an autonomous roving grabber arm. The lift and grab mechanism on this robot has to be seen in action to be believed – a single motor closes the grabber and raises the arm in one motion. Laurens has done a good job describing how the mechanism works as it is complex. The building instructions, like the rest of the book, and printed in high-quality 4-colour and are some of the best I’ve seen in a book that did not come from Lego.

2014-06-14 11.37.50 2014-06-14 11.37.28 EV3DB_070-071_web EV3DB_146-147_web

What else is in the book? Laurens covers the basics of the EV3 set, and focuses on programming in the graphical language provided by Lego. Along the way he makes the concepts introduced more concrete by demonstrating how they make different robots work. I like how at the end of each chapter there are suggestions for ways to try more advance approaches to make your robot do more.

What about the robots? I’m delighted to see that Laurens has provided building instructions for six (yes 6!) new robots that haven’t been seen before. These are:

  1. The EXPLOR3R, a wheeled vehicle that uses sensors to navigate around a room and follow lines
  2. The FORMULA EV3 RACE CAR, a streamlined remote-controlled race car
  3. ANTY, a six-legged walking creature that adapts its behavior to its surroundings
  4. SK3TCHBOT, a robot that lets you play games on the EV3 screen
  5. The SNATCH3R, a robotic arm that can autonomously find, grab, lift, and move the infrared beacon
  6. LAVA R3X, a humanoid robot that walks and talks

This is a must-have book if you want to learn more about building and programming EV3 robots. Nice work Laurens!

]]> 0
Space Invaders written in Java for the LEGO Mindstorms EV3 Tue, 27 May 2014 02:05:32 +0000

Space Invaders! The classic arcade game is back, and this time built using a single Lego Mindstorms EV3 kit.

I decide to write this game in leJOS using the 0.8.1-beta release (see the leJOS wiki for more on getting it installed). I contemplated writing it in the EV3 graphical language but the thought of coding the invader movements made me cry, so Java it is!

What’s does this little game have in it? A coin reader that waits for you to put a coin in the slot before you can play the game (just like in the arcade), a theme tune playing in the background, realistic space invader movements, a joystick using an EV3 large servo motor and invaders that fire at you as you shot at them.


Invaders Insert Coininvaders2

Graphics and Sounds

leJOS supports simple graphics using the Image class. An Image is a series of bytes that describe a graphics object on the screen. Unfortunately you can’t take a standard graphics format such as PNG or JPG and display it on the EV3 screen. The EV3 uses a LEGO image format and the leJOS code expects the image to display to be in this format. However the EV3Control tool provided with leJOS 0.8.1-beta allows you to convert between a bitmap file and the EV3 image format.

I used Paintbrush to create the original graphics for my Space Invaders. Paintbrush is a basic image drawing program for Mac OS, which suits my needs perfectly. Each invader is a 20×20 pixel bitmap which I draw by hand. The player’s ship is also a 20×20 pixel bitmap file. I then used EV3Control to convert the bitmaps into EV3 images. These files are available in this ZIP file: ImageFiles

  • Invader bitmap files. Two versions for each move of the invader: one and two.
  • Ship bitmap file
  • Explosion bitmap.
  • Invader EV3 image file.
  • Ship EV3 image file.
  • Explosion image file.

I made a little theme tune to play while the game waits for you to enter a coin. I composed this using Garage Band on my iPad and then downsampled it into an 8-bit WAV file to play on the EV3. Sorry about the quality. Download it here: Theme2

You will need to copy the EV3 image files and the sound file into the same directory holding the Space Invaders jar file on the EV3 using scp. This would require you to use the Terminal and type the following commands. I assume you have your EV3 connected via a USB cable, if you use wifi then replace with the IP address of your EV3 shown on the display. The root password on the EV3 is r00tme.

scp Theme2.m4a root@

scp invader1.lni root@

scp invader2.lni root@

scp ship.lni root@

scp explosion.lni root@

Program Structure

The code is broken down into a number of class each of which implement a basic function. I make heavy use of Java threads to keep everything moving in parallel.

  • Sprite: the Sprite class represents an image on the screen at an x,y position. Each Sprite class holds a single image and can render it onto the screen, erase it or move it. The Sprite class is used by the Ship and Invader classes to represent the graphics on the screen.
  • Score: the Score class represents the player’s score, number of lives left and ammo remaining. The score class runs as a thread to update the score on the screen.
  • Invader: represents a single space invader on the screen. An invader has an x,y position and can move sideways and down. The invader understands that when it reaches the edge of the screen it has to change directions and move down a line.
  • Invaders: this class represents all of the invaders currently left in the game. The invaders are stored in an ArrayList of Invader class objects. Each invader is placed along a grid at its starting position when the constructor is called. Each time the invaders move I iterate over this list and tell each invader to move itself on the screen. If an invader is shot down then I simply delete it from the ArrayList and it disappears off the screen. The invaders run on their own thread so that they keep moving in the background.
  • Ship: the player’s ship. This class handles reading from the joystick to control the ship movement and firing missiles at the invaders. It also runs as a thread so the player can always move the ship.
  • Missile: a single missile fired by either a player or an invader. The direction of travel is controlled by the movingUp boolean variable set when the missile is created. A missile is just a 3×3 rectangle on the screen as it is faster to draw than an image. A missile runs as a thread so that it continues to move until it either goes off the edge of the screen or intersects with another sprite.
  • Missiles: represents all of the missiles currently fired in the game. The key feature of this class is to run a thread to periodically check which missiles have hit which objects. If a missile has hit an invader then the player scores a point. If the missile has hit the ship then the player loses a life.
  • SpaceInvaders: the main class that starts everything running.

How to play

Here’s how to play the Space Invaders game:

  1. Install leJOS for the EV3 on an SD card and boot your EV3.
  2. Copy the class files into a new project, or just grab the SpaceInvaders.jar.
  3. Copy the image files into /home/lejos/programs
  4. Run Space Invaders
  5. Insert a coin!
  6. Move the joystick left/right to move the ship and the touch sensor fires missiles.
  7. You start with 50 ammo so use it wisely!
  8. The invaders will be shooting at you so dodge their bullets while firing your missiles.
  9. Remember the lower down the screen the invaders get the faster they move!


  • All of the image files as a zip: ImageFiles
  • The compiled Space Invaders executable jar file ready to run on the EV3. Compressed as a ZIP file. SpaceInvaders.jar
  • The Space invaders theme tune in wav format compressed to 8 bit for the EV3. Groovy! Theme2
  • If you prefer you can download and import the SpaceInvaders Eclipse project and import it into your workspace in Eclipse. SpaceInvaders


2014-05-26 14.58.472014-05-26 14.59.10 HDR 2014-05-26 14.58.57 2014-05-26 15.01.19 2014-05-26 15.00.46 2014-05-26 15.00.38 2014-05-26 15.00.26 2014-05-26 15.00.19 2014-05-26 14.59.43 2014-05-26 14.59.10

]]> 11