Skip to main content

Remote control and streaming video

Under Construction

Beta: 0, Gamma: 0
On a smartphone you should see beta and gamma values giving the orientation of your device. These should affect the orientation of the Pibot above. On an iPhone it should try and stay upright when viewed in landscape mode.

Rather than having to have a keyboard, mouse and screen attached to the Raspberry Pi, sometimes it would be nice to control it, and view output from it, remotely. One approach is to use an ssh client, or even a remote desktop, as described inĀ Optional set up, but this page is about more ‘user friendly’ control. The goal is to have the smartphone gyroscope control the Pibot’s behaviour. But first let’s look at using simple text-based messages to trigger behaviour on the Pibot.

The first step is to create a program on the Raspberry Pi that is capable of listening for messages coming in, and then taking appropriate action. The second step is generating messages to send to the Raspberry Pi.

Listening for messages

We will use UDP to send little text messages.

  • We need to use a Python library to enable remote control: ‘socket’ which will listen for messages.
  • The main code now starts with setting up a socket – a bit like a postbox with an address (your IP) and a number (port number, here 6005).
  • The rest of the code, in this example, just repeatedly checks for a message, turns the bytes received into a string ‘message’, and prints it out.
  • An ‘if’ statement shows how you can then take appropriate action depending on the message received.
  • In order to test this you will need to send messages, there are some free apps for iPhones and on Android that will do it.
    • For the iPhone UDP Remote from Alcorn McBride is easy to use and customisable. In Settings change the IP address and the messages generated.
    • For Android Simple UDP Tester looks like it would do the job, although there is probably a better option if you search around.

Raspberry Pi is a trademark of the Raspberry Pi Foundation