Pi Zero NoIR Camera with Preview Screen


Hi there,
This is a work in progress project for making a NoIR camera with a Pi Zero and a Robopeak 2.4" display to display a preview.
After a lot of code work in a previous support article (Robopeak 2.4" Display on Pi Zero), the display part is no longer a support based issue, so the topic has been moved to projects.

Robopeak Display
Robopeak 2.4" Display on Pi Zero

Here’s what I have so far for my insane mplayer based camera script, it seems to handle resizing to the display fine and captures images in 1024x768:


mkfifo /tmp/mplayercontrol

sudo \
SDL_MOUSEDEV=/dev/null \
SDL_FBDEV=/dev/fb1 \
mplayer \
-slave \
-input file=/tmp/mplayercontrol \
-vf screenshot \
-vo sdl \
-tv driver=v4l2:device=/dev/video0:width=$CAPTURE_WIDTH:height=$CAPTURE_HEIGHT:fps=$FPS \

I dropped tap to screenshot support because mplayer was handling mouse presses and moves in weird and unpredictable ways, so it was nearly unusable and kept pausing the video stream.

Instead I’ve switched to mplayer “slave” mode, this involves a fifo through which you can send commands direct to mplayer at your heart’s content.

For example, if you run the above script (assuming everything is set up correctly, we’ll cross that bridge when it comes to it etc) you can command mplayer to take a screenshot simply by running:

echo "screenshot" > /tmp/mplayercontrol

Other mplayer commands will work, too, but I suspect most of them will be useless.


I work mainly (in fact, usually solely) with the Python languages on Pi, so most of that system configuration is waaaayyyy over my head. On a positive note, you probably know what you’re doing! :D

I’m used to using GPIO stuff on Python, but would that even be compatible with this kinda stuff. I.E; when using the button push on a Python script, would their be a cleaner way of taking a still other than getting it to system out “echo “screenshot””? That’s the way that I’d most usually use, but it’s just… Ew.

Also, my apologies for not being overly involved in the code aspects, and great thanks to you for it; I’ve got exams all over the place at the minute, so time is sparse.
I have however compiled a few images of what hardware I have for the camera in a general overview:

  • Black project box from Maplin,
  • The Pi Zero, of course (not the Zero W, though I may change my mind about that…),
  • Pi NoIR camera,
  • With a ring of 9 IR LEDs (various wavelengths),
  • 2600 mAh battery,
  • And two momentary push buttons.

I was hoping to hook the LEDs straight up to the power bank with a couple resistors in their and a button for activation just to simplify the I/O stuff. Basically making the IR LEDs optional without the need to make fancy GUI buttons and sorts


Well, after 23 days of non-stop exams I have finally gotten around to testing your script. Huzzah!
Bad news: I’m afraid it doesn’t work. Or, at least for me it doesn’t…
Long story short; I got some time and rigged together a little prototype of the camera (just the pi, camera, screen and a battery) and SSHd into the command line. I first tried your original script from the support post, but alas, it receives the same error as the new script from this post which I tried after the first failed.
Both seem to work perfetly fine, apart from that they do not recognise TV as being a file format.

mkfifo: cannot create fifo ‘/tmp/mplayercontrol’: File exists
MPlayer2 2.0-728-g2c378c7-4+b1 © 2000-2012 MPlayer Team
Cannot open file ‘/root/.mplayer/input.conf’: No such file or directory
Failed to open /root/.mplayer/input.conf.
Cannot open file ‘/etc/mplayer/input.conf’: No such file or directory
Failed to open /etc/mplayer/input.conf.

Playing tv://.
Detected file format: TV
Selected driver: v4l2
name: Video 4 Linux 2 input
author: Martin Olschewski olschewski@zpr.uni-koeln.de
comment: first try, more to come ;-)
v4l2: unable to open ‘/dev/video0’: No such file or directory
v4l2: ioctl set mute failed: Bad file descriptor
v4l2: 0 frames successfully processed, 0 frames dropped.
Opening as detected format “TV” failed.
Failed to recognize file format.

It may be due to the fact that during the install of mplayer, my apt-get decided to automatically install mplayer2, not simply mplayer, which may have caused some compatibility issues. I’m looking into this at the moment.
Here’s to finally getting this working!
As always, help is appreciated and undoubtedly needed. :)


Ooh don’t forget to: sudo modprobe bcm2835-v4l2

And see if that makes a difference!


Aha! Success! I must have missed a step. :)
Quick question: Well, two really…

  • Firstly, the preview was flipped 90* anti-clockwise from my perspective. I have the screen situated in landscape, so it’s probably an easy fix, but your bash file doesn’t seem to have any parameters for orientation?

  • Also: the image was filtered green. From what I’ve seen with the NoIR Camera, the usual image is of visible light with purple hints to suggest IR light; I don’t mind the green colour, but I just wanted to compare my results with your own tests to make sure I haven’t cross-wired any circuitry anywhere. :3



How very strange… I moved the screen position and it seems it has returned to the pink hue now. Huh! I’ll have to figure out how I did that; the green hue seemed to act as a thermal imaging camera. Would be very useful!

Anyway, everything seems to work now other than the button which I haven’t yet hooked up. I’ll keep you informed! :)

Edit:- Wait… Nope. I rebooted the Pi and it’s back to green hue thermal view… I’m confused. Any clues?


I’m afraid I haven’t played much with the NoIR so you’ve got me at a loss!

I do think this may be of interest to you, though: https://www.youtube.com/watch?v=1RJfinvFBiE


How did you know it was my Birthday? Don’t worry, I’ll save you some cake. :D Though from the title I expected it to be a tricorder. :3
However, I beat you too it, albeit a little bulkier;

Don’t worry though, I’m already waiting for new HyperPixel stock, so my refresh rates should hopefully be a little quicker. With any luck, the case should also be milled soon for a nice shiny finish, so I’ll keep updating throughout the process.

PS: I’ve found that the strange IR hues are to do with the settings it adopts upon startup. If the program begins in bright light, you get a lovely purple hue; in dark, a luminescent green. Interesting!