Sunday, June 30, 2013

Going with Raspberry Pi for HTTP communication

This is going to be the heart and soul of my project; the communication platform that allows the end user to communicate with the robot. Without a solid, reliable solution, the robot could be banging into walls or falling down steps because vital data couldn't be transferred reliably.

With the need for wireless communication to the internet router, I needed a WiFi solution. Since I know the Arduino platform pretty well now, I naturally wanted to stick with what I knew so I got an Arduino WiFi Shield and immediately ran into problems with it. The problem was multi-layered. There were multiple versions of the hardware, multiple versions of the WiFi libraries, multiple versions of example code and multiple versions of the IDE. You could only run some of the examples on 1.0.5 of the IDE and of course some of the libraries only worked with some of the hardware versions.

I actually got it to work, where I was receiving HTTP requests and serving up HTTP responses but the success was short lived due to buffer overruns, unresponsiveness and just general problems. I've played around with a Raspberry Pi in the past but have never really done anything with it. I did put Apache on it and served up some pages and it seemed pretty stable so I thought I'd give it a shot.

I had a couple concerns. One was the learning curve. I know Unix, but just enough to get work stuff done at work (building/deploying applications and writing kornshell scripts). I just never considered myself a unix guy. Their cryptic commands just really erked me so I stayed away from them. The other concern I had was how was I going to translate HTTP arguments over to Serial commands. Sounded like a pain in the butt and I didn't want to have to mess with it. I knew Arduino so I wanted to stay in that camp. When I knew that couldn't happen I thought I would give it a try.

What I ended up with was a pretty efficient way to communicate HTTP data to the Arduino via the Serial port using a USB connection. I had a couple connection options to the Arduino, I2C, UART or USB. USB I read was the easiest and since these two boards are going to be together for the entire project, I didn't see a need to mess with the other options. Hardware connection, solved. I got Apache2 up and running on the RPi so now I just needed a way to talk through it's Serial ports. I found some Python libraries that talked to the ports and did some tests and it worked. Python just seemed like an awful lot of overhead for what I wanted to do. Then I ran across this post which said you could connect your RPi to an Arduino through PHP. That seemed like a much cleaner approach so I tried that. Using a class called PHP_Serial, I was able to send data to my Arduino causing a blinky light to blink. I knew I had broken through and that this was most likely the way I was going to move forward.

One caveat was that I would have to do all of my Arduino development over on the RPi because I would need to see the Serial Monitor for debugging purposes. Since the Arduino was connected to on of the USB ports on the RPi this was the only way to go. I read that it was a pain in the butt to do but I just ran 'sudo apt-get install Arduino' on my RPi and viola, a JRE was installed and after 3 minutes or so, I had a working version of the Arduino IDE on my RPi. Pretty slick! =)

So that's where I'm at for now. I just made a backup of my RPi image, documented my findings and progress here. Now, time to do some tests with my new communication configuration!

1 comment:

  1. Indeed...Telepresence refers to a set of technologies which allow a person to feel as if they were present, to give the appearance of being present, or to have an effect, via telerobotics, at a place other than their true location.

    ReplyDelete