[driver] Problem with /dev/video0

This is where you talk about the EV3 software itself, installation issues, and programming talk.

Moderators: roger, gloomyandy, skoehler

[driver] Problem with /dev/video0

Postby esmetaman » Thu Sep 19, 2013 7:46 pm

Hi,

I am trying to connect a webcam in EV3 and Linux detect the device:

Code: Select all
root@EV3:~/lejos/examples/5# lsusb
Bus 001 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 002: ID 05e3:0608 Genesys Logic, Inc. USB-2.0 4-Port HUB
Bus 001 Device 003: ID 0bda:8176 Realtek Semiconductor Corp.
Bus 001 Device 004: ID 046d:08ad Logitech, Inc. QuickCam Communicate STX


But later,

I don't now that device in /dev

Code: Select all
root@EV3:/dev# ls
block               mtdblock3           tty38
bus                 mtdblock4           tty39
char                network_latency     tty4
console             network_throughput  tty40
cpu_dma_latency     null                tty41
disk                ptmx                tty42
fb                  pts                 tty43
fb0                 ptyp0               tty44
full                ptyp1               tty45
i2c-1               ptyp2               tty46
initctl             ptyp3               tty47
kmem                ptyp4               tty48
kmsg                ptyp5               tty49
lms_analog          ptyp6               tty5
lms_bt              ptyp7               tty50
lms_dcm             ram0                tty51
lms_iic             random              tty52
lms_motor           rtc                 tty53
lms_power           rtc0                tty54
lms_pwm             shm                 tty55
lms_sound           tty                 tty56
lms_tst_pin         tty0                tty57
lms_tst_uart        tty1                tty58
lms_uart            tty10               tty59
lms_ui              tty11               tty6
lms_update          tty12               tty60
lms_usbdev          tty13               tty61
lms_usbhost         tty14               tty62
loop0               tty15               tty63
loop1               tty16               tty7
loop2               tty17               tty8
loop3               tty18               tty9
loop4               tty19               ttyS0
loop5               tty2                ttyS1
loop6               tty20               ttyS2
loop7               tty21               ttyp0
mem                 tty22               ttyp1
mmcblk0             tty23               ttyp2
mmcblk0p1           tty24               ttyp3
mmcblk0p2           tty25               ttyp4
mtd0                tty26               ttyp5
mtd0ro              tty27               ttyp6
mtd1                tty28               ttyp7
mtd1ro              tty29               udev_network_queue
mtd2                tty3                urandom
mtd2ro              tty30               vcs
mtd3                tty31               vcs1
mtd3ro              tty32               vcsa
mtd4                tty33               vcsa1
mtd4ro              tty34               watchdog
mtdblock0           tty35               zero
mtdblock1           tty36
mtdblock2           tty37
root@EV3:/dev#


In ubuntu, when I connect the same webcam, I say it in /dev/video1.

What is the problem?

Cheers
Last edited by esmetaman on Thu Oct 03, 2013 8:10 pm, edited 1 time in total.
Juan Antonio Breña Moral
http://www.juanantonio.info/lejos-ebook/
http://www.roboticaenlaescuela.es
User avatar
esmetaman
Advanced Member
 
Posts: 238
Joined: Wed Sep 13, 2006 12:16 am
Location: Madrid, Spain

Re: Problem with /dev/video0

Postby skoehler » Thu Sep 19, 2013 7:57 pm

Well, that's because you ubuntu has the corresponding kernel modules install. If you want video camera support for the EV3, you will have to add the kernel modules.

Well, assuming that you have the kernel modules in place, how would you access the camera?
skoehler
leJOS Team Member
 
Posts: 1350
Joined: Thu Oct 30, 2008 4:54 pm

Re: Problem with /dev/video0

Postby esmetaman » Thu Sep 19, 2013 8:19 pm

Well, I suppose that you know OpenCV. OpenCV is the best way to do something about ComputerVision, but in this small environment, I am not sure if OpenCV is possible to install, so I was surfing on internet to know a low level way. Linux has a video library: v4l
http://linuxtv.org/downloads/v4l-dvb-apis/

