Free up SD card space on Raspberry Pi


Raspberry Pi uses SD card for its main storage and you may run out of the free space as your project goes on. Here are some tips to free up your SD card space.

 

1. Uninstall unnecessary packages
Wolfram Engine: I’ve never used but it seems that Wolfram Engine is for mathematical/physics programming. If you don’t have any plans to use, you can get about 700 MB of free space by uninstalling it.

libreoffice: LibreOffice is a free and open source office suite that can be run on multiple OSes such as Linux, Windows, Mac, etc, which is very nice. However, I don’t think many people use LibreOffice on Raspberry Pi… If you remove this pre-installed office suite, you can get approx. 250 MB of free space.

scratch: Scratch is a free educational programming language. If you don’t need it, you can remove it and get approx. 90 MB space.

After you decide what packages to remove, you can remove it like below:

sudo apt-get purge wolfram-engine libreoffice* scratch -y

 

2. Clean up of apt cache
When installing and updating packages, cache date is kept and it’s getting bigger and bigger. To clear the cache, run the following command.

sudo apt-get clean

 

3. Remove unused dependencies
This command removes packages that are no longer used/required.

sudo apt-get autoremove -y

 

arecord creates hundreds of files

Update (Sep. 7th, 2017):
If you are using Raspbian Stretch, the pre-installed version is now v1.1.3 and this issue doesn’t occur any more!

Update (Dec. 9th, 2018):
If you are looking for steps to update ALSA on Raspbian Strech, please see this post.

 

If you find hundreds of files like below after the recording is done by arecord command, you may need to update your alsa-utils. According to here, this problem is introduced in alsa-utils 1.0.28, which is preinstalled in Raspbian Jessie, and can be fixed by either downgrading or upgrading alsa-utils version.

pi@raspberrypi:~/tmp $ ls -l
total 360
-rw-r--r-- 1 pi pi 319798 Jun 11 02:12 test-01.wav
-rw-r--r-- 1 pi pi     44 Jun 11 02:12 test-02.wav
-rw-r--r-- 1 pi pi     44 Jun 11 02:12 test-03.wav
-rw-r--r-- 1 pi pi     44 Jun 11 02:12 test-04.wav
-rw-r--r-- 1 pi pi     44 Jun 11 02:12 test-05.wav
...

 

Steps
Here are the steps to get the latest alsa-utils (1.1.4 as of 6/10/2017) from source.

1. Download and extract the source code.

wget ftp://ftp.alsa-project.org/pub/utils/alsa-utils-1.1.4.tar.bz2
tar xvjf alsa-utils-1.1.4.tar.bz2
cd alsa-utils-1.1.4/

2. Install the dependencies.

sudo apt-get install libasound2-dev libncursesw5-dev -y

3. Configure, make and install.

./configure --disable-alsaconf --disable-bat --disable-xmlto --with-curses=ncursesw
make && sudo make install

4. Check the version:

arecord --version

If everything is fine, the result should be this:

pi@raspberrypi:~/installation/alsa-utils-1.1.4 $ arecord --version
arecord: version 1.1.4 by Jaroslav Kysela <perex@perex.cz>

5. Check if the problem is fixed.

$ arecord -D hw:1,0 -d 10 -f S16_LE -r 16000 test.wav
Recording WAVE 'test.wav' : Signed 16 bit Little Endian, Rate 16000 Hz, Mono
$ ls -l
total 316
-rw-r--r-- 1 pi pi 320044 Jun 11 04:23 test.wav

 

Reference
– Multiple files created by arecord
http://stackoverflow.com/questions/24629915/multiple-files-created-by-arecord

 

Voice Recording on Raspberry Pi

 

The purpose of this post is to record audio (e.g. voice) on Raspberry Pi with a microphone. Raspberry Pi doesn’t have mic input by default, so USB microphone or USB soundcard + 3.5 mm jack mic is required.

 

Example Setup

 

