Close

Camera

A project log for Tote Zero

Affordable quadruped robot powered by a Pi Zero

dehipudeʃhipu 02/07/2016 at 13:400 Comments

Today I worked a little bit on adding a camera to Tote Zero. Most of this I have already done for #Pico-Kubik quadruped robot, but I thought I will do a more detailed write-up. I started by digging up from my junk pile an old camera module from a laptop. You can usually find those in electronic junk, or, failing that, buy them as spare parts for a dollar or two. Mine looked something like this:

Next I opened it and extracted the actual sensor:

The cable has a plug, for convenience. I took my ohm-meter, and checked which cables are connected to the ground. In this case it was the green one, and, of course, the shielding -- the first two pins. The rest is easy: orange and red are D+ and D-, and black is VCC. In this cable, black and brown cables are connected to the same pin. Once I knew which cable is which, I used a piece of 1.27mm pin header to connect that to a normal USB cable:

Then I needed a way to test it. I didn't feel like risking frying my laptop, so instead I took a raspberry pi and some cheap USB hub, and used that:

The camera enumerated nicely. Here's an excerpt from dmesg:

[ 3875.068666] usb 1-1.4: new high-speed USB device number 45 using dwc_otg
[ 3875.176718] usb 1-1.4: New USB device found, idVendor=174f, idProduct=5a31
[ 3875.176759] usb 1-1.4: New USB device strings: Mfr=2, Product=1, SerialNumber=3
[ 3875.176779] usb 1-1.4: Product: USB 2.0 Camera
[ 3875.176798] usb 1-1.4: Manufacturer: Sonix Technology Co., Ltd.
[ 3875.176815] usb 1-1.4: SerialNumber: SN0001
[ 3875.190376] uvcvideo: Found UVC 1.00 device USB 2.0 Camera (174f:5a31)
[ 3875.205832] input: USB 2.0 Camera as /devices/platform/soc/20980000.usb/usb1/1-1/1-1.4/1-1.4:1.0/input/input17

And here is lsusb:

Bus 001 Device 045: ID 174f:5a31 Syntek Sonix USB 2.0 Camera
Bus 001 Device 003: ID 148f:7601 Ralink Technology, Corp. 
Bus 001 Device 002: ID 1a40:0101 Terminus Technology Inc. 4-Port HUB
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Then I installed motion and tried the camera with it. I had to modify the configuration to make the stream available outside of localhost. Otherwise, it just worked:

Unfortunately, motion has quite a bit of a lag, and if I wanted to use the streaming for controlling the robot remotely, that would be unacceptable. So I decided to try mjpegstreamer. There is a simple tutorial on installing mjpegstreamer on Raspberry Pi. Of course instead of using files as input, I used input_uvs.so plugin:

./mjpg_streamer -i 'plugins/input_uvc/input_uvc.so -r 160x100 -fps 20 -y -q 40' -o 'plugins/output_http/output_http.so -w www'

With such a low resolution and quality, the streaming is quite fluent!

I noticed, that the camera module is getting quite warm while working. @Arsenijs suggested, that those laptop modules, while pretty much normal USB devices, expect lower voltage than the usual 5V. I will have to try and power it from Pi's 3.3V power and see how it works then.

I also made a plug for the Pi Zero, to save some space:

That should work, but then I can't have the WiFi dongle. I guess I will need to look into making Tote Zero compatible with the #RPi WiFi pants (or even add the ESP8266 to Tote's PCB).

Update: I made a smaller cable for the Pi Zero:

While that makes it impossible to use the WiFi dongle, I can still use OpenCV with this camera to make the robot analyze what it sees and actually do something fun.

Discussions