I have a YUN and I want to take a picture with it. I have a book called: Internet of Things with the Arduino Yun by Marco Schwartz. Like a lot of these book it take a few leaps of faith — but overall I am happy.
I wanted to test the web cam feature — cause someone told me that “the world is like all about image man”. And i plan to prove them wrong.
I needed a webcam (and it had to be UVC compatible). Went to a big box ignored the stares from the staff when asked them about UVC driver compatibility. They suggested I needed a new computer cause they never heard of a Yun (nor arduino) — I let that one slide. Fortunately know some model numbers from here and bought a cheap one.
Purchased logitech c270
Using my newly formatted sd card — I was away to the races.
You need to ssh into the Yun linux processor to install necessary software onto the Yun. From the terminal in your laptop —
ssh root@ IP_OF_YOUR_YUN
password: YOUR_PASSWORD
You should now be at command line prompt in your Yun. You will be logged in as root so will have a ‘~’ prompt.
You can <code>cd / and ls -al </code> to see the usual linux file structure.
As per above book installed several packages:
opkg update
opkg install kmod-video-uvc
opkg install fswebcam
Packages installed, sd card inserted, camera plugged to Yun usb (check ,check, check) — take a picture.
at command line type
fswebcam test.png
Fail. Got this:
--- Opening /dev/video0...
Trying source module v4l2...
/dev/video0 opened.
No input was specified, using the first.
Adjusting resolution from 384x288 to 352x288.
--- Capturing frame...
VIDIOC_DQBUF: No such device
No frames captured.
At this point I look for the trouble shooting section of the book. Nothing. I like this book, I do, really, but a couple of crumbs regarding what can go wrong wouldn’t hurt.
Some google advice from the raspberry pi community suggests that this is not uncommon. But they suggest is has to do with power — which may be, but I am attached to a wall outlet so I really hope not.
At command line try the picture with a little more feedback ( add a -v :: for verbose):
fswebcam test.png -v
now I get error above plus:
src_v4l2_set_pix_format,554: 0: [0x56595559] 'YUYV' (YUV 4:2:2 (YUYV))
src_v4l2_set_pix_format,554: 1: [0x47504A4D] 'MJPG' (MJPEG)
the camera seems to only produce these formats. Man page time — the pallet switch helped me out:
fswebcam --help
-p, --palette Try to use the specified image format when capturing the image. Default is to select one automatically. Supported formats: PNG JPEG MJPEG RGB32 RGB24 BGR32 BGR24 YUYV UYVY YUV420P BAYER RGB565 RGB555 GREY
I try
fswebcam -p YUYV test.png -v
And I get a picture. Cool.
Some messing around suggests I only need the -p YUYV
switch the first time after re-boot. I can leave out after that — YMMV.
So now the second ( and subsequent) pictures can be captured like this:
fswebcam test.png
Note:: that the image is stored in what ever directory your using when you type above command. So I suggest you nav over to your sd card before taking any more pics (and maybe delete those first few unless they are keepers). Assuming your card is in the default location.
cd /mnt/sda1
now type to snap a shot. it will be on your card!
Excellent. The book suggests you unmount the card and put in your laptop and look at your pic — and this works to be sure — (NOTE that unmount command skips the first ‘n’ — umount — so you will get a command not found error if you type it human style).
nav away from the card — you will get a resource busy otherwise.
cd ~
umount /dev/sda1
sd card is unmounted -- safe to pull it out.
stick card in laptop nifty you have a camera (sort of).
But this whole mount / unmount — move card thing gets old the second time. But fortunately really smart people exist and they knew about setting up the /arduino/www directory. Check it out.
Follow the instructions at above and now you can command line click in your Yun and web browser view your pics from your laptop — no card swap needed.
That’s cool.
A couple of other things I learned along the way ….
dmesg
To see kernel messages — these should include a block about your camera and a block about your sd card.
you can also try:
lsusb
To see the USB devices connected (including your camera and card reader).
lsmod
To list modules including the libraries installed above.
RESOURCES: