Java Socket Server/Client on Raspberry Pi

In order to connect to the Raspberry Pi, we've been using either a secure shell login (ssh) or a virtual desktop (VNC). These capabilities allow to us download software and test different code vital to our project. What these do not allow is instant communication through a Java Program. Socket servers/clients will allow us to open up different ports on the Raspberry Pi and wirelessly stream data through them. For example we could open up a port that wirelessly writes numbers to a Pi-Blaster file, therefore controlling our motors.

A socket server program listens to a port. When a client tries to connect the server either allows it in or denies it access to the port. If allowed access the client and server can now communicate using UDP/TCP communication protocols.

Below is a quick explanation and example of using Socket Severs/Clients on the Raspberry Pi for PWM control.

Sockets Running Pi-Blaster:

Sending strings back and forth between a client and server uses simple InputStream()/OutputStream() commands. We needed to be able to send strings and then have them echoed to /dev/pi-blaster (command line virtualization). We had some trouble echoing commands using 'bash' from a Java program. We eventually figured it out using a Java program and Shell Script on the Raspberry Pi.

We first sent PWM values to a file called motorcontrol.sh and then use Runtime() in Java to emulate a 'bash'  command. The following is the Shell Script which 'echos' are the values we give it to /dev/pi-blaster.

The code for the Server and Client can be found on our Downloads page under Java - Socket Server.

Edit the IP address in the Client.java and Server.java files to match you specific IP requirements.

After exporting the server into a runnable .jar file copy it to the Raspberry Pi and then run it using this command:

Next run the Client on your laptop (we are just using Eclipse for now). It should look something like this:

and you have a Client/Server connection to the Raspberry Pi to run Pi-Blaster! Stay updated for instructions on how to use an XBox Controller to send values (instead of a JOptionPane).


Arduino Sensor: DS18B20 1-Wire Temp. Probe

This is the first of many posts which deal with setting up the environmental sensors on our submersible. The first sensor we experimented with was the DS18B20 Waterproof Temperature Sensor. This sensor was extremely easy to setup and therefore a good start for us.

We also decided to choose this temperature sensor because of its diverse capabilities. The DS18B20 is designed on a "1-Wire" data transfer technique. This allows for the easy addition of multiple temperature sensors on one Arduino.

Materials Needed:

  • Arduino UNO (and Arduino software)
  • DS18B20 Waterproof Temperature Sensor
  • 4.7k ohm resistor (***make sure it is 4.7k ohm NOT 4.7 ohm)
  • Wire cutters/strippers and electrical tap
  • Solder

1. Visit our Download Page and download our code + libraries in the folder: Arduino - DS18B20

2. Download the libraries and then move them into Documents---->Arduino---->Libraries (may have to make  the library folder).

3. Acquire a DS18B20. There will be three different wires (white=data, red=power, black=ground)

4. Stip off the waterproof casing from the first 6 inches of the sensor.

5. Cut both the power and data wires about 1 inch from the end of the casing.

6. Solder one side of the resistor onto the data wire and the other side to the power wire.

7. Solder on pins to the end of each sensor wire.

8. A picture of the final product is below (we recommend wrapping the open wire in electrical tape):

and this is a sketch of the setup we used (yellow=data):

and here is a picture of the sensor and our Arduino. 

9. Upload the code to the Arduino. You should see a serial monitor output (baud 9600) like this:

Stay updated for tutorials on how to use Java to display Serial Outputs from the Arduino over the Video Stream. To output the data using Python on the Raspberry Pi check out the Arduino UNO: Serial Outputs to Raspberry Pi. To use the DS18B20 through Java check out this post.


RoboGoby T-Shirt

For the past week and a half we have been coming up with ways to fundraise for our project. We have been working on an Indiegogo campaign that we will publish soon. We have also met with a few local businesses. We also came up with the idea of using t-shirts sales as fundraiser/promotion gig. We spent a while deciding what the shirt would look like. Today we finalized the image and the text on the front of the shirt.  We have decided to have a robotic looking fish that is modeled after a Goby, as well as the words, "Project RoboGoby."

Project RoboGoby Fundraising T-shirt
The entire thing was made by Nick in Photoshop Elements 8, though some pieces were modified from pictures found online. Everyone please give a BIG shout-out to Nick – he spent a ton of time on this design.

The basic shape of the fish is modeled after the dimensions and fins of a goby. We decided that the most important robotic parts would be: gears, propellors, sensors, and lights/cameras. In the end we decided to make it look fairly simple so the design isn't too overwhelming for the observer (edited out a lot of the extra material). The shirt is blue to represent underwater and the fish is green mostly because it stands our on a blue back ground. The fish is made of 28 different layers.

The back of the shirt is going to have the phrase: "Limbeck, I don't know what it means either." This is because we are always asked how we came up with the name and what it means. We are also going to order four shirts for ourselves with backs that say: "Head Engineer."

If you are interested in buying one, please fill out the form at the bottom of this page. They cost $20 plus shipping and handling ($3).

Embedding Video with VLC Media Player

VLC has a handy Java library that can be used to create an instance of the VLC media player that can be embedded in a separate Java program. This player will play any media that VLC player can play independently if it is given the correct file path to that media as well as the location to the pre-downloaded VLC libraries. This includes media streams from other devices such as internet servers. This API (Application Programming Interface) is very useful for designing your own media player in which your GUI (Graphical User Interface) foundation is a functional media stream. It is also relatively easy to set up.

  1. http://www.videolan.org/vlc/download-windows.html go to this link and download the appropriate system architecture version of the VLC installer for your operating system (64-bit or 32-bit). It is important to get the bit number right as a 32-bit VLC will not work for a 64-bit system and vice versa. 
    • make sure to note the location of the VLC folder containing its files (usually something like C:\Program Files\VideoLAN\VLC)
  2. http://www.capricasoftware.co.uk/downloads/index.html go to this website and download the latest vlcj distribution zip. Extract this to a folder of your choosing. 
  3. Open up Eclipse (we use Eclipse but if you understand how import external libraries in a different IDE then use that). Create a new project and right click on it. Select the "build path" option then select "configure build path"
  4. In the resulting window, select "add external jars" and navigate to the vlcj distribution you downloaded in step 2. Select the "jna.jar," "platform.jar," and "vlcj.jar" (note: each of those will have a version number in the name).
