Pages

Monday 2 July 2012

em28xx procedure

This is my em28xx procedure to get a working capture device running on a raspberry pi from an empty SD card. It is a bit crude - but it worked for me. These notes are primarily for my own benefit, so may not be as thorough as they could be... I presume there must be an easier way to build the em28xx driver without building everything each time, but this worked. I have presently dropped the RPi in favour of the BeagleBone, which doesn't seem to have any USB issues with larger image sizes. You won't see any sudo commands, other than building the wheezy image on the mac, as I log in as root on the raspberry pi

Make the disk image (mac)


diskutil list

sudo diskutil unmountDisk /dev/disk1

dd if=/Users/michael/Desktop/RaspberryPi/Images/2012-06-18-wheezy-beta.img of=/dev/disk1 bs=1m

boot the pi with new card

apt-get update && apt-get upgrade
apt-get install git ffmpeg motion libncurses5-dev

Rebuild the kernel

see;


git clone --depth 1 https://github.com/raspberrypi/linux.git

cd linux

zcat /proc/config.gz > .config


make menuconfig

(enable i2c and em28xx stuff)

make

git clone https://github.com/raspberrypi/tools

cd tools/mkimage/
python imagetool-uncompressed.py home/pi/linux/arch/arm/boot/Image

mv /boot/kernel.img /boot/kernel.old



cp kernel.img /boot/kernel.img

cd /home/pi/linux

make modules_install

reboot



update em28xx drivers

sudo apt-get install  patchutils libproc-processtable-perl

git clone git://linuxtv.org/media_build.git

cd media_build

./build

./build downloads the latest everything and tries to make it - if this works, that's great, but we need to edit em28xx-core.c and remake this. The sed command below changes height >>= norm_maxh(dev)to height = norm_maxh(dev) >> 1 in /linux/drivers/media/video/em28xx/em28xx-core.c to solve a portability issue to ARM. (Makarov, 2012)




cd linux/drivers/media/video/em28xx/


sed -i 's/height >>= norm_maxh(dev)/height = norm_maxh(dev) >> 1/' em28xx-core.c


Now build the drivers again. This time using make all instead of ./build to preserve changes to em28xx-core.c


cd media_build

make all    


make install





Note, Trying to repeat this process on another SD card has invoked an error during the ./build stage;

/home/pi/media_build/v4l/drxk_hard.c:333:3: error: implicit declaration of function '__i2c_transfer' [-Werror=implicit-function-declaration]

I'm not sure what I have done differently - but I ran make menuconfig in the media_build directory and removed any modules that 'didn't look very useful' and that fixed it.

Don't forget to edit /etc/motion/motion.conf

cd /etc/motion/motion.conf


cp motion.conf motion.conf.original


nano motion.conf

Input should be input 1 or input 0 depending on the device - if you get it wrong, and the device is working you will see a black screen (not green!). I would recommend the resolution is 320x240 for the first run. Turn on interlacing (ffmpeg_deinterlace on) and webserver (webcam_localhost off), you will probably want webconfig too (control_localhost off)... you know all this stuff. Here are some sed commands I might use next time I do this, because it's getting boring;

sed -i 's/input 8/input 0/' motion.conf


sed -i 's/ffmpeg_deinterlace off/ffmpeg_deinterlace on/' motion.conf


sed -i 's/webcam_localhost on/webcam_localhost off/' motion.conf


sed -i 's/control_localhost on/control_localhost off/' motion.conf


Then test it

motion


References

Vitaly Makarov (2011) Non-portable code in em28XX driver, available from http://www.digipedia.pl/usenet/thread/18550/7691/ , accessed 21/7/12