Steps
1. Setting Up
1-1. Connect the speakers into 3.5 mm audio jack.
1-2. Connect the USB mic into USB ports.
1-3. Boot up Raspberry Pi Board. If it’s not set up yet, please refer this post.
1-4. Make sure the speaker is working. The command below can be used for speaker output test. To end the test, press Ctrl-C.

speaker-test -t wav

1-5. Check if the mic is recognized as a recording device by this command:

arecord -l

If everything is fine, the result should be something like below.

**** List of CAPTURE Hardware Devices ****
card 1: Device [USB PnP Sound Device], device 0: USB Audio [USB Audio]
 Subdevices: 1/1
 Subdevice #0: subdevice #0

This means the USB mic is on “card 1”, “device 0”. This card number and device number will be used when you record.

 

2. Recording
2-1. Now you can start recording by “arecord” command, for example:

arecord -D hw:1,0 -d 5 -f cd test.wav -c 1

-D option specifies recording device. Since the mic is on “card 1”, “device 0” (see step 1-4), the value is “hw:1,0” here. This command creates “test.wav” as a 5-second, CD-quality wave file. Since it’s a mono mic, specify “1” as the number of channels with “-c” option. You can find the details of the options here.

Note:
If you find hundreds of files (test-01.wav, test-02.wav…) after the recording is done, please refer this troubleshooting.

Note:
I found that a hissing noise is introduced when the file is played through 3.5 mm audio jack on Raspberry Pi board, even though the recording quality itself is ok. So you may want to use HDMI sound output or a USB sound card to play the audio file.

 

3. Testing

3-1. Play the recorded file and make sure the recording is done properly.

aplay test.wav

*If the playback volume is too low (or high), you can check and change it with “amixer” command.

Check the current volume.

amixer

Below is an output example. In this case, the current vol is 77%.

$ amixer 
Simple mixer control 'PCM',0
  Capabilities: pvolume pvolume-joined pswitch pswitch-joined
  Playback channels: Mono
  Limits: Playback -10239 - 400
  Mono: Playback -2000 [77%] [-20.00dB] [on]

Set the vol to 100%.

amixer set PCM 100%

 

Reference
– USB Audio Cards with a Raspberry Pi
https://cdn-learn.adafruit.com/downloads/pdf/usb-audio-cards-with-a-raspberry-pi.pdf

 

 

HFP on Raspberry Pi


Update (Sep 7, 2017):
If you are using Raspbian Stretch, please refer here instead of steps below. This post below is for Raspbian Jessie.


The purpose of this post is to enable Bluetooth Handsfree Profile (HFP) on Raspberry Pi so that Raspberry Pi can act like as a handsfree speaker phone or a handsfree car kit. There is one thing needs to be mentioned before start. The original plan was to use Raspberry Pi3’s on-board Bluetooth chip for this project. Unfortunately, it didn’t work. It seems that the problem is related with the chip. So, we have to use a Bluetooth dongle instead.

Here is the list of contents of this post.

Contents:
– Hardware Prerequisites
– Software Prerequisites
– Steps
1. Setting Up
2. oFono
3. PulseAudio
4. Connect your Phone
5. Make a Call!
– Conclusion
– Reference

Let’s get started.

 

Hardware Prerequisites
Since Raspberry Pi doesn’t have microphone input by default, it need to be added. In this post, I’ll use a USB sound card with a 3.5 mm jack microphone.

Also, as mentioned above, we’ll use a Bluetooth dongle instead of on-board Bluetooth chip.

Raspberry Pi 3 B+
– Bluetooth dongle (Panda Bluetooth 4.0 USB Adapter)
– USB Sound Card (SYBA USB sound adapter / FG-UAUDV1-C119)
Microphone with 3.5 mm audio jack
– Speakers with 3.5 mm audio jack (e.g. Rumfo Mini Speaker)

 

Software Prerequisites
Below are the required versions to enable Bluetooth HFP according to PulseAudio release note.

– Bluez 5.0 (or later)
– PulseAudio 6.0 (or later)
– oFono 1.13 (or later)

 

