Tag Archives: Ubuntu

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

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:
    user-name@computer-name:current-folder-name$
  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

UbuntuMidnightCommander

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)

LinuxMidnightCommanderSelectEditor

“mceditor” has highlight of syntax

LinuxMidnightCommanderEditor

Change the default editor by command “update-alternatives”

sudo update-alternatives –config editor

LinuxSelectEditor

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”

AcrduinoIDESelectBoard

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

AcrduinoIDESelectPort

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

ArduinoIDESelectExampleBlink

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”

UbuntuSystemSettingsMenuItem

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)

UbuntuDialogDetails

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

 

Other

sudo apt-cache search your-program

show all devices
lsblk

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
autologin=USERNAME

or

sudo apt-get install lxsession-edit

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

[SeatDefaults] autologin-user=USERNAME
autologin-user-timeout=0
user-session=Lubuntu
greeter-session=lightdm-gtk-greeter

 

Disable auto-load of lightdm
echo “manual” | sudo tee -a /etc/init/lightdm.override
or
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
or
tzselect

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)

Commands
: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

Editing

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”

Blocks
ma    -> puts mark “a”

Select

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

Search

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

Replace

: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

:next
:prev
:last

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

Buffers
:buffers

Explorer mode
:E

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
exit
* minibufexpl: http://www.vim.org/scripts/script.php?script_id=159
buffer-viewer
cd ~/.vim/bundle
git clone https://github.com/fholgado/minibufexpl.vim

* C++ code completion (requires to build vim from sources) YouCompleteMe
https://github.com/Valloric/YouCompleteMe/wiki/Building-Vim-from-source
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/

 

Archives

Unpack

uncompress filename.tar.Z

unzip filename.zip

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

tar xvf filename.tar

tar zxvf filename.tgz

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

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