Game apps for smartphones and tablets

Research project PHBern  
HomeStart online editorAndroid TurtlegraphicsPrintJava-Online

Bluetooth connection between NXT and smartphone

In this first example, a Bluetooth connection is set up between the smartphone and the NXT robot. The program execution on NXT can be started and ended with the smartphone.

Before the first use, both devices have to be paired.
Switch on NXT and select on smartphone: Settings -Wireless and networks - Bluetooth settings



After selecting the NXT, you will be asked to enter a code Code. Enter 1234.


Show example

Edit example in the online editor

App installieren auf Smartphone oder Tablet

Program code:

package app.nxtbasic;


public class NxtBasic extends GameGrid
  public void main()
    GGConsole = GGConsole.init();
    c.println("NxtBasic starting...");
    TurtleRobot robot = new TurtleRobot(c.getActivity());
    if (!robot.isConnected())
      c.println("Connection to robot failed.");
    c.println("Working now...");
    for (int = 0; i < 4; i++)
    c.println("Connection closed.");


Explanations to the program code:
GGConsole.init() Initializes a console window on the smartphone
new TurtleRobot(c.getActivity())  
if (robot.connect() != NxtRobot.ConnectState.CONNECTED)
If the Bluetooth connection cannot be set up, the following lines are not executed
robot.exit() The Bluetooth connection to the NXT is closed