Build cool stuff with littleBits, a Pi, and some Lego Bricks

Raspberry Pi with a Wii Remote

A remote controller is another way to control the rover (Figure 7). We chose to use a Wii remote, which needs the cwiid Python library to communicate via Bluetooth. To install this package, enter:

Figure 7: The final rover configuration with the Wii remote.
sudo apt-get install python-cwiid

We used the simple test program shown in Listing 4 to verify that the Pi and the Wii remote were communicating. To get the program to see the Wii remote, you need to push the buttons labeled 1 and 2 at the same time.

Listing 4

01 #
02 # Simple test code to show that a Wii remote is talking
03 #
04 import time
05 import cwiid
07 print 'Press button 1+2 on your Wiimote now...'
08 wii = cwiid.Wiimote()
10 time.sleep(1)
12 wii.rpt_mode = cwiid.RPT_BTN
13 print 'WII Remote Connected'
15 while True:
16     buttons = wii.state['buttons']
18     if (buttons & cwiid.BTN_UP):
19         print 'up button'
20         time.sleep(0.2)
22     if (buttons & cwiid.BTN_DOWN):
23         print 'down button'
24         time.sleep(0.2)

For the final application (Listing 5), we translated the Wii commands into the keyboard commands and wrote to the USB port as before. In lines 17-31, you can see that pressing the upper side of the control pad at the top of the Wii remote sends a g, for go, and pressing the bottom side sends an s, for stop; pressing the left side sends an l, for left, and pressing the right side sends an r, for right.

Listing 5

01 #
02 # - Wii remote sends commands to a littleBits Arduino via the USB
03 #
04 import serial
05 import time
06 import cwiid
08 print 'Press 1+2 on your Wiimote now...'
09 wii = cwiid.Wiimote()
11 time.sleep(1)
13 wii.rpt_mode = cwiid.RPT_BTN
14 print 'WII Remote Connected'
16 littlebits = serial.Serial("/dev/ttyACM0", baudrate=9600)
17 while True:
18         buttons = wii.state['buttons']
20         if (buttons & cwiid.BTN_UP):
21                 littlebits.write('g')
22                 time.sleep(0.2)
24         if (buttons & cwiid.BTN_DOWN):
25                 littlebits.write('s')
26                 time.sleep(0.2)
28         if (buttons & cwiid.BTN_LEFT):
29                 littlebits.write('l')
30                 time.sleep(0.2)
32         if (buttons & cwiid.BTN_RIGHT):
33                 littlebits.write('r')
34                 time.sleep(0.2)


The littleBits motors cannot handle a lot of weight, so be careful when you design your rover. Cardboard, elastic bands, and tape might be a better solution than the Lego blocks we used in our project.

The littleBits modules by themselves are a ton of fun, but if you include a Raspberry Pi and some Lego bricks, there is no telling how far you can go.

The Author

Brooke and Leah Metcalfe are 12-year-old twins who live in Burlington, Canada. When they aren't doing computer projects with their dad, Pete, they like swimming, paddleboarding, and skiing.

Buy this article as PDF

Express-Checkout as PDF

Pages: 6

Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Make an Android phone app to control your littleBits projects

    Make a remote control paddleboat with the littleBits Arduino module, DC motors, and generic Bluetooth module and control the boat with a phone app that uses the MIT App Inventor package.

  • Control your littleBits projects with a homemade wireless remote

    Make a custom handheld wireless remote control with littleBits Wireless Transmitter and Receiver bits and slider, knob, button, or toggle bits.

  • Infinite Possibilities

    The open hardware movement continues to add, improve, and reinvent itself. No sooner did the Raspberry Pi Model B+ come on the scene, than the Raspberry Pi 2 debuted, adding a "1" to the name of all Rasp Pis that came before. Faster, smaller, and smarter devices appear almost daily, inspiring makers as they address ever more diverse real-world problems.

  • Build cool stuff with Lego and Pi

    By combining your Lego Mindstorms NXT, a Raspberry Pi, and some stuff from around the house, you can make some cool projects.

  • SunRover Part 2 – Solar Power Controller/Power System

    Putting power in your robot is more than just running wires – you'll need to make sure the power supply doesn't cause interference that will disrupt other components. This article explores the problem of electrical noise and describes the design for a multiplexing solar power system.