Tag Archives: Linux

Amazon Alexa functionality on Raspberry Pi

Alexa (wiki) is Amazon’s cloud-based voice service available on number of devices. It provides a natural voice experiences for interaction, playing music and other options. There are devices, produced by Amazon, as well, as supported by other vendors.

There is an Alexa Skill Kit to create custom products, based on the Amazon Alexa services. It is also available API and SDKs to integrate Alexa into own connected products.

This article walks through one of such option – to build own device, connected to Amazon Alexa, using Raspberry Pi single board PC.

Different projects

Following options require an powered speaker and a USB microphone. It is recommended to use Raspberry Pi3, however Raspberry Pi2 should work as well.

  • An option on Python github.com/devicehive/AlexaDevice – “the project allows to launch Alexa on any Linux devices, even on embedded devices like Raspberry Pi (with usb headset)”. A guideline to set it up.
  • An option on Python github.com/alexa-pi/AlexaPi “a client for Amazon’s Alexa service. It is intended and tested to run on a wide range of platforms, such as Raspberry Pi, Orange Pi, CHIP and ordinary Linux or Windows desktops“. A guideline to set it up.
  • An option github.com/alexa/alexa-avs-sample-app/wiki/Raspberry-Pi – the project provides step-by-step instructions for setting up Alexa Voice Service (AVS) on a Raspberry Pi and using wake word engines from Sensory or KITT.AI”. Discontinued – authors has put their project “into maintenance mode. To leverage the latest Alexa features, please use the AVS Device SDK C++ Sample App
  • An option, used in this article – github.com/alexa/avs-device-sdk , mentioned earlier as “AVS Device SDK C++ Sample App”.

AVS Device SDK C++ Sample App

Prepare Raspberry Pi

sudo apt-get update
sudo apt install xfce4 xfce4-goodies tightvncserver
In case errors, related locale
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
 LANGUAGE = (unset),
 LC_ALL = (unset),
 LC_CTYPE = "UTF-8",
 LANG = "en_GB.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to a fallback locale ("en_GB.UTF-8").

Fix locale

sudo locale-gen "en_US.UTF-8"
sudo dpkg-reconfigure locales

Resize the CF card

Run a command resize2fs as shown below. “/dev/sda2” is a volume name of the CF card, which can be found with a command lsblk

resize2fs -p /dev/sda2

Another option (only in GUI mode) is to use a graphics tool for disk, volumes and partition management: GParted

sudo apt-get install gparted
sudo gparted

Follow the guideline Raspberry Pi Quick Start Guide with Script – step-by-step instructions to set up the Alexa Voice Service (AVS) Device SDK on a Raspberry Pi.

Issues within a step, when starting startsample.sh


ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition 'defaults.bluealsa.device'
#       Client not connected!       #
Failed to initialize SampleApplication
Failed to create to SampleApplication!

Solutions from Alsa lib conf issue #105

1. Not connected USB microphone

  • Check out this guideline of follow the next brief instruction
  • Check available recording devices
arecord -l

If the respond is as following – there is no recording devices available

**** List of CAPTURE Hardware Devices ****
  • Connect a USB microphone or a USB headset to the Raspberry Pi and check again. Example of a connected UCS headset
**** List of CAPTURE Hardware Devices ****
card 1: LX3000 [Microsoft LifeChat LX-3000], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

Set the USB audio device as default


  • Try to record audio and play it back – the command records audio from the default recording device to the specified file during 10 seconds
arecord -d 10 test-mic.wav
  • It might be an error related to not supported format
Recording WAVE 'test-mic.wav' : Unsigned 8 bit, Rate 8000 Hz, Mono
arecord: set_params:1299: Sample format non available
Available formats:
- S16_LE
  • Specifying the format will lett make record – example
arecord -f S16_LE -d 10 test-mic.wav

However this may lead to the other issues. So follow the further steps to change the ~/.asoundrc

  • Check available asound cards
    cat /proc/asound/cards


    Check which one is selected as current for playback and for capture. In this example: “ALSA” is a card #0, it is used for playback, “USB-Audio – Microsoft LifeChat LX-3000” is a card #1, it is used for capture. So the file ~/.asoundrc should be like following

