If I bought a BrickPi could I then make it so my iPhone could control my nxt?


#1

Hi all

Wondered if I bought a BrickPi I could programme it so that I could connect my iPhone via wifi or Bluetooth to control the nxt


#2

The answer is yes, at least for wifi, but it will require some work. First though you need to understand that the i{Phone will not control the BrickPi directly so this is not really a BrickPi question. Instead you use the iPhone to talk to programs running on the Raspberry PI. Those programs talk to the BrickPi. Since the PI is a linux machine and linux supports almost anything you can imagine network wise the hardest part is the iPhone. Apple is quite restrictive on what apps can do so the trick is finding an iPhone app that fits your needs.

You have quite a few choices. The most straightforward is to start a web server on the raspberry pi then write some web pages to do what you want. Then you access the web pages from a browser on any device including the iPhone. A simpler solution to implement is to use a terminal program on the iPhone (there are several good ones) and use ssh to log into the raspberry pi. That gives you a text interface to do whatever you want. A third choice is to install an X11 app on the phone. That allows you to run gui programs on the raspberry pi. For example you could run Scratch applications that way. You could even write your own dedicated iPhone app though that would be a lot of work if your are not already an iPhone developer.

Except for the small screen and the strangeness of the iPhone touchscreen pretending it is a mouse to the X11 client there is not much difference between talking to the PI from a desktop machine or from the iPhone. You can even do all development (writing BrickPi software) using the iPhone in place of a regular workstation. You basically use the iPhone as a remote terminal and let the RPI do the heavy lifting. That’s what makes BrickPI so cool.

Since we are talking about general Linux and Raspberry PI capabilities this forum is probably not the best place to get information about using the iPhone to talk to a Raspberry PI. You would probably get better answers on a Raspberry PI forum for that part of the problem.

I’m less familiar with the bluetooth options but I know you can do it.

-steve


#3

Just to reiterate on Steve’s post, yes you can. Maybe the simplest and most straightforward way is to start with one of our examples that uses browser control:

https://github.com/DexterInd/BrickPi_Python/tree/master/Project_Examples/browserBot

This is an example of controlling the BrickPi with a phone or tablet. Like Steve says, you can write a program for the BrickPi that can be controlled with your iPhone (or any other browser device with HTML5 or websockets).


#4

@keymaster. Thanks. I didn’t know about websockets. That will be useful for other projects as well.


#5

That’s what I’m intending to do with my Brickpi, albeit with Android as opposed to iPhone, but the principles are the same.

I decided to create a Python script that listens for commands on a socket, something like :

def main():
    s = socket.socket()
    host = socket.gethostname()
    port = 3033
    s.bind((host, port))
 
    print "Server listening on port {p}...".format(p=port)
 
    s.listen(5)                 # Now wait for client connection.
 
    while True:
        try:
            client, addr = s.accept()
            ready = select.select([client,],[], [],2)
            if ready[0]:
                data = client.recv(4096)
                t.add(data)
        except KeyboardInterrupt:
            print
            print "Stopping server."
            break
        except socket.error, msg:
            print "Socket error %s" % msg
            break

Then on your iPhone client open up a socket to the Pi and write commands like “MOTOR1FORWARD”, then handle those in your python script to interact with the motors.

Probably not the best solution but it does the job!