posts tagged with the keyword ‘linux’

2016.01.31

Slideshow

I’ve been using Raspberry Pi single-board computers for video players for years now, and I’ve also used them as audio players, but I was missing a good way to use them as slide show devices… Until now.

I’ve used Screenly OSE for the MMPIS at Milwaukee Makerspace, and while Screenly is great for what it is (a network-connected, browser-controllable, digital signage device) sometimes you don’t want all the options and features and you don’t have a network. So I needed another solution.

I found fbi, “the Linux framebuffer imageviewer”, which can run at boot up and display a folder full of images at full screen with a configurable delay between changing images. Perfect!

Boot Volume

Now, there’s one more thing… If I’m going to put this somewhere that doesn’t have a network connection (like, in a museum) I want to be able to easily update the slides. The slides won’t be changing daily, but may be changing every month or so. For something like this it’s easy to store the images directly on the /boot volume, which is accessible on the SD card when you pop it in a Mac OS X or Windows computer.

You’ll notice a folder names “slides” and a file named “slideshow.sh”, which do the hard work here. It’s actually ridiculous to call it “hard work” because it’s dead simple. The slides folder contains images which will be displayed in alphabetical order. (Sadly, my screen shot does not reflect this!) In an ideal world you’d name your images 0001.jpg, 0002.png, 0003.jpg, etc. Just name them in order, and they’ll display in order. Easy.

Images

The SD card only has about 40MB of free space for you to put images on, but with JPG compression of photos, you can probably fit plenty of them. OK, so once you’ve got your folder full of images (which you can easily update on the SD card) you’ll need some way to run the slideshow.sh script.

Typically I do a sudo nano /etc/rc.local and add what’s needed to run my script. In this case it’s the /bin/bash /boot/slideshow.sh & you see on line 20. Oh, don’t forget to set the Pi to auto-login at boot. Since it’s been added to recent versions of Raspbian you don’t even have to muck around anymore.

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
fi

/bin/bash /boot/slideshow.sh &

exit 0

So yeah, we’re all set… but you probably want to see the code in slideshow.sh, right? This is it. Right here. Yes, it’s pretty much just two lines. Linux is like that sometimes… It’s not hard implementing something, it’s just hard finding out exactly how to implement something. It can be hard finding those two lines that you need! (The 20 may need adjustment. Longer may be better, but in my testing on a Raspberry Pi 2 Model B it worked well.)

#!/bin/sh

sleep 20

