## Introduction: BricKuber Project – a Raspberry Pi Rubiks Cube Solving Robot

The BricKuber can solve a Rubik’s cube in about less than 2 minutes.

The BricKuber is an open source Rubik’s cube solving robot you can build yourself.

We wanted to build a Rubiks cube solving robot with the Raspberry Pi. Rather than go for speed, we went with simplicity: if you have a Raspberry Pi, a BrickPi kit, and a standard LEGO Mindstorms EV3 or NXT Kit, you should be able to easily follow in our footsteps. The software is written in the Python programming language. You can see all the source-code on Github here.

Background The Rubik’s cube has recently begun making a comeback. Invented in 1974, it is the world’s best-selling toy. But solving them takes thought, effort, and skill . . . so why not let a robot do it? In this project, we take a Raspberry Pi, a BrickPi, and a set of LEGO Mindstorms and build a Rubik’s cube solving robot. Simply place an unsolved Rubik’s cube in the solver, run the python program, and your Rubik’s cube is solved! The project uses the Pi to directly solve the Rubik’s cube. The BrickPi3 takes the unsolved Rubik’s cube and the Raspberry Pi takes a picture of each side of the Rubik’s cube with the Raspberry Pi Camera. The Pi creates a text map of the color squares that shows where they are located on the cube. When it has fully mapped the cube, the Pi uses the “kociemba” python library to map out the moves needed to solve the Rubik’s cube. This information is taken by the Pi and BrickPi3 to solve the Rubik’s cube using the LEGO motors. The result: a solved Rubik’s cube.

## Step 2: Build It

Building the Solver

This design was inspired by the MindCub3r design for LEGO EV3. To build the BricKuber, start by building the MindCub3r. Full LEGO building instructions can be found here.

The Rubiks cube solver design has three major moving parts. The first is a cradle to hold the Rubik’s cube. The second is the shuffler, an arm that is used to turn the Rubik’s cube over.

Finally, we add a camera arm. In the original design by MindCubr, this held the EV3 color sensor over the Rubik’s cube. In our modified design, it holds a Raspberry Pi Camera over the Rubik’s cube. We use two LEGO Mindstorms motors to manipulate the cube: the first sits below the cradle to rotate the cube, and the second moves the shuffler arm to spin the cube on an opposite axis.

Assemble the BrickPi3

You can find assembly instructions for the BrickPi3 here. We will need to assemble the case, attach the BrickPi3, the Raspberry Pi, the Raspberry Pi Camera, add an SD Card, and add batteries. To make the software easier to setup, Raspbian for Robots comes with most of the software you will need already setup. You will need at least an 8 GB SD Card, and you will want to expand the disk to fit the full size of the SD Card.

Attach the BrickPi3

We add the BrickPi3 to the LEGO assembly. We used the LEGO EV3 “wings” to support the BrickPi3 and make it level with the BricKuber body. This is a good step to add 8XAA batteries to the power pack and attach the BrickPi3 power pack to the LEGO assembly. For programming you can power the BrickPi3 via USB power to the Raspberry Pi, however to move the motors you will need to supply power with the Power Pack.

Connect the Motors to the BrickPi3

Attach the Shuffler Motor to motor port “MD”. Attach the cradle motor to the “MA” port on the BrickPi3. Attach the Camera sensor motor to the “MC” port (this is the smaller servo-like motor). Even though we won’t be moving the camera, you may want to adjust the location of the camera using the motors.

Attach the Raspberry Pi Camera

Using the LEGO Camera support, attach the camera. The small black lens of the camera should fit between the two LEGO beam supports. Secure the camera in place to the LEGO supports with some electrical tape. This is a good time to make sure that the camera is position to be able to capture the entire Rubik’s cube. You can take a test picture with the raspistill command

raspistill -o cam.jpg

Check that the cube is well-centered in the middle of the picture.

## Step 3: Prep the Software

You can use any version of Raspbian or Raspbian for Robots, our custom image that comes with the BrickPi3 already installed. If you use a standard version of Raspbian, you can install the BrickPi3 libraries using the command

sudo curl -kL dexterindustries.com/update_brickpi3 | bash

This step will install all the libraries needed to run the BrickPi3 on your Raspbian Image. Skip this step if you’re using Raspbian for Robots: the BrickPi3 is already installed.

Finally, install all project dependencies using the command:

sudo curl https://raw.githubusercontent.com/DexterInd/Brick... | bash

For this step your BrickPi3 will need to be connected to the internet. There are a number of libraries that the project depends on, including some crucial ones by Daniel Walton (@dwalton76) on Github, that are used to solve the Rubik’s cube.

## Step 4: Solve a Rubik’s Cube

Place an unsolved Rubik’s cube in the cradle. Run the command

sudo python ~/Dexter/BrickPi3/Projects/BricKuber/BricKuber.py

The robot will turn the cube to each face and the camera will take 6 pictures, one of each side of the Cube. The Raspberry Pi will determine the cube configuration from the six pictures. The Cube configuration will be passed to the kociemba Python library to find an efficient solution. Finally, the robot will execute the moves to solve the Rubik’s Cube!

## Step 5: ​The Source Code

All of the source code for the BricKuber can be found in our open source github repo here.

This project uses the following software packages installed by the command

install_brickuber.sh

Participated in the
Raspberry Pi Contest 2017