Android Controlled Gondola

fullsetupUsing the Lego Mindstorms NXT robotics kit we built a remote control gondola. The MIT App Inventor package was used to create an Android phone app that controlled the gondola.

For this project we used:

• 1 Lego Mindstorms NXT brick with 1 motor and cable
• 1 Android phone
• lots of Lego bricks
• some string
• 2 adjustable mens or womens belts

The Lego Mindstorms motor should be connected in either the B or C connection on the brick.

You will need to make two gondola platforms. One with the Lego Mindstorms brick and motor, and a second platform with a wheel that can spin freely. You can have a lot of fun creating different gondola platforms. We found that some of the important points in the construction to be:

the platforms needed to be firmly secured. We put our platforms on chairs and we used belts to stop them from moving (Figure 2). A carpeted floor will help stop the chairs from slipping.

Small gondola. It’s tempting to want to make a big gondola, but we found that big gondolas had more string slippage and you had to have the gondola stations closer together.

Use wheels with grooves or rims. If you use wheels with grooves or rims the gondola string is less likely to slip out.station2

gondola

The Lego NXT brick needs to have Bluetooth turned on. Check the top left corner of the Brick’s screen to see if the Bluetooth symbol is showing. If it is not showing go into the Bluetooth options and turn visibility on.

For the Bluetooth pairing the Lego NXT needs to be turned on and your Android phone will need to have Bluetooth enabled. From your Android Bluetooth setting select “Search for Devices”. The Lego NXT brick will appear as NXT on your Android phone. On the phone select “pair with device”, and the phone pairing dialog will come up. The pairing request dialog may look different for different versions of Android, but the key is to enter the correct pairing PIN.

When the pairing is started the NXT will beep and prompt you for the pairing passkey. For the pin code (passkey) use the default of: 1234, and finish with the check mark. The pin code of 1234 is used on both the NXT and on the Android phone.

AppInventor has a set of components that will talk to the Lego Mindstorm NXT (or EV3) bricks. Below are pictures showing the our screen layouts and the key code elements.

blocks

app_layout

Wii Controlled Lego Rover

Use your Raspberry Pi (or a Linux PC) to talk to a Lego NXT rover and then use a Wii remote to drive the rover.

Python Libraries

There are 2 sets of libraries that we used:

  • nxt-python : to talk to the Lego Mindstorm NXT
  • cwiid : to talk to Wii remotes

To install these libraries:

wget https://nxt-python.googlecode.com/files/nxt-python-2.2.2.tar.gz
tar -zxvf nxt-python-2.2.2.tar.gz
cd nxt*
sudo python setup.py install
sudo apt-get install python-cwiid

The Lego NXT brick needs to have Bluetooth turned on. Check the top left corner of the Brick’s screen to see if the Bluetooth symbol is showing. If it is not showing go into the Bluetooth options and turn it on.

nxt_bt

The next step is to ensure that the Raspberry Pi can see the Lego NXT. The Pi can scan Bluetooth devices with the command:

hcitool scan

If the Bluetooth is working then you will see the Bluetooth address of the NXT., (for example: 00:16:53:04:23:3D). Using the NXT’s Bluetooth address you can pair the Pi and the Lego NXT by:

sudo bluez-simple-agent hci0 00:16:53:04:23:3D

For the pin code use the default of: 1234
The NXT will beep and prompt you for the pairing passkey.

nxt_pair

After the Raspberry Pi is paired with the Lego NXT brick you are able to use Python to read the NXT sensors and control the motors. No NXT coding is required. In the Python NXT directory there are some examples, mary.py  is a good test example because it does not require any sensors or motors.

Our full Python code to control the NXT Rover with a Wii remote is below:

import cwiid
import time
import nxt.locator
from nxt.motor import *

print 'Looking for a Lego NXT ... may take up to 15 seconds...'
b = nxt.locator.find_one_brick()
print 'Lego NXT Connected'

left = Motor(b, PORT_B)
right = Motor(b, PORT_C)

print 'Press 1+2 on your Wiimote now...'
wii = cwiid.Wiimote()
time.sleep(1)
wii.rpt_mode = cwiid.RPT_BTN 
print 'WII Remote Connected'

while True:
 buttons = wii.state['buttons']
 if (buttons & cwiid.BTN_LEFT):
 right.brake()
 left.run(power = 100,regulated=False)
 time.sleep(0.1)

if (buttons & cwiid.BTN_RIGHT):
 left.brake()
 right.run(power = 100,regulated=False)
 time.sleep(0.1)

if (buttons & cwiid.BTN_UP):
 right.run(power = 100,regulated=False)
 left.run(power = 100,regulated=False)
 time.sleep(0.1)

if (buttons & cwiid.BTN_DOWN):
 left.brake()
 right.brake()
 time.sleep(0.1)