15 comments:

  1. I followed your direction as printed and never received any errors, but I do not get a /dev/video0 when I plug in the EasyCap.

    Here is what lsusb is telling me:
    Syntek Semiconductor Co., Ltd STK1160 Video Capture Device

    Is that the same as yours? Thanks.

    ReplyDelete
  2. No, sorry Sean - the Syntek chip is one of the other easycap devices. From what I've read it doesn't use the em28xx driver, but I don't have one so I can't offer any advice. I have an 'easycap' DC60 and a kworld usb2800.

    http://www.amazon.co.uk/KWorld-MAKER-USB2-0-VS-USB2800D-Direct/dp/B0007W5LWI/ref=cm_cr_pr_product_top

    http://www.amazon.co.uk/gp/product/B007C88ISY/

    ReplyDelete
  3. Thanks michael, I was afraid that was the case. . . . I'll keep looking for a solution. . .

    ReplyDelete
  4. Doesn't look like the em28xx will become available on ARM:
    http://www.digipedia.pl/usenet/thread/18550/32899/#post32898

    ReplyDelete
  5. Thanks for the link Tomasz. I have been looking for an alternative to em28xx.. but time and money are limiting factors. I can say for sure that cx231xx doesn't work for me on Raspberry or Beaglebone. It is also surprising how many of the £30-£40 capture cards have em28xx chips in them when you start looking for alternatives.

    I wonder if the answer might come from a usb tv dongle with video input. I am open to suggestions!

    That said - I HAVE managed to get images out of em28xx on the raspberry pi using the method above... but, as you may have seen in later posts, I haven't succeeded in doing so on the beaglebone yet. I do not think the limitation in image size is a product of the em28xx driver, moreover it seems to be something to do with the USB port.

    ReplyDelete
  6. ...although I've just tried this with the new recommended raspbian image and it's failed - so it's a flaky method at best.

    ReplyDelete
  7. Thanks for the guide.
    I have managed to get it done on my Pi without any trouble.
    Thought i cannot start Motion
    Gets to: [1] Resizing pre_capture buffer to 1 items
    [0] Thread 1 - Watchdog timeout, trying to do a graceful restart
    [0] httpd - Finishing
    [0] httpd Closing
    [0] httpd thread exit
    [0] Thread 1 - Watchdog timeout, did NOT restart graceful,killing it!
    [0] Calling vid_close() from motion_cleanup
    [0] Closing video device /dev/video0

    Then hangs there.
    Anyone got any suggestions on a fix.

    ReplyDelete
  8. As mentioned above, this doesn't work for me anymore either. This may be a change in either the raspberry pi image or the media drivers. There is a new em28xx patch, but I haven't had chance to try it yet.

    http://www.mail-archive.com/linuxtv-commits@linuxtv.org/msg14456.html

    ReplyDelete
  9. hello michael,
    thank you very much for sharing your experience, as I was trying to hard to find out solution on installing em28xx drivers on android from last month , you proved to be only solution provider..... thank u for some clue.

    Michael , as i am very new to android and linux ... i am not able to understand things clearly...

    Please guide me on my issue....please

    ?? I want to develop an android app which capture anlog video from composite port.... so i wish to use Easycap (em28xx) on my tablet PC with android (version Ice Cream Sandwich) on cortex A8 1ghz processor which has Std USB port ??

    so my queries are...
    what shud be the exact steps to do it...

    1.get android 4.0 source code
    2.get em28xx source code
    3 compile drivers
    4.make image of it(drivers + android source)
    5 remove existing android OS on tablet & then install it on tablet
    6. now i attach EasyCap to android tablet and it works???


    well steps 1 to 6 is wht i figured out...but i still don't know ...should i make image???? should i compile drivers??? sholud i format tablet??? or what ...as i don't understand anything..

    pls pls guide me...

    thank u in advance for your time.:)

    ReplyDelete
    Replies
    1. Unfortunately I can't be of much help. I don't have a great deal of experience with linux, and no experience with android. These notes are the product of much time spend on google piecing together information.

      This guide doesn't even work for the Raspberry Pi at present. I have managed to get some pictures working with the latest patch (see link above) on the Beaglebone, so I will try that on the Raspberry Pi at some point.

      Delete
  10. Hi,
    Didnt work for me.

    Before trying this, My tv tuner card was getting detected. Now there seems to be no detection after following above steps. Error: No device at /dev/video0

    ReplyDelete
  11. Hi - if you have read the earlier comments that shouldn't have come as a surprise. I've stopped trying to make this work now, even when it did work it could only sustain 320x240 due to RPI USB issues - I'm going for an off the shelf video server solution... if you go back a few steps and repeat the 'make modules install' I think that will put your old em28xx module back in for you.

    ReplyDelete
  12. OK Thanks. Any other solution for using TV tuner usb on Raspberry pi ? Do you know any other USB tv tuner device that works on Raspi ?

    Please let me know.

    Thanks.

    ReplyDelete
  13. No, none that I tried worked - I don't think any will until there's some progress with the usb port. I certainly wouldn't recommend wasting as much time and money as I did looking at this.

    ReplyDelete

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial 3.0 Unported License