I was compiling some templated C++ on a Raspberry Pi when the compilation failed with this error:
cc1plus: out of memory allocating 66574076 bytes after a total of 98316160 bytes
The Raspberry Pi had 1GB of RAM. From the error it looked like the compiler needed more memory than that.
It turns out that Raspbian does not use a swap partition. Instead it uses a
/var/swap file on the SD card. This is called dphys-swapfile. The default size of this swapfile is 100MB. As can be seen from the error above, this swap space was not enough.
Since I had more than 1GB of free space still available on my SD card, I decided to increase this swapfile. To do that, open the file
/etc/dphys-swapfile and increase the number of MB set in the line
Restart the swapfile using the command:
$ /etc/init.d/dphys-swapfile restart
Or alternately you could restart Raspbian.
Tried with: Raspbian 9 and Raspberry Pi B+ Rev3
If you are running Raspbian on the Raspberry Pi board, you can print out its model:
$ cat /proc/device-tree/model
Raspberry Pi Model B Rev 1
As you can see, I am using the first generation B model.
Tried with: Raspbian 7
Raspbian 9 (Stretch) is the latest version of Debian for the Raspberry Pi.
Here is how I installed it:
- Download the Raspbian Stretch Lite installation file from here.
We need a tool to write the OS image to a SD card. I used Etcher which can be installed from here.
Insert a SD card of at least 4GB capacity into your computer. Use Etcher and install the zip file to the SD card.
Eject the SD card. Remove it and plug it back into your computer. Create an empty file named ssh in the root directory of the SD card. This will enable you to SSH to your Raspberry Pi.
Insert this SD card into the Raspberry Pi board. Connect your Pi to your home wireless router with a Ethernet cable. You can also connect your Pi to your TV or computer display with a HDMI cable. Power on the Pi.
You can see Raspbian booting up on your TV or display. At the end it displays what IP address was assigned to it by DHCP. You can also figure out the IP address from the admin console of your wireless router. Let us say the IP address is 192.168.0.10.
SSH to the IP address of your Pi. The login is pi and the password is raspberry.
$ ssh email@example.com
$ sudo apt update
$ sudo apt upgrade
Your Raspbian 9 is all set now for your use.
Fret not that your friends can cast Youtube videos from their Android device to their TV using Chromecast! You can cast anything from your Android device to your TV if you have a Raspberry Pi connected to it using the awesome Raspicast app!
- Setup your Pi: You will need a Raspberry Pi with Raspbian installed on it. It is connected to your TV using a HDMI cable. You can SSH to your Pi. Optionally, you have OMXPlayer installed on your Pi and checked that you can play video files using it.
- Install app: Install the Raspicast app from here.
- Configure: Provide the IP address of your Pi, its port (usually 22), login (usually pi) and password.
- Cast away: Play any video in Youtube app on your Android device. Click the Share option and choose Cast (Raspicast). Raspicast opens, wait for a second and you will see it playing on your TV. If you want to keep adding Youtube videos to a queue then choose Queue (Raspicast) while sharing. You can view the queue in the Raspicast app.
- Use the Files section of the app to browse and play video files that are on your Pi. The UI for this is pretty basic. You are probably better off using OMX Remote for this.
- Use the Cast section of the app to browse and play video files that are on your Android device itself.
Tried with: Raspicast 1.3.6
Video files that are on partitions accessible by Raspbian can be played using OMXPlayer. However, it is quite a hassle to SSH into your Raspberry Pi and play a movie using OMX Player from the shell. The ideal solution would be to browse the video files from the comfort of your Android device and play it from there. And that is exactly what OMX Remote does!
- HDMI: Connect your Pi to your TV using a HDMI cable.
- SSH: Make sure you can SSH into your Raspberry Pi from a computer on your home network.
- OMXPlayer: After SSH into the Pi, make sure you can play videos from the shell using OMXPlayer as described here.
- Install OMX Remote: It can be installed from the Play Store here.
- Configure OMX Remote: Provide the hostname (or IP address of your Pi), port (usually 22), username (usually pi) and password. I also like to set the root directory of my media.
- Play using remote: Browse the video files from the app and click on a video file to play it on your TV. Various remote control UIs of varying complexity are available by swiping left and right. Some of the useful buttons on the remote control is to switch audio channels (speaker with arrow buttons) and to switch subtitles (speech bubble with arrow buttons).
Tried with: OMX Remote 1.9
The Raspberry Pi is a great device for video playback using its HDMI output. It is popularly used as a HTPC by installing a full-blown media player solution like OSMC (formerly RaspBMC) or OpenELEC. What if you do not want such a heavy-handed solution, but just need the ability to play a video file now and then?
OMXPlayer is a command-line video player written specifically for the capabilities of the Raspberry Pi. It is filled with features and can output to the HDMI of the Pi.
- SSH into your Raspbian and install it:
$ sudo apt-get install omxplayer
- Make sure your HDMI is forced to turn on at boot, as described here.
Shutdown your Pi and your TV. Connect the Pi to the TV using a HDMI cable. Power on the TV first and choose the HDMI input. Next, power on the Pi.
SSH to the Pi and play the video file you want using OMXPlayer:
$ omxplayer foo.mkv
- For the keyboard shortcuts to control the player:
$ omxplayer --help
- Though command-line is great for setting up and debugging, if you need to play videos frequently, then consider using the OMX Remote on your Android device. You can browse the files on your Pi and play any of them effortlessly using OMXPlayer using this app. I highly recommend it!
Tried with: OMXPlayer 0.3.6, OMX Remote 1.9 and Raspbian 7
Copy provides 15GB of free space online in a Dropbox like two-way sync and cloud storage. The reason I tried it was that it has clients for almost all systems, including Linux, Android and even Raspberry Pi!
- Download the Linux client from here. It worked with both Ubuntu and Raspberry Pi.
Unzip the contents to a suitable directory. The client binary will be run from this location on every restart of your system, so choose the location well.
Both commandline and GUI clients are available. I used the GUI client on my desktop Ubuntu and commandline client on my Raspberry Pi.
- On Ubuntu I used the
x86_64 build of the client. I like that the GUI client works just like Dropbox: stays in system tray and has similar UI. You just need to run it the first time:
$ ./x86_64/CopyAgent &
- The GUI will prompt you for login, password and sync directory the first time. From the next time it runs automatically. It even adds itself to the Startup Applications list and will start with Linux from the next reboot.
- On Raspberry Pi, I use the
armv6h build of the client. I call the client by specifying the sync directory to use, the login, the password and also request it to run in the background as daemon:
$ ./armv6h/CopyConsole -root=/my/sync/dir -firstname.lastname@example.org -password=hushhush -daemonize
- That is it! Add, delete and modify the files in your sync directory and see them sync them across multiple computers!
Tried with: Copy 1.48.0456, Ubuntu 14.04 and Raspbian 7
Raspberry Pi can be setup as a media server to simultaneously stream videos, music and pictures to multiple devices on the home wireless network. ReadyMedia (formerly known as MiniDLNA) is a simple media server that can be used to achieve this.
- Install Raspbian to the Pi, as described here.
Connect and mount the hard disk containing the content to the USB port of the Pi. Let us assume the partition with the content is mounted at
SSH into the Pi and install the ReadyMedia server:
$ sudo apt-get install minidlna
Open the file
/etc/minidlna.conf and edit the following entries.
Set the video, music and pictures directories. For example:
- If you want ReadyMedia to automatically index new media files as they are added to your media directories:
- Restart the ReadyMedia server. This will index media files in your media directories and build the media database of the server:
$ sudo service minidlna force-reload
Open a browser on any other device on the network and open
192.168.0.99 is the IP address of the Pi.
8200 is the default port of the ReadyMedia server. The webpage should show the number of content files in the server database.
You are now ready to enjoy your content on any device on the network! On Android smartphone or tablet, I like to use MediaHouse UPnP/DLNA Browser. Once open, it shows my Pi and I can browse video, audio and image content.
Videos can be played using any video player on your Android device. I like to use MX Player for this. Audio is played by the browser itself.
Tried with: ReadyMedia 1.0.24 and Raspbian 7
Raspbian is based on Debian, so the distribution version information for both is stored in the same file:
Here is what I got on my Raspbian 9 (Stretch):
$ cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 9 (stretch)"
Raspbian is a Debian distribution for the Raspberry Pi. Installing it to the Pi is easy:
- Download the latest Raspbian disk image from here. Unzip the
.img file from the downloaded zip file.
Insert a SD card of at least 4GB capacity into your computer. Write the downloaded disk image to it, as described here.
Insert this SD card into the Pi board. Connect your Pi and your home wireless router with a Ethernet cable. Power on the Pi.
Go to the Admin webpage of your wireless router and figure out what IP address has been assigned to your Pi. Let us assume it is assigned
SSH into your Pi using the command
ssh email@example.com. The default password is
sudo raspi-config and choose to
Expand filesystem. This expands Raspbian to make full use of the space on your SD card. Exit the config tool and choose to reboot when it requests so.
Once your Pi restarts back and is connected to the home network, SSH into it again. Update the packages to the latest versions:
$ sudo apt-get update
$ sudo apt-get upgrade
- If you want Raspbian to auto-mount USB storage devices (thumbdrives and harddisks) and NTFS partitions, then install these tools:
$ sudo apt-get install usbmount
$ sudo apt-get install ntfs-3g
You now have a Raspbian system that is ready to roar! 🙂
Tried with: Raspbian 7