Steps
1. Setting Up
1-1. Connect Bluetooth dongle and USB sound card with Raspberry Pi.
1-2. Connect the microphone and speakers to 3.5 mm audio jacks on the USB sound card.
1-3. Boot up Raspberry Pi Board. If it’s not set up yet, please refer this post.
1-4. As described, we don’t use on-board Bluetooth chip. So it needs to be disabled. To do that, open “/etc/modprobe.d/raspi-blacklist.conf”.

sudo nano /etc/modprobe.d/raspi-blacklist.conf

1-5. Add lines below and save.

blacklist btbcm
blacklist hci_uart

1-6. Then reboot the board.

sudo reboot

1-7. After reboot, check dmesg and make sure there is no Bluetooth-related errors.

dmesg | grep -i bluetooth

1-8. Also, make sure hci0 is UP.

hciconfig

The result should be like this:

hci0:    Type: BR/EDR  Bus: USB
    BD Address: 00:1A:7D:DA:71:08  ACL MTU: 310:10  SCO MTU: 64:8
    UP RUNNING
    RX bytes:622 acl:0 sco:0 events:38 errors:0
    TX bytes:1437 acl:0 sco:0 commands:38 errors:0

If it’s DOWN for some reason, then turn it up.

sudo hciconfig hci0 up

2. oFono
2-1. oFono is not installed by default, so let’s install it.

sudo apt-get install ofono -y

2-2. Make sure the version is 1.13 or later.

pi@raspberrypi:~ $ ofonod --version
1.15

2-2. Then, start the service.

sudo systemctl start ofono

You can check the service running like below.

systemctl -a |grep ofono
  ofono.service     loaded    active   running   LSB: oFono Mobile Telephony Daemon

3. PulseAudio
Since the preinstalled PulseAudio is 5.0, it needs to be updated to at least 6.0.

pi@raspberrypi:~ $ pulseaudio --version
pulseaudio 5.0

3-1. Uninstall the current PulseAudio.

sudo apt-get purge pulseaudio -y

3-2. Open “/etc/apt/sources.list”.

sudo nano /etc/apt/sources.list

3-3. Add the line below:

deb http://ftp.debian.org/debian jessie-backports main

3-4. Execute commands below:

gpg --keyserver pgpkeys.mit.edu --recv-key 8B48AD6246925553
gpg --keyserver pgpkeys.mit.edu --recv-key 7638D0442B90D010
gpg -a --export 8B48AD6246925553 | sudo apt-key add --
gpg -a --export 7638D0442B90D010 | sudo apt-key add --

3-5. Update the package list.

sudo apt-get update

3-6. Install PulseAudio and its Bluetooth module:

sudo apt-get -t jessie-backports install pulseaudio pulseaudio-module-bluetooth -y

3-7. Check the version and make sure it’s 6.0 or later.

$ pulseaudio --version
pulseaudio 7.1

3-8. Open “/etc/pulse/default.pa”.

sudo nano /etc/pulse/default.pa

3-9. Add “headset=ofono” on the line of ‘module-bluetooth-discover’.

load-module module-bluetooth-discover headset=ofono

3-10. To enable echo canceling, add the lines below:

### Echo cancel and noise reduction
.ifexists module-echo-cancel.so
load-module module-echo-cancel aec_method=webrtc source_name=ec_out sink_name=ec_ref
set-default-source ec_out
set-default-sink ec_ref
.endif

3-11. Start PulseAudio.

pulseaudio --start

4. Connect your Phone
4-1. Launch bluetoothctl.

bluetoothctl

4-2. Then, input below commands.

power on
agent on
default-agent

4-3. Start searching your phone. Make sure your phone is discoverable.

scan on

4-4. After detecting your phone, turn scan off.

scan off

devices command shows a list of found devices.

[bluetooth]# devices
Device XX:XX:XX:XX:XX:XX Galaxy S7

4-5. Then, pair, trust and connect to your phone by specifying the Bluetooth device address (in this case it’s “XX:XX:XX:XX:XX:XX”, please replace it wity your device’s address).

