For a recent project, we attempted to build a hexapod that would carry a beer from the kitchen to my study, so I didn’t have to get up and get the damn thing. One of the interesting plans was to be able to teach it new paths and record the path so that it could replay the path later – set and forget navigation. That never quite worked out, but a few people on some forums have expressed interest in what we *did* get up and running – the hexapod had a raspberry pi with a camera and wireless module, and I wrote an interface to run on a PC that could connect to the Pi, stream the video and steer it over wifi.
So this is a little tutorial on how to achieve that.
First thing – get your wifi dongle working. there are a bunch of instructions for that depending on model. Make sure you can connect to it from whatever PC you’ll eventually be using to control. Similarly, make sure the camera works locally.
Once you have the camera and the wifi working, we can put them together. The video and the UI are separate things – it might be easiest to set up the streaming video first. I just followed this tutorial:
Streaming video on the Raspberry Pi
You can see the stream in a standard browser. Later we’ll integrate it with commands to the arduino, but for now, check that works.
Now we’ll start at the arduino and work backwards. This is a pretty straightforward piece of code that listens for serial comms, and uses the data to “walk”. Here we’re just turning LEDs on so you don’t need a hexapod – you’ll get both LEDs for forwards, one on for turning each way, both off for “stopped”.
Here’s the code: Arduino serial LEDs
It’s pretty straightforward – it listens for serial data, and if the data is “1”, “2”, “3” or “4”, it takes appropriate action – left, right, forward, stop.
You can install that on an arduino with an LED on pins 6 and 7, and send commands from the serial monitor to see it work before moving on.
The next step is to install a daemon on the Raspberry Pi to listen for TCP data. Again, sometimes the easiest way is to use other people’s code. This one worked perfectly for me:
TCP to Serial for Arduino
That’s all for the raspberry pi. Test each of those things – connect to the stream with a browser, telnet to the TCP port and send control bytes, etc. When you’re happy with that, here’s the python:
RPI Streaming UI
That should run under python 2.7. Porting the stream to Python3 is an exercise for the reader – I ended up using the browser for the stream and a static picture for the UI, because it was difficult to get streaming working under openCV in python3. Oh well 🙂
In theory, that’s it. When you run the python script on the PC you want to use for control, it should connect to the Pi, stream the video and send control signals to turn LEDs on and off.
Hope it’s useful!