But at the moment, I am not able to run with this API, but finding in internet, I found a very simple example:

Code: Select all
#include <stdio.h>
#include <stdlib.h>
#define SIZE 307200 // number of pixels (640x480 for my webcam)
int main() {
FILE *camera, *grab;
camera=fopen("/dev/video0", "rb");
grab=fopen("grab.raw", "wb");
float data[SIZE];
fread(data, sizeof(data[0]), SIZE, camera);
fwrite(data, sizeof(data[0]), SIZE, grab);
fclose(camera);
fclose(grab);
return 0;
}


Code: Select all
gcc -o snap camera.c


and with this webcam, I am able to store a frame from a webcam, but I think that it is not the right way to handle a webcam, but it is a beginning. :)
Juan Antonio Breña Moral
http://www.juanantonio.info/lejos-ebook/
http://www.roboticaenlaescuela.es
User avatar
esmetaman
Advanced Member
 
Posts: 238
Joined: Wed Sep 13, 2006 12:16 am
Location: Madrid, Spain

Re: Problem with /dev/video0

Postby topikachu » Sun Sep 22, 2013 3:36 am

http://git.kernel.org/cgit/linux/kernel ... xt?id=HEAD
zc3xx 046d:08ad Logitech QCCommunicate STX

You need zc3xx module and it's dependency.

Make the system recognize and initialize your webcam correctly first.
topikachu
Novice
 
Posts: 32
Joined: Wed Sep 18, 2013 3:27 am

Re: Problem with /dev/video0

Postby esmetaman » Sun Sep 22, 2013 10:16 am

Hi,

many thanks, because you found the sources for that webcam.

Code: Select all
root@EV3:~/lejos/examples/5# lsusb
Bus 001 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 002: ID 05e3:0608 Genesys Logic, Inc. USB-2.0 4-Port HUB
Bus 001 Device 003: ID 0bda:8176 Realtek Semiconductor Corp.
Bus 001 Device 004: ID 046d:08ad Logitech, Inc. QuickCam Communicate STX


But, how to update script to build kernel?
http://sourceforge.net/p/lejos/ev3/ci/m ... ee/kernel/

My questions are:

Where I have to locate this module in filesystem in ubuntu to build kernel?
Is it necessary to update the file: build_kernel.sh?
Once I have built kernel, what is the next task? Normally, I have created a bootable SD using the guide:
http://sourceforge.net/p/lejos/wiki/Cre ... SD%20card/
Downloading image from URL:
http://sourceforge.net/p/lejos/ev3/ci/m ... ee/sdcard/ (lejosimage.bz2)
If I turn on EV3 brick with new kernel, the module is added automaticale or I have to add manually using insmod ./webcam.ko

Many thanks in advance.

Cheers
Juan Antonio Breña Moral
http://www.juanantonio.info/lejos-ebook/
http://www.roboticaenlaescuela.es
User avatar
esmetaman
Advanced Member
 
Posts: 238
Joined: Wed Sep 13, 2006 12:16 am
Location: Madrid, Spain

Re: Problem with /dev/video0

Postby topikachu » Sun Sep 22, 2013 2:22 pm

You need to build from kernel source.
It seems Andy uses different kernel from the one lego released https://github.com/mindboards/ev3sources/
So if you use 0.3 alpha version, ask Andy where to download the kernel source and other tools

Also you need to setup the tool chain to build the kernel.
Then
Code: Select all
make menuconfig ARCH=arm
to config the right module. It's better to start with a pre-config one. For example http://sourceforge.net/p/lejos/ev3/ci/0 ... ard.config

Save your new config to overwrite LEGOBoard.config and use Andy's build kernel script
or
Save to default .config and
Code: Select all
make modules ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi-


Don't burn the image (sdcard image) at this time

Just boot lejos on your brick and copy the new modules to the system by sftp. Enable the modules by insmod. Connect your webcam and see whether there' s a /dev/vidoe0
If works, copy your new module to lejosfs and modify http://sourceforge.net/p/lejos/ev3/ci/0 ... s/bin/init to insert your modules at system start.
topikachu
Novice
 
