LEGO MovieMaker USB Camera with EV3 and ev3dev
Some (but not all) USB webcams will work on LEGO MINDSTORMS EV3 running ev3dev. Fortunately, one of them is the camera from the LEGO Studios Steven Spielberg MovieMaker Set. The camera from the Vision Command set should have the same internals and work too, but the one I have looks like this.
First, lets make sure it works. After booting up ev3dev and plugging in the camera, open an SSH terminal and run lsusb.
robot@ev3dev:~$ lsusb Bus 001 Device 002: ID 046d:0850 Logitech, Inc. QuickCam Web Bus 001 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
It shows up as a Logitech webcam. Now lets see if we can take a picture. Here is a nice list of Linux webcam apps that I found. Many of these are available as Debian packages. I’m going to try fswebcam since it is a command line application. Some other command line programs are motion and uvccapture.
robot@ev3dev:~$ sudo apt-get update [sudo] password for robot: Get:1 http://ev3dev.org jessie InRelease [8,400 B] ... Fetched 11.6 MB in 4min 0s (48.2 kB/s) Reading package lists... Done robot@ev3dev:~$ sudo apt-get install fswebcam Reading package lists... Done Building dependency tree Reading state information... Done The following extra packages will be installed: fontconfig-config fonts-dejavu-core libfontconfig1 libgd3 libvpx1 libx11-6 libx11-data libxau6 libxcb1 libxdmcp6 libxpm4 Suggested packages: libgd-tools The following NEW packages will be installed: fontconfig-config fonts-dejavu-core fswebcam libfontconfig1 libgd3 libvpx1 libx11-6 libx11-data libxau6 libxcb1 libxdmcp6 libxpm4 0 upgraded, 12 newly installed, 0 to remove and 79 not upgraded. Need to get 3,594 kB of archives. After this operation, 10.3 MB of additional disk space will be used. Do you want to continue? [Y/n] Get:1 http://ftp.debian.org/debian/ jessie/main fonts-dejavu-core all 2.34-1 [1,047 kB] ... Processing triggers for libc-bin (2.19-18+deb8u1) ...
Remember, always run apt-get update before apt-get anything else. Now, for that picture…
robot@ev3dev:~$ fswebcam test.jpg --- Opening /dev/video0... Trying source module v4l2... /dev/video0 opened. No input was specified, using the first. Adjusting resolution from 384x288 to 356x292. --- Capturing frame... Captured frame in 0.00 seconds. --- Processing captured image... Writing JPEG image to 'test.jpg'. robot@ev3dev:~$ fswebcam test.jpg --- Opening /dev/video0... Trying source module v4l2... /dev/video0 opened. No input was specified, using the first. Adjusting resolution from 384x288 to 356x292. --- Capturing frame... Captured frame in 0.00 seconds. --- Processing captured image... Writing JPEG image to 'test.jpg'.
It works! Now, there is just one problem: this camera has a 5 meter cable – way too long for putting on a robot, so let’s make it shorter.
First, remove the two screws on the bottom of the camera.
Most of the wires unplug, but there is one (the shield) that we will have to cut. Using a knife, remove the heat shrink by the strain relief. Then cut all of the wires at the strain relief. Finally, remove the strain relief itself. It may be difficult to break free, but it does come off.
Cut the USB cable to the desired length. I made mine about 50cm. Be sure to replace the strain relief before stripping the wires. It will be much easier to put on that way. Use a knife to strip the outer part of the USB cable being careful not to knick the inner wires. Use heat shrink tubing to insulate the uninsulated wire. Twist the braided shielding into a wire too. Strip the ends of the wires on both cables and tin them with solder. I also used a bigger diameter heat shrink around the whole USB cable to keep things nice and neat.
When connecting the wires, make sure to put heat shrink on first. Slide it out of the way so the heat from the soldering iron won’t shrink it. I attached the wires one at a time and then shrank the tubing over the soldered part before moving on to the next wire. Just match the colors. There are red, black, white and green plus a copper uninsulated wire and the aluminum shielding.
Once all the wires are reconnected, plug the connector back in. It’s always better to test before completely reassembling, so plug the USB cable into your EV3 or your computer and make sure the webcam still works. Once it is confirmed working, carefully cram the wires back in and replace the cover on the camera. Now you have an awesome LEGO camera to use with your EV3 without a ridiculous amount of cable getting in your way.
The folks behind LeJOS have some articles on computer vision with the EV3. Most of the information should be applicable to ev3dev as well.