fbi -a -t 6 --blend 200 --readahead --noverbose -T 1 /boot/slides/* >/dev/null 2>&1

There’s some parameters you can set, like -t 6 which sets each slide to display for 6 seconds, and the blend thing, which sort of works. Hey, it’s a slide show, okay!?

I’ll probably work on this more, but I was pleased to find a solution so I thought it was worth sharing.

2016.01.25

Video Installation

Last summer Ray Chi got in touch with me about an installation he was doing for the Milwaukee Art Museum. He wanted a video screen that could be activated to play a video by touching a metal plate. Well, actually six videos and six video screens and six metal plates.

I told him I’d figure out how to get it all to work the way he wanted. I came up with a few ideas, one of which was using Processing, which I did get working, but at the time Processing wasn’t really running on the Raspberry Pi, at least not officially (or very well) and since the Pi was what we ended up choosing, I needed another solution.

For an installation that’s going to be running for years, simplicity and reliability are key. I had used Pis in the past many times for video players using omxplayer. Typically I’d just launch omxplayer on boot and have it play a video, looping, forever. For this application we wanted the video to play only when the metal plate was touched by a human hand (and then stop playing when someone stopped touching it) which meant capacitive touch.

Rather than spend a lot of time coming up with something that might work, I went with something that I was 98% sure would work. I used Adafruit’s Standalone Momentary Capacitive Touch Sensor Breakout attached to a Teensy LC. Why a Teensy LC? Because it’s a low-cost (LC!) Arduino-compatible microcontroller and it can emulate a keyboard.

Yes, a keyboard! If you have a USB keyboard connected to a Raspberry Pi computer while omxplayer is playing a video, you can just hit the space bar to play the video, and then hit it again to pause the video. Those are the two things we needed to do.

Video Player Controls

So, Raspberry Pi, running omxplayer to play the video, with a Teensy LC attached programmed to work as a USB keyboard, and triggered by a capacitive touch sensor, which was then connected to the metal plate. Simple!

There was this issue of……. timing.

So in theory, the Teensy would just need to send a space character to play the video, and it would do this when you touched the metal plate. But! (And it’s a Big But) the issue was that we wanted the video to start playing at boot and then pause at the beginning and sit there waiting… for someone to touch the metal to start the video playing. Rather than fire up the video via the typical Linux methods, we ended up just starting up the Pis, auto-logging in, and having them wait at the command line… yes, just sit their waiting, doing nothing… Sort of.

When the Pi booted up, it provided power to the Teensy, which then started running its sketch. The sketch would start at boot, wait 45 seconds to ensure the Pi was booted up and sitting there waiting at the command line, and then it would type:

/bin/bash /boot/video.sh

So we actually used the Teensy to send the text to the Pi (just as if a human typed it) which then fired up the script and started the video playing. The sketch would then wait 2.4 seconds and type a space character, which would pause the video. This set the state of things exactly where we wanted them. The video way paused, just waiting for the next command from the Teensy, which was… space, of course!

Now, there’s the concept of “rising edge” and “falling edge” when it comes to pressing buttons. A rising edge is the transition from low to high, and a falling edge is the transition from high to low. That’s a fancy way of saying we can tell when the button is being pressed, and when it’s being released. It’s best to use debouncing for this, and there’s a library for that.

Video Players Mounted

So with everything mounted in place we still had to deal with one issue. The HDMI displays worked find as long as they were turned on before the Raspberry Pi computers. If they were turned on at the same time the resolution wouldn’t set right, and the video would be letter-boxed. There were two options, one would be using two different power strips to get power to everything, with instructions for museum staff to follow a specific order. This wasn’t ideal, so we went with option two. I used a time delay relay so that one single power strip could be turned on, which would turn on the HDMI displays, and then a few seconds later turn on the computers. It worked. (And yes, I found out later I probably could have fixed the issue in software. Duly noted.)

Are there things we could have done better? Yes. Did we get the project done on time, and within (or under) budget? Yes. Was it fun and challenging? Yes and Yes. You may read this and think “Hey, you totally could have solved problem X by doing Y!” and you’d probably be right. I’ve found a number of things I’d do slightly differently if I were to do something like this again. That’s all part of experience, and learning, and sharing… right?

Video Player

When the installation was all done and tested, I got photos of everything, and then set to work on documenting it all. I delivered a 14 page manual on the construction and operation of the video players, along with the code and instructions on how to use one of the backup SD cards that was prepared in case of failure.

Besides, now I can (sort of) say that my work is in the Milwaukee Art Museum. ;)

2016.01.04

*nix

Hey there… Dan Gillmor moved to Linux and it’s even better than he expected!

As for me, I’ve been using Mac OS X pretty much since it came out, and before that I used System 9, 8, 7, etc… Operating systems created by Apple. I’ve also used FreeBSD in the past (though mainly on servers) and I’ve been using Linux in some form or another for close to 20 years. Along the way I’ve also used Windows, though always for work, never for fun.

I’m going to call out a few things Dan mentions, just so I can comment on them.

…here I am, writing this piece on a laptop computer running the Linux* operating system and LibreOffice Writer, not on a Mac or Windows machine using Microsoft Word. All is well.

Luckily you can use LibreOffice on Mac OS X, Windows, and Linux. You can also use OpenOffice on Mac OS X, Windows, and Linux. And hey, you can also run NeoOffice on Mac OS X (sorry Windows and Linux users) which is what I did years ago before OpenOffice ran on Mac OS X.

This brings up a point I’d like to expand on, that even if you run Mac OS X (or Windows) you can almost always lean towards the open alternative that is available. This might mean LibreOffice instead of Microsoft Office, and it may mean Thunderbird instead of Mail.app, or Firefox instead of Safari.

Other software I use includes jEdit, Arduino, Processing, Fritzing, Inkscape, Audacity, OpenSCAD, and yes… those are all available for Mac OS X, Windows, and Linux. You might also notice that (almost) all of the websites listed end with .org, which is telling.

The applications you use all depend on what you do with a computer, and what you use a computer for. I tend to use computers to make things, and luckily the specific things I like to make fit in well with the software I use.

Some of the applications listed above rely on Java. I’ve always had a love/hate relationship with Java, but it does help a lot of software run on multiple platforms. One of the applications listed relies on an X11, or more specifically, XQuartz. X11.app used to be distributed by Apple, but they abandoned it, but that’s okay because XQuartz exists.

One application I use that is not available for Linux is Evernote. I should say “not officially available”, since there is Nevernote and Geeknote. Yeah, often you can find an unofficial client for Linux that might work.

Of course if your work demands you use specific software, you may not be able to exclusively run Linux. Oh well…

Now…

No one should ever have to open a command-line window and type “sudo apt-get update” or other such instructions.

I tend to cringe when I see things a computer user should never have to do. I mean, if you want to do X, you may have to learn Y, right? Now, personally, great power comes from being able to open a command line window and type commands. It’s not always the easiest thing to do, though sometimes it is the easier thing to do, if you have the knowledge. If you don’t want to open a command line window and type things, chances are good you won’t have to. (But you should anyway, if you really want to harness the power of your computer. As long as it’s running *nix, I mean. Sorry, Windows users!)

And then…

It’s almost certainly too late for Linux to be a hugely popular desktop/laptop operating system, at least in the developed world.

Maybe, I don’t know… I have seen Linux change over the last two decades, and I’m still excited about what I see.

Dan did say “desktop/laptop operating system”, but let’s look elsewhere. Linux is used on servers, and appliances, and things. What do I mean by “things”? Well, every Raspberry Pi project runs Linux. Here’s 400+ projects running Linux. Here’s a few more projects and some tutorials, all using Linux. I even use Linux computers at work (building exhibits) that just play sounds. Using Linux on a Raspberry Pi makes sense for this, and lots of other things.

Anyway, Dan’s post is good (though it’s strange it’s posted on Medium instead of his own web site, because, freedom and all that) and I’d urge anyone who is not familiar with Linux to take a look at it. It’s pretty awesome. So is open source, and freedom, and the command line.

2015.09.01

Linux

Occasionally I post things here because I may need them in the future… this is probably one of those things, which is setting a Raspberry Pi to auto-magically login to the shell (not the desktop) on boot.

Install and configure Raspbian as you normally would, setting it to boot up to the command line, not the desktop.

Boot the Pi and login as the user pi, and then run the following command:

sudo nano /etc/inittab

Find the following line:

1:2345:respawn:/sbin/getty --noclear 38400 tty1

and comment it out by adding a # to the front:

#1:2345:respawn:/sbin/getty --noclear 38400 tty1

Just under it, add this line:

1:2345:respawn:/bin/login -f pi tty1 </dev/tty1 >/dev/tty1 2>&1

Save the file, quit nano, and reboot.

Obviously this can pose a security risk, just like any other auto-login procedure. If you’re using a Raspberry Pi that is not connected to the network, and doesn’t have a keyboard attached, and is secured in a case, there’s a bit less of a concern.

(Most of this info is from the post Auto Login and Auto Start in Raspberry Pi. Thanks!)

2013.09.06

CameraPi

If you wondered why I needed a Raspberry Pi case that could also hold a Raspberry Pi Camera… well, seriously, don’t you people know me by now!? :)

This ‘CameraPi’ is a prototype for Time Lapse Bot 4, and if you’re not familiar with my time lapse hardware experiments, check out the Time Lapse Bot project page for a good introduction.

My Time Lapse Bots have always relied on old computers, and while you can typically get old computers pretty cheap, they are also, well… old. They run old software, they often have hardware failures, non-working batteries, are heavy, and a lot of other things that are (sometimes) fine, but sometimes annoying.

Enter the Raspberry Pi, a small, inexpensive, low-power, modern Linux computer that can use an add-on camera module to create an all-in-one solution to time lapse captures. This is the kind of stuff I love playing with!

So here’s the story of making the CameraPi. I’ll avoid getting into code at this post and just talk about the process and some applications.

At raspberrypi.org I grabbed the NOOBS install, mainly because I wanted to test it out, and it worked well! I went with Rasbian. I think it had all the camera software baked in, but if not, it’s easy to add.

AppleTalk

Once up and running, I added Avahi to give the Raspberry Pi a nice network name (camerapi.local) and I also installed Netatalk to allow my Mac OS X machines to easily connect to it. Neither of these are required for the camera stuff, but I tend to drop these on most Linux machines I use.

As for the image capture, while the camera utilities have some time lapse capabilities, they did not work for me, which is fine, I created my own. (I should note that the Raspberry Pi is for educational use, so I try to follow that idea and, well, learn a lot while using it.)

I wrote a simple bash script to capture a new image every 60 seconds. You can set whatever interval you like, but I like 60 seconds. For one day that gives you 1440 images, if you’re keeping track at home. Depending on your image size and compression settings that could be over 1GB per day of still images. I’m currently using 1280×720 for my image size, as that works well when compiling video.

Photo

As long as we’re capturing images every minute, why not have a way to display them remotely via a web browser? Sure! I also installed Apache for that. There are lighter HTTP servers, but I like Apache. I wrote a simple CGI script to grab the latest image file and display it on a page… and there’s also a link to all the images for the day. Oh, and the page auto-refreshes so it keeps showing the latest image. (The images are named like so: 20130905140427 using the YYYYMMDDHHMMSS format.)

Files

OK, so we now have this running archive of photos. At some point (like, the second day) you’re going to have way more images in that folder than you want. Another shell script is the answer! Script #2 runs after midnight, grabs the date of the previous day, and moves all images matching that date to their own folder. (Oh, where do we store all these images? On a tiny USB thumb drive. It’s an 8GB drive. We figured filling that was better than filling the SD Card that contains the system.)

Files

Now we’ve got a folder named 20130905 with 1440 images in it. We should probably do something with it… Make a video! Once the files are moved we run a command with mencoder to compile all the JPG files (sorted by name, which is also sorted by date) into an AVI file. I don’t really care for AVI files though, so when that is done (and, it takes about 6 hours due to the high-quality encoding settings I use) we then use avconv (which used to be ffmpeg, sort of, oh, Linux!) to convert the AVI to an MP4 file. That does not take hours. This is all messy and could be done better.

Video

So after all that, we now have an MP4 file we can view in our browser, though it’s a silly MP4 that needs to completely load before it starts. Silly! There must be a better way.

Yes. There must be a better way. I’m sure there is. Here’s the thing. I really just started hacking. I didn’t know where I was going, so it’s all been guessing and trying things along the way. That’s the beauty of it. I’m not building this for a client. I’m not building a commercial product. I’m just playing and learning. I love it.

Oh, I forgot, I also set my capture script to launch at startup as a service. That means it also stops cleanly when you halt the system. Also, you can halt the system via another CGI just by loading a web page. Secure? Probably not. Ideally I’d like to be able to have the Pi create a WiFi network I can attach to from my phone and control. That would be nice. I’m sure it’s doable, I just need to dig in more. Dig. In. More.

Well that was fun! Thanks for reading this. If anyone really wants more info on the code, I could clean it up a bit (or not) and post it. As always, improvements are very welcome.

Update: Here’s an example video.

« Older Entries |


buy the button:

Buy The Button