Posts: 32
Joined: Wed Sep 18, 2013 3:27 am

Re: Problem with /dev/video0

Postby esmetaman » Thu Oct 03, 2013 8:08 pm

Hi,

Now, with release 0.4, in GIT repository exist this folders:

Code: Select all
kernel
modules
sdcard


Project sdcard is the final step used to follow Wiki document to create a bootable SD Card:
http://sourceforge.net/p/lejos/wiki/Cre ... SD%20card/

But, with the new organization, what is the first step to add a new module?

I checked your link today:
http://git.kernel.org/cgit/linux/kernel ... xt?id=HEAD

But I didn't see any link to download sources to compile. I tried to surf in the web, but I didn't find a good location to download that module.

Using the project organization:

    kernel
    modules

Where is the best place to paste that module?
maybe this path: ./kernel/modules/lib/2.6.33-rc4/kernel/drivers ?

In previous posts, you said:

Also you need to setup the tool chain to build the kernel.


I suppose that the script to build is this one: build_kernel.sh
Is it correct?
I tried to execute, but I receive the following messages:

Code: Select all
./build_kernel.sh: line 22: cd: ./linux-03.20.00.13: No such file or directory
make: *** No rule to make target `distclean'.  Stop.
cp: cannot stat `pru-firmware-05-31-2011-1423-v3.0/PRU_SUART_Emulation.bin': No such file or directory
cp: cannot stat `pru-firmware-05-31-2011-1423-v3.0/PRU_SUART_Emulation.bin': No such file or directory
make: *** No targets specified and no makefile found.  Stop.
make: Nothing to be done for `uImage'.
cp: cannot stat `arch/arm/boot/uImage': No such file or directory
make: Nothing to be done for `modules'.
make: *** No rule to make target `modules_install'.  Stop.


Once the script would run in the right way, is the script's output the file named "uImage"?

What is the purpose of the folder: "modules"?

In the project sdcard in the path: sdcard/external appear the file: uImage. Is the same file from the project kernel?
I saw the file that you said: sourceforge.net/p/lejos/ev3/ci/0.3.0-aplha/tree/sdcard/lejosfs/home/root/lejos/bin/init to add the support for new driver.
I tested the script setup.sh from project sdcard. This script generate the file: lejosimage.bz2

Conclusions:

    Where is the best place to download sources for zc3xx or linux drivers in general?
    What is the best place to locate new kernel module with this project organization?
    Is a good idea to update the script: build_kernel.sh to compile that sources?
    Once, driver is compiled, where is the right location?

This evening, I discovered this book, it is free:
http://lwn.net/Kernel/LDD3/

Many thanks in advance.

Juan Antonio
Juan Antonio Breña Moral
http://www.juanantonio.info/lejos-ebook/
http://www.roboticaenlaescuela.es
User avatar
esmetaman
Advanced Member
 
Posts: 238
Joined: Wed Sep 13, 2006 12:16 am
Location: Madrid, Spain

Re: [driver] Problem with /dev/video0

Postby gloomyandy » Thu Oct 03, 2013 9:15 pm

I'm sorry I don't have the time at the moment to write a tutorial on building Linux modules. But the following may help.....

The source used for the leJOS kernel is a patched version of the Lego kernel source. All of the required source is included in the leJOS git repo as two tar files. The setup.sh file in the kernel project will extract the kernel and backports code and patch them as required. Then you can run the build scripts to build the kernel and additional backports modules, make sure you build the kernel first. You will need the gcc cross compiler installed and configured as per the env_setup command. I use the tools recommend by Lego to do this, no idea if others work.

Building modules for the EV3 is not trivial, the kernel is old and often the source you find on the web will be for a newer kernel. Also many of the build scripts do not work in a cross compiler setup particularly the modules make install step. Pleas be careful if you don't know what you are doing as it is easy to end up overwriting modules on your Linux system with arm versions!

Good luck...

Andy
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3645
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK


Return to EV3 Software

Who is online

Users browsing this forum: Baidu [Spider] and 1 guest

more stuff