pair XX:XX:XX:XX:XX:XX
trust XX:XX:XX:XX:XX:XX
connect XX:XX:XX:XX:XX:XX

If everything is ok, you should see “successful” at the end of the result for each command like below.

[bluetooth]# pair XX:XX:XX:XX:XX:XX
...
Pairing successful
[bluetooth]# trust XX:XX:XX:XX:XX:XX
...
trust succeeded
[bluetooth]# connect XX:XX:XX:XX:XX:XX
...
Connection successful

5. Make a Call!
To make a call, we’ll use oFono test scripts which is included in the source code.
5-1. First, download the source and extruct.

wget https://www.kernel.org/pub/linux/network/ofono/ofono-1.15.tar.gz
tar -xzvf ofono-1.15.tar.gz

5-2. Then, you can make a call by:

python ./test/dial-number 1234567890

If you want to end the call, then execute:

python ./test/hangup-active

 

Conclusion
Thanks for all the forums and articles I referred, now HFP is working on Raspberry Pi!
Next, I’m planning to apply echo canceling and ambient noise suppression, maybe equalizer.


Update (June 22, 2017):
Added one step (step 3-10) to enable echo cancellation. It seems that ‘module-echo-cancel’ does not only echo cancellation but ambient noise suppression. I haven’t check the noise suppression yet but I think the echo cancellation is working well based on my brief testing.


Update (May 2, 2018):
The steps to enable equalizer on HFP sending audio is newly posted.


 

Reference
– Connect Bluetooth Headset To Raspberry Pi 3 (A2DP & HSP)
http://youness.net/raspberry-pi/bluetooth-headset-raspberry-pi-3-ad2p-hsp

– PulseAudio 6.0 Release Notes –freedesktop.org
https://www.freedesktop.org/wiki/Software/PulseAudio/Notes/6.0/

– PulseAudio Documentation –freedesktop.org
https://freedesktop.org/wiki/Software/PulseAudio/Documentation/

– module-echo-cancel –freedesktop.org
https://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/User/Modules/#index45h3

– Pulseaudio echo cancellation — Debian User Forums
http://forums.debian.net/viewtopic.php?f=16&t=128306

 

Installing the Latest Qt Creator on Ubuntu Linux

This is a step-by-step procedure to install the latest official release of Qt Creator onto Ubuntu Linux PC. Qt Creator can be installed by “apt-get” command, however in that case you may not get the latest version. In this post we’ll use the online installer so that we can get the latest version.

For the reference, bellow are the latest version as of 6/2/2017.
– Qt Creator version : 4.3.0
– Ubuntu version : 16.04.02 (LTS)


Update (April 27, 2018):
My ubuntu got updated and I reinstalled Qt. The exact same steps still work. Now the versions are:
– Qt Creator 4.6.0
– Ubuntu 18.04 (LTS)


 

Prerequisites:
– 64-bit Ubuntu Installed PC
(I’m not sure why but I was not able to get the latest version when I was installing on 32-bit Ubuntu. So, in this post, I use 64-bit Ubuntu PC.)

 

Steps
1. Install required packages.

sudo apt-get update
sudo apt-get install build-essential libgl1-mesa-dev -y

2. Download the online installer.

wget http://download.qt.io/official_releases/online_installers/qt-unified-linux-x64-online.run

3. Add execute permission.

chmod a+x qt-unified-linux-x64-online.run

4. Run the installer.

./qt-unified-linux-x64-online.run

5. Follow the wizard and complete the installation.

6. Launch Qt Creator.

Qt Creator should automatically configure compilers, debuggers, etc for the PC environment. Now you can run examples from “Welcome” tab or create your a new project from “File” > “New File or Project…”!

 

References
Getting Started With Qt and Qt Creator on Linux
http://www.ics.com/blog/getting-started-qt-and-qt-creator-linux

Online installer of Qt Creator official releases
http://download.qt.io/official_releases/online_installers