pcm.!default {
  type asym
   playback.pcm {
     type plug
     slave.pcm "hw:0,0"
   capture.pcm {
     type plug
     slave.pcm "hw:1,0"
  • If file has been created – check it, replaying it with the command
aplay test-mic.wav
  • Note: changes of the default (or current) audio in the GUI will change this file ~/.asoundrc

2. Not licensed Sensory engine

Is the Sensory library you are using licensed? If not, there is a script in the Sensory project you downloaded from Github under bin/license.sh that you can use to license to the project. You may not may not have to re-link the Sensory library.


If everything has been setup well – there will be following information and a option’s info displayed (i+Enter – shows this option’s info).


Press “q” (end “Enter”) to quit the sample.

There are some advises in the troubleshooting guide. One of them – to test the issue “No audio output from the SDK“. To do the testing – install GStreamer

sudo apt-get install libgstreamer1.0-0 gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-libav gstreamer1.0-doc gstreamer1.0-tools


Useful resources:

Setup C++ IDE CLion on Raspberry Pi with Ubuntu Mate

CLion is a crossplatform IDE for C++ made by JetBrains. CLion is not free but it is really helpful – with all its intentions, hints and refactorings. CLion has 30 days free trial license. Find out more on video introductions.

Eclipse is a free alternative but with less automation, assistance and features (this article describes the installation of Eclipse on Ubuntu).

Known issues on Raspberry Pi with Ubuntu Mate

  • Debugging does not work – because of not supported GDB version
  • On basic “Hello world” example there are issues with running the code – one of native terminal libraries fails. Compiled executable works fine. More complex example also works.

Continue reading

Program remotely on Raspberry Pi

Major advantage of such tiny computers as Raspberry Pi (RPi) is ability to work on small autonomous platforms like mobile robots. However computer, moving with a robot, is a challenge as well – during development it is not easy to change the code. Remote connection to the computer via SSH or VNC, using Wi-Fi, might help in such cases.

Continue reading

Setup OctoPrint on Raspberry Pi 2 with Ubuntu

OctoPrint is a server controlling a 3D-printer over web-interface, running on the small computer like Raspberry Pi or PCDuino with Linux OS. This article describes how to setup OctoPrint on Raspberry Pi 2 with Ubuntu OS. Read another article to setup OctoPrint on PCDuino.

Raspberry-Pi-2-with-connectors  OctoPrint-intro

Raspberry Pi 2 has ARMv7-based CPU on-board – this allows to run Ubuntu directly on this small computer. Ubuntu has plenty of features in compare to special editions of Linux distributives for such small devices and therefore less limitations with installing specific programs and components on it.

Continue reading

Setup 3D printer server OctoPrint on PCDuino

OctoPrint is a server controlling a 3D-printer over web-interface, running on the small computer like Raspberry Pi or PCDuino with Linux OS. If such computer has WiFi or connected to WiFi router within local network (e.g. personal WiFi router at home), the 3D-printer can be controlled and monitored remotely – on PC, tablet or smartphone.


Continue reading

Install Robotics Operating System (ROS) on Ubuntu

Robot Operating System (ROS) is a set of libraries and tools for software developers to create robot applications. ROS can be installed on different platforms – Linux, Windows, OS X, and a number of others. ROS is licensed under an open source, BSD license.

This article describes how ROS can be installed on one of Linux distributions Ubuntu – for those who are not familiar with Linux. Continue reading

Ubuntu and Linux – hints for beginners

Install/uninstall software

UbuntuSoftware Center Ubuntu Software Center

  1. Click on the icon “Ubuntu Software Center” UbuntuSoftware Center
  2. Type name (or its part) of software product in the search field
  3. Select the program in the list and click on “Install” button

UbuntuSoftware CenterFileCommander

4. If the software is installed – click on “Uninstall” button to uninstall it

Navigation within folders and files

UbuntuTerminal Terminal

  1. Run the Terminal – click on the icon “Terminal” UbuntuTerminal or hit the key combination Ctrl+Alt+T
  2. Prompt with the cursor has following format:
  3. Command cd folder-name changes the current folder to specified as folder-name in the parameter
  4. Command ls folder-name displays the content of the folder specified as folder-name in the parameter. The command ls without parameters – displays the content of the current folder
Predefined folder names

. – “single dot” refers to a current folder ( ./ “single dot followed by slash” is the same).
.. – “double dot” refers to a parent folder ( ../ “double dot followed by slash” is the same).
/ – “slash” refers to a root folder of the system.
~ – “tilda” refers to a “home” folder of the logged user – with subfolders “Documents”, “Downloads”, “Pictures”, etc. ( ~/ – “tilda followed by slash” is the same).

UbuntuFileExplorer File explorer

  1. Click on the icon  to open file manager window UbuntuFileExplorer
  2. Item “Home” on the left panel of the file manager window refers to a “home” folder of the logged user
  3. The way to easy change of a size of a window – keep the key Alt and the middle mouse button pressed when the mouse cursor is near the border or a corner of a window and move the mouse cursor.

UbuntuMidnightCommander Midnight Commander

Well known text terminal based file manager


Many operations available in two clicks from menus

LinuxMidnightCommanderPanelMenu LinuxMidnightCommanderCommandsMenu LinuxMidnightCommanderFileMenu

Ctrl+O – hide/show panels

F3 – view selected file withing embedded viewer

F4 – edit selected file with one of system editors – first editing operation suggests to select the editor (which can be changed later)


“mceditor” has highlight of syntax


Change the default editor by command “update-alternatives”

sudo update-alternatives –config editor


UbuntuGNOME Commander GNOME Commander

GUI based file manager with useful features

UbuntuGNOME Commander

For view/edit files it uses “gedit” text editor

ArduinoIDEIcon Installation of Arduino IDE

Install “Arduino IDE” from “Ubuntu Software Center“. This version can be not latest and mai not have support needed boards and new features.

From site arduino.cc download latest Arduino IDE  for Linux 32 bit or 64 bit – check the system version.

Extract downloaded file to a directory “Downloads”.

Replace installed Arduino IDE with downloaded latest version:

1. Run the Terminal (hit Ctrl+Alt+T)2. Remove the installed Arduino IDE – type or copy/paste the following command to the Terminal (a user password can me required)

sudo rm -r /usr/share/arduino

3. Copy downloaded and extracted latest Arduino IDE on the place of removed version

sudo cp -r ~/Downloads/arduino* /usr/share/arduino

4. Connect Arduino IDE to the computer by USB

5. Click on the icon ArduinoIDEIcon to start the Arduino IDE

6. Select an Arduino board model in a menu “Tools”/”Board”


7. Select a serial port on which the Arduino board is connected in menu “Tools”/”Serial Port”


8. Load an example from menu “File”/”Examples”/”Basics”/”Blink”


9. Click on an icon “Upload” ArduinoIDEIconUpload to try uploading a sketch to the board

During first time of  working with Arduino IDE it might be required to log-off/log-on or restart the computer to add permissions on using a port.

UbuntuSystemSettingsIconDetails Find Ubuntu version and if system is 32 bit or 64 bit

Click on the icon UbuntuSystem in the top right corner of a desktop and select “System Settings” from drop-down menu to show a dialog “System Settings”


In the dialog click on the icon “Details” UbuntuSystemSettingsIconDetails to show a dialog “Details”. This dialog contains a version of Ubuntu (12.04 in the screenshot below) and a version of the system (32 bits in the screenshot)


Ubuntu-performance-monitor-icon Performance Monitoring

Terminal based performance monitors

  • Installed by default “top” – just run this command in the terminal

Ubuntu performance monitor: top

  • “htop” – more advanced performance monitor. Install it

sudo apt-get install htop

run with command “htop”

Ubuntu performance monitor - htop



sudo apt-cache search your-program

show all devices

show devices
$ls -la /dev/sd*

try mount X-3rd letter in device (e.g. “a” in /dev/sda1)
mnt – mounted device name
sudo mount /dev/sdX1 /mnt
sudo mount -t vfat /dev/sdX1 /mnt
sudo mount -t ntfs /dev/sdX1 /mnt
sudo mount -t msdos /dev/sdX1 /mnt

Start gui lubuntu https://wiki.ubuntu.com/LightDM
sudo lightdm

sudo vim /etc/lxdm/default.conf


sudo apt-get install lxsession-edit

sudo vim /etc/lightdm/lightdm.conf.d/20-lubuntu.conf

[SeatDefaults] autologin-user=USERNAME


Disable auto-load of lightdm
echo “manual” | sudo tee -a /etc/init/lightdm.override
systemctl disable lightdm

delete directory (folder) and all its subdirectories including file
rm -rf folder-name

change timezone
sudo unlink /etc/localtime
sudo ln -s /usr/share/zoneinfo/Etc/GMT+6 /etc/localtime

Cannot login GUI
Ctrl + Alt + F1 to get to terminal
sudo passwd > to change password
sudo apt-get install –reinstall xorg
If still can’t login – try following
cd /home/<user> ( cd ~ will get you to the same place, instead of type the name of your directory)
sudo mv .Xauthority .XauthorityBak (renaming this file)

alter way
$ ls -l ~/.Xauthority
-rw——- 1 root root 61 Sep 16 15:43 .Xauthority
$ chown group:user ~/.Xauthority
where ‘group’ and ‘user’ are the group and the user that you use to login. in this example
$ chown akonsu:akonsu ~/.Xauthority

wget – download files from internet
sudo apt-get install wget
-b, –background     Go to background immediately after startup. If no output file is specified via the -o, output is redirected to wget-log.
-e command; –execute command  Execute command as if it were a part of the file .wgetrc. A command thus invoked will be executed after the commands in .wgetrc, thus taking precedence over them.
-o logfile logging
-a logfile append to a log
-c continue download
–progress=type where type: dot or bar
–spider check is file exists
–http-user=user, –http-passwd=password
–post-data=string, –post-file=file E.g.: wget –save-cookies cookies.txt –post-
data ‘user=user-name&password=user-password’ http://server-name/page-name
-O file-name alter downloaded file name


Raspberry Pi
sudo apt-get install linux-firmware

sudo apt-get install openssh-server
sudo apt-get install lubuntu-desktop


Editor vim

Navigation: arrows or keys “hjkl”
k    ->     up
h   l    -> left  right
j    ->    down

0    -> move to first column in a line
^    -> move to a first non-space character of the line
$    -> move to a last letter of a line
^u    -> move page up
^d    -> move page down
b    -> move to a word left
w    -> move to a word right
#    -> move to the prev occurence of current word
*    -> move to the next occurence of current word

Esc or ^[    -> switch to normal mode
i        -> switch to insert mode (starts before the current letter)
a        -> switch to append mode (starts after the current letter)

:e filename    -> edit to file with name “filename” (:e! -> reload current file)
:w filename    -> write to file with name “filename”
😡        -> save and exit
:q        -> exit if there is no changes
:q!        -> exit without save
:u        -> undo last command
:^R -> redo last “undone” command
:%command    -> range of the “command” is a document – not only line. Eg. :%s/ab/xz/g
:123<CR>         -> move to the line number 123
:!shell-command -> run any shell command

Ctrl+Z                  -> temporary switch to the shell; enter “fg” to return back to vim


y    -> copy char (yw->copy word, y3w, etc.)
yw    -> copy word
yy    -> copy line
x    -> cut char
dd    -> delete (cut) line
dw    -> delee (cut) word (d3w -> cuts 3 words)
de    -> delete (cut) til next of the word
p    -> paste
cw    -> change word
ctZ    -> change till “Z”

ma    -> puts mark “a”


V – selects entire lines
v – selects range of text
^v – selects columns
gv – reselect block


:/sometext    -> search “sometext” down the document
:?sometext    -> search “sometext” up of the document
:*        -> repeate last search
N        -> prev searched occurence
n        -> next searched occurence


:s/foo/bar/g -> Find each occurrence of ‘foo’ (in the current line only), and replace it with ‘bar’.
:%s/foo/bar/g -> Find each occurrence of ‘foo’ (in all lines), and replace it with ‘bar’.
:%s/foo/bar/gc -> Change each ‘foo’ to ‘bar’, but ask for confirmation first.
:%s/\<foo\>/bar/gc -> Change only whole words exactly matching ‘foo’ to ‘bar’; ask for confirmation.
:%s/foo/bar/gci -> Change each ‘foo’ (case insensitive due to the i flag) to ‘bar’; ask for confirmation.
:%s/foo/bar/gcI -> Change each ‘foo’ (case sensitive due to the I flag) to ‘bar’; ask for confirmation.

., *, \, [, ^, and $ are metacharacters.
+, ?, |, &, {, (, and ) must be escaped to use their special function.
\/ is / (use backslash + forward slash to search for forward slash)
\t is tab, \s is whitespace
\n is newline, \r is CR

Multiple files
vim file1 file2 file3


Multiple windows
:new – opens new file in new window
:split – opens same file with new window
:split file2 – opens file2 in new window
:split +command file2 – e.g :split +/text-to-search file2
:4 split – splits window with leaving 4 lines of current window

^W-W – to top window
^W-k – to window above
^W-j – to window below
^W-w – to bottom window
^W-c or zz or :q – close the window


Explorer mode

d – creates a new directory
% – creates and opens a new file
D – deletes a directory or file
R – renames a file
o – opens the file in a horizontal split
v – opens the file in a vertical split

let g:netrw_liststyle=3 – in ~/.vimrc sets tree-style

let mapleader=” ”
map <leader>k :E<CR> – in ~/.vimrc maps space-k to :E

Custom color scheme

  • Choose one of color schemes on vimcolors.com
  • Create the folder ~/.vim/colors if not exists

mkdir ~/.vim/colors

  • Install the util wget if it is not installed

sudo apt-get install wget

  • Download the RAW file of selected scheme from GitHub

wget https://github.com/wimstefan/Lightning/raw/master/colors/lightning.vim -O ~/.vim/colors/lightning.vim

  • put following lines to the file ~/.vimrc (e.g.: vim ~/.vimrc)

set t_Co=256
set background=light
colorscheme lightning

IDE, plugins: http://vim.wikia.com/wiki/Use_Vim_like_an_IDE

* pathogen http://www.vim.org/scripts/script.php?script_id=2332
plugin manager
cd ~
mkdir -p ~/.vim/autoload ~/.vim/bundle

sudo apt-get install curl
curl -LSso ~/.vim/autoload/pathogen.vim https://tpo.pe/pathogen.vim

git config –global core.excludesfile ‘~/.cvsignore’
echo tags >> ~/.cvsignore

* Vundle: https://github.com/gmarik/Vundle.vim#about
plugin manager
git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vim

* nerdtree: http://www.vim.org/scripts/script.php?script_id=1658
file-system tree. Explorer mode can be used instead (see above)
cd ~/.vim/bundle
git clone https://github.com/scrooloose/nerdtree.git
:NERDTree    -> invoke in vim
autocmd vimenter * NERDTree >> ~/.vimrc
# adds  to ~/.vimrc for autostart with vim
* minibufexpl: http://www.vim.org/scripts/script.php?script_id=159
cd ~/.vim/bundle
git clone https://github.com/fholgado/minibufexpl.vim

* C++ code completion (requires to build vim from sources) YouCompleteMe
sudo apt-get install build-essential cmake

* C++ code completion OmniCppComplete

cd ~/.vim

wget http://www.vim.org/scripts/download_script.php?src_id=7722 -O omnicppcomplete.zip

unzip omnicppcomplete.zip
rm omnicppcomplete.zip

Add following lines to the file ~/.vimrc

set nocp
filetype plugin on
" configure tags - add additional tags here or comment out not-used ones
set tags+=~/.vim/tags/cpp
set tags+=~/.vim/tags/gl
set tags+=~/.vim/tags/sdl
set tags+=~/.vim/tags/qt4
" build tags of your own project with Ctrl-F12
map  :!ctags -R --sort=yes --c++-kinds=+p --fields=+iaS --extra=+q .
" OmniCppComplete
let OmniCpp_NamespaceSearch = 1
let OmniCpp_GlobalScopeSearch = 1
let OmniCpp_ShowAccess = 1
let OmniCpp_ShowPrototypeInAbbr = 1 " show function parameters
let OmniCpp_MayCompleteDot = 1 " autocomplete after .
let OmniCpp_MayCompleteArrow = 1 " autocomplete after ->
let OmniCpp_MayCompleteScope = 1 " autocomplete after ::
let OmniCpp_DefaultNamespaces = ["std", "_GLIBCXX_STD"]
" automatically open and close the popup menu / preview window
au CursorMovedI,InsertLeave * if pumvisible() == 0|silent! pclose|endif
set completeopt=menuone,menu,longest,preview

Install ctags if not exists

sudo apt-get install exuberant-ctags

Add a tag for C++

mkdir ~/.vim/tags
cd ~/.vim/tags
ctags -R --sort=1 --c++-kinds=+p --fields=+iaS --extra=+q --language-force=C++ -f cpp

Specify the help for tags in vim running the command

:helptags $HOME/.vim/doc

^X/^O – open completion window
^N and ^P – navigate withing completion lines
^12 – mapped (in .vimrc) to prepare completion for own project

Create tag for a library (add the command in the file ~/.vimrc)
ctags -R –sort=yes –c++-kinds=+p –fields=+iaS –extra=+q –language-force=C++ -f some-library-tag /usr/include/some-library-name

E.g. create a tag for QT4
ctags -R –sort=yes –c++-kinds=+p –fields=+iaS –extra=+q –language-force=C++ -f qt4 /usr/include/qt4/




uncompress filename.tar.Z

unzip filename.zip

gunzip filename.tar.gz
tar -xvzf filenam.tar.gz

tar xvf filename.tar

tar zxvf filename.tgz

zcat filename.tar.Z  | tar xvf - 
gzcat filename.tar.gz | tar xvf -

bzip2 -d filename.bz2
bzip2 -dk filename.bz2
tar cvjf filename.tar.bz *.txt