From there, you will need to point your program toward the VLC folder mentioned in step 1 as well as the media file you want to play. http://www.youtube.com/watch?v=orMgNh0o38A This video does a very good job of describing the basic procedure of coding a media window to play a file pointed to during run time. in order to play a video stream, you must replace the argument for 


with the url of the stream (what you might enter into a web browser to view the stream). For the MJPG-streamer software that we use, this is a little different. We pass the string 

"http://[local ip adress of stream]:port/?action=stream"

Our code for the media player will be on our Github and a link will be posted soon. 


Mechanical Testing: Motor and Prop Testing

After creating our testing tank and our setting up our sensors (for volts, amps, and newtons) we started to actually test the motors. It took about an hour to test each motor with the corresponding props in both forwards and reverse. Although the whole process took much longer because we had to try motors multiple times and we were often distracted by other parts of the project.

To test the motors we put them into our (not so much) waterproof container. We ended up flooding this container because some of the motors moved to much and caused flooding. Therefore, we had to create a constant (which was our container) to test the motors in. It was a challenge to get some of the motors into our container (particularly the Rule 1000GPH and Rule 800GPH, which we had to "carefully" force in). Another complication was making sure that the wires were fed up through the pipe to the surface of the water and were not too twisted or submerged. The rod in the top of the tank was then threaded through the pipe to act as the fulcrum of our lever. We then connected non-stretch fishing line that ran from the force plate, through the pulley and to the pipe, we had to tie it so that it was continually pulling on the container (because it would have been very hard to zero it perfectly by tying it...). We then zeroed it using Logger Pro. Lastly we connected the motors wires to the motor controller and then the controller to the battery.

The first picture below is of our testing tank from a ground perspective. The Raspberry Pi is in the foreground and the tank with the our motor controller and battery are in the background. The second picture is a front view of the tank we used for testing:

After that we had to set up the equipment for reading the data. We connecter the Vernier force plate we were using to our computer through a Lab Pro and into LoggerPro, from this we got force readings to the nearest newton (setup pictured above). To get amperage readings we used a Blue Point CAT III amp clamp connected to a Vantage graphing voltmeter. Finally for voltage we used another more basic voltmeter. We had to record our data in a google spread-sheet and then transfer it to Logger Pro because of some program limitations.

To test we needed to SSH into the Raspberry Pi and used Pi-Blaster (a PWM program) to control the motor through our motor controller. Setting PWM duty cycle signals to 25%, 50%, 75% and 100% to get a quarter, half, three-quarters and full power respectively. At each of these presets we took readings of voltage, amperage and force. We then switched out the propellor which was easy thanks to our propellor attachment design. After we had finished using all ten of our chosen propellors we would switch the direction of the entire container by switching its direction on the rod in the other direction and switching a double pole, double throw switch to change the direction of the electricity. We than ran through all of the propellors in forward and reverse giving us twenty-four data points for each test. We tested 10 different props and 3 different motors giving us a total data point set of 720.


RPi Video Streaming: MJPG-Streamer

MJPG-Streamer was the last pre-built video streaming software we tested. It was something that we had looked into earlier in the summer, but had never followed through with. It is comparatively "lighter" than both Ffmpeg and Motion. It was fairly easy to download and compile although you do have to jump through a few loopholes.

 1. Use your laptop to download and unzip the MJPG-Streamer software.

 2. Forward the folder from your desktop using a secure shell connection (scp forwarding).

3. Login to your Raspberry Pi and download the following dependencies.

--------> Update the Raspbian Operating System
--------> Install dependencies (libv4l-dev, subversion, libjpeg8-dev, imagemagick)

4. Copy the following file to a different name (MJPG-Streamer will show a make error otherwise). Try this a few times as it may not work correctly the first time.

5. Then, just for good housekeeping, Clean All and then run the Makefile.

7. Now you're ready to stream using MJPG-Streamer. Enter the following command. It will hopefully inform you that the stream is up and running. Our stream is running at 20 frames per second, at a resolution of 1280x960 pixels on the port 8092.

To customize the settings (fps, resolution, and device) you can change the values that follow these letters:

8. To view your stream open up Firefox (or Chrome) and type in the ip of the Pi followed by the port # (i.e. You should see the following:

9. Obviously you will not always want to view your stream over this page. To view this same stream directly open VLC and type in the following:

The direct stream should look like this:

After long nights testing different camera's and there capabilities we finally found one worth the effort. MJPG-Streamer is the best universal USB video streaming software we've used. We would recommend this over Motion and Ffmpeg because of its fluidity and response time. 
To see how we have integrated MJPG-Streamer into a friendly Java GUI check out this post.


Choosing our Environmental Sensors

In our earlier posts we discussed using environmental sensors (salinity, temperature, pH) as well as a camera to take stock of the underwater environment around our ROV. We did some research on the different types of sensors and came up with a list of what we'd like to see on our ROV. We also talked to Research institutes (such as Gulf of Maine Reserch Institute and Bigelow Laboratories) to see what features would be useful to them. After talking with representatives from both Institutions we were able to come up with the list below:

Light Sensor

Dissolved Oxygen

Stay up-to-date and check out following posts on how to use these sensors with the Raspberry Pi and Arduino.