Rpi Config

=Installing OS on MicroSD Card=


 * 1) Download image from raspberrypi.org downloads page.
 * 2) Insert a (4GB+) SD Card using card reader into computer.
 * 3) Use gparted to format the entire disk as FAT32 (FAT16 will not work!).
 * 4) Open ImageWriter(GUI) & select the image file (example 2012-10-28-wheezy-raspbian.img).
 * 5) Click the Write button (ignore the error for smaller image size & larger card space).

Dual boot with NOOBS

 * Use a format tool like Gparted to format the SD card as FAT32 (FAT16 will not work!)
 * Download Noobs Offline version
 * Dump the contents of the .ZIP file onto your SD card
 * Safely eject the card, place it in powered down Raspberry Pi’s SD card slot, and power the system up.
 * Once initialization is done, NOOBS wizard will appear.
 * Check Disk space portion of the wizard’s display.
 * After making selections, simply click the install button or press I on your keyboard:
 * Once the process is finished, you can boot right into your installed operating systems.
 * On each subsequent startup, a 10 second window will appear to select your OS before it boots into the last-used operating system.

=First Boot into Raspbian= Managing Raspberry Pi with/without Keyboard or Mouse: sudo apt-get update sudo apt-get upgrade
 * 1) Install Raspian(as explained above).
 * 2) Insert SD Card, LAN Cable/WIFI Adapter, Power cable, HDMI/RCA cable for video.
 * 3) Keyboard & Mouse are helpful, but optional.
 * 4) Use NMAP or Wifi DHCP IP List to find out IP assigned to PI.
 * 5) Connect using pi:raspberry credentials.
 * 6) Run sudo raspi-config
 * 7) Choose Boot into desktop mode option.
 * 8) Reboot
 * 9) Update the distro:

Install VNC Server
sudo apt-get install tightvncserver Now run the vncserver to finish the setup: vncserver

cd /home/pi cd .config mkdir autostart cd autostart nano tightvnc.desktop

paste following text:

[Desktop Entry] Type=Application Name=TightVNC Exec=vncserver :1 StartupNotify=false

X11 VNC
The above VNC access will create a new virtual desktop. If you want to access the first desktop itself(:0), use the following method:

sudo apt-get install x11vnc x11vnc -storepasswd

create autostart entry

cd .config mkdir autostart cd autostart nano x11vnc.desktop

paste following text:

[Desktop Entry] Encoding=UTF-8 Type=Application Name=X11VNC Comment= Exec=x11vnc -forever -usepw -display :0 -ultrafilexfer StartupNotify=false Terminal=false Hidden=false

save and reboot

XRDP
Source: raspberrypiblog.com

Change Root Password
sudo raspi-config

Adding new User
sudo adduser username sudo leafpad /etc/sudoers.

Leafpad will load the Sudoers file. Under the heading
 * 1) User Privilege specification

add the following text: username ALL=(ALL) ALL

TimeZone
By default, debian will come up in UTC. To make it reflect the time where you are -

sudo raspi-config select change_timezone

Verify NTP: ntpq -p

Hardcoding Display Resolution
Source: weblogs.asp.net

If your HDMI display is not switched on at pi bootup, the display resolution is set to a very low value.

You have to reboot the pi so that a correct resolution is selected at boot up.

You can resolve this issue by hard-coding the resolution as follow:

tvservice -d edid edidparser edid
 * Get the list of what’s supported by your monitor:

HDMI:EDID best score mode is now DMT (39) 1360x768p @ 60 Hz with pixel clock 85 MHz (score 5188004) HDMI:EDID preferred mode remained as DMT (39) 1360x768p @ 60 Hz with pixel clock 85 MHz
 * Similar to following output will appear(along with several other lines):

sudo nano /boot/config.txt
 * Edit the config file:

If your mode description contains “DMT” the group is 2 and if it is “CEA” group is 1: hdmi_force_hotplug=1 hdmi_group=2 hdmi_mode=39
 * Find the section about HDMI, uncomment it and set the right group and mode.


 * Save and Reboot Pi.

Changing Keyboard Layout
Edit the following file: sudo nano /etc/default/keyboard

Find where it says XKBLAYOUT=”gb”

Change the "gb" to "us" or the two letter code for your country.

Remove Clutter
Remove Wolfram(~400MB): sudo apt-get remove --purge wolfram-engine

Do the same for LibreOffice: sudo apt-get remove --purge libreoffice*

Remove Desktop packages: sudo apt-get remove --purge desktop-base lightdm lxappearance lxde-common lxde-icon-theme lxinput lxpanel lxpolkit lxrandr lxsession-edit lxshortcut lxtask lxterminal

Remove X packages: sudo apt-get remove --purge obconf openbox raspberrypi-artwork xarchiver xinit xserver-xorg xserver-xorg-video-fbdev x11-utils x11-common x11-session utils

Clean up extra packages no longer required: sudo apt-get autoremove –purge

= Raspberry Pi 3=

Disable WiFi & Bluetooth
Preferred Way: sudo nano /boot/config.txt

At the bottom of this file add: dtoverlay=pi3-disable-wifi dtoverlay=pi3-disable-bt

Alternative Way: sudo nano /etc/modprobe.d/raspi-blacklist.conf

blacklist brcmfmac blacklist brcmutil #bt blacklist btbcm blacklist hci_uart
 * 1) wifi

FFMPEG
Source: jeffreythompson.org

cd /usr/src git clone git://git.videolan.org/x264 cd x264 ./configure --host=arm-unknown-linux-gnueabi --enable-static --disable-opencl make -j4 sudo make -j4 install
 * INSTALL H264 SUPPORT

cd /usr/src git clone https://github.com/FFmpeg/FFmpeg.git cd ffmpeg sudo ./configure --arch=armel --target-os=linux --enable-gpl --enable-libx264 --enable-nonfree make -j4 sudo make -j4 install
 * INSTALL FFMPEG

= Rpi Zero W =

Headless Installation
df cd /media/{your-username}/boot touch ssh
 * Burn fresh MicroSD Card
 * Eject SD card, and reinsert to mount:

cd /media/{your-username}/boot nano wpa_supplicant.conf
 * Now create a wpa_supplicant.conf file for WiFi Config:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 country=IN

network={ ssid="myssid" scan_ssid=1 psk="mypass" key_mgmt=WPA-PSK }

ssh pi@raspberrypi.local
 * Boot up the Pi.
 * Use a terminal to connect to it over ssh:

Password is: raspberry

Installing Python 3.6 using BerryConda
Sources: berryconda, stackexchange.com

wget https://github.com/jjhelmus/berryconda/releases/download/v2.0.0/Berryconda3-2.0.0-Linux-armv6l.sh
 * Download binary installer for armv6l installers (Raspberry Pi 1 or Zero)

chmod +x Berryconda3-2.0.0-Linux-armv6l.sh ./Berryconda3-2.0.0-Linux-armv6l.sh
 * Installation

conda list which python3 pip --version
 * Verify installation

nano /home/pi/script.py
 * Autorun Script using berryconda python
 * 1) !/home/pi/berryconda3/bin/python3

chmod +x script.py

nano /etc/rc.local /home/pi/script.py &

conda config --add channels rpi conda install python=3.6
 * Add Rpi channels for existing Conda installation

= Misc =

Add the following line to the configuration file /boot/config.txt:
 * Sound does not work with an HDMI monitor

hdmi_drive=2

omxplayer example.mp3 1
 * Using OMX Player to play audio files through CLI:

You can force it with: sudo amixer cset numid=3  where n is 0=auto, 1=headphones, 2=hdmi.
 * By default output will be automatic (hdmi if hdmi supports audio, otherwise analogue).

cat /proc/cpuinfo      This will output information about the device’s processor. cat /proc/version      Shows you which version of the Pi you are using cat /proc/meminfo      Displays details about the Raspberry Pi’s memory cat /proc/partitions   Reveals the size and number of partitions on your SD card or HDD
 * To find hardware info type:

vcgencmd measure_temp
 * Board Temperature:

vcgencmd get_mem arm && vcgencmd get_mem gpu
 * CPU & GPU Memory allocation:

df -h df / -h
 * To find free space in the filesystem/SD Card:

lsusb ​free
 * Other Commands:

Update Raspberry Softwares
sudo apt-get update -y && sudo apt-get upgrade -y && sudo apt-get dist-upgrade -y && sudo rpi-update && sudo apt-get autoremove -y

Updating OpenElec Major Release

 * Manual process to upgrade Openelec to next Major Release.


 * Upgrading from Gotham(v13) to Kodi(v14) have to be done manually.


 * The AutoUpdate function within OpenELEC does not support this major version

http://openelec.tv/get-openelec
 * Select url for the correct mode in RaspberryPi Builds section

root:openelec
 * SSH into OpenElec by using following credentials:

cd /storage/.update/ wget http://releases.openelec.tv/OpenELEC-RPi.arm-5.0.8.tar
 * Download the new release tar file at following location:


 * Reboot to install the update.

Accessing Raspberry Pi using Hostname
sudo apt-get install avahi-daemon sudo insserv avahi-daemon
 * Install avahi:

sudo nano /etc/avahi/services/multiple.service
 * Create a configfile for Avahi at /etc/avahi/services/multiple.service:

 <!DOCTYPE service-group SYSTEM "avahi-service.dtd">  %h _device-info._tcp 0                model=RackMac _ssh._tcp 22 

sudo /etc/init.d/avahi-daemon restart
 * Apply the new configuration with:

ssh pi@raspberrypi.local
 * Access Pi from other machines:

sudo nano /etc/nsswitch.conf
 * If you get "Name or service not known" error:

Edit this file & update to use below order hosts:         files resolve [!UNAVAIL=return] mdns4_minimal [NOTFOUND=return] dns

SD Card Backup

 * Windows:
 * 1) Download [Win32 Disk Imager]
 * 2) Insert SD card into PC & select the correct drive in Win32 Disk Imager.
 * 3) Click the folder icon beside it and select path to save your image.


 * Linux:


 * 1) Boor Raspberry Pi & run following command: sudo apt-get clean
 * 2) Shutdown, Insert SD card into reader & Unmount the partitions.
 * 3) Install dcfldd sudo apt-get install dcfldd
 * 4) Start Backup: sudo dcfldd bs=4M if=/dev/sdb hash=sha1 hashlog=/data/sdcard.img.sha1sum | gzip -9 - > sdcard.img.gz && sudo sync
 * 5) Watch the progress: watch ls -lh *img.gz


 * Restoring

gunzip -c sdcard.img.gz | sudo dcfldd bs=4M of=/dev/mmcblk0 hash=sha1 hashlog=./hash.log && sudo sync
 * 1) Check the image: diff -sq sdcard.img.sha1sum hash.log
 * 2) Restore image:

Repair corrupt SD Card
If you get error after sudden power outage that the SD Card is corrupt but you are able to boot, the repair the SD card: df -hT
 * Find out the partitions:

sudo fsck /dev/mmcblk0p5
 * For all partitions run the following:

sudo fsck -rV /dev/mmcblk0p5
 * Run the following command for the partitions with errors from above command:

Initial Video Troubleshooting

 * On a PC its the BIOS that allows it to immediately generate a video signal, even with no OS installed or even no storage device (hard-disk or SSD) connected. PI Does not work like this. Without flawless access to SD-card it cannot pull any code to generate video. So the first order job is to provide it with an up-to-date correctly set up SD-card from which it can draw in more software, without that the PI won't generate any kind of video signal, leaving only the ACT LED as an indicator.


 * If the ACT LED doesn't blink in an irregular pattern for at least 20/30 seconds, it means the PI cannot read from the card, and NO booting takes place!


 * B+ it is now controlled by a "brownout detector" which will switch off the LED whenever the PI receives insufficient power, new software will now show a "rainbow square" in the GUI when a brownout event is detected. Brownouts are caused by an insufficient power supply and/or by a weak microUSB cable (to long with to thin wires), and can lead to SD-card corruptions and boot problems. The model B+ has a new "undervoltage detector" that turns off the POWER OK LED when the input voltage drops below 4.6 Volt, so you can be reasonably sure, with a model B+, that with a burning POWER OK LED your power is Okay.


 * The raspberry PI (its Raspbian OS) is designed to output a HDMI signal, but if it doesn't detect a HDMI device connected it will default to generating a composite signal on 4-pins 3.5mm A/V jack. Booting NOOBS works a bit differently, as it will always output a HDMI signal, unless you press one of the numerical keys 3 (PAL) or 4 (NTSC) to switch to a composite video output mode.

3.5MM to Composite Audio / Video Cable 3.5mm Stereo to 3 RCA AV Cable Video 	Ground 	Right 	Left Sleeve Ring 2  Ring 1  Tip 4 	3 	2 	1
 * RCA Audio-Video cable [Link]
 * Model B+ RCA Cable requirements:

Locale Error
If you are getting the following error: perl: warning: Please check that your locale settings:

Please add the following to the .bashrc file: export LC_ALL=C

Automount USB Drive
Create Mount Point: sudo mkdir /media/aman32/ sudo chown -R pi:pi /media/aman32/

For NTFS-3g or ExFAT: sudo apt-get install ntfs-3g -y sudo apt-get install exfat-utils -y

Get UUID & filesystem info: sudo ls -l /dev/disk/by-uuid/ sudo blkid

Edit FSTAB: sudo nano /etc/fstab

UUID=XXXX-XXXX /media/aman32 vfat   uid=pi,gid=pi   0   0

If any issues, replace uid,gid with defaults- for ext4 UUID=XXXX-XXXX   /media/aman32    ext4   defaults    0   0

For NTFS, not NTFS-3g: UUID=XXXX-XXXX   /media/aman32    ntfs   uid=pi,gid=pi    0   0 UUID=XXXX-XXXX   /media/aman32    ext4   uid=pi,gid=pi    0   0

Mount using Path: /dev/sda1   /media/aman32    ext4   defaults    0   0

Test FSTAB file: sudo mount -a

WiFi IP Address issue
Source: weworkweplay.com

You are unable to access your headless Raspberry Pi using WiFi if the hotspot is offline during startup or after restart of Access point later. This Script will restart the networking service enabling the connection.

sudo nano /usr/local/bin/checkwifi.sh

ping -c4 192.168.1.1 > /dev/null if [ $? != 0 ] then echo "$(date) - Restarting networking service" >> /var/log/mylogs sudo service networking restart sleep 60 fi

sudo chmod 775 /usr/local/bin/checkwifi.sh

* * * * * /usr/bin/sudo -H /usr/local/bin/checkwifi.sh >> /dev/null 2>&1

Gurbani Live Stream
Create a script file: sudo nano /etc/init.d/gurbani

Paste the following Script: sleep 10 omxplayer http://192.69.212.61:8020/stream -o local --vol -500
 * 1) !/bin/sh
 * 2) /etc/init.d/gurbani

Set the permissions: sudo chmod 755 /etc/init.d/gurbani sudo update-rc.d gurbani defaults

@reboot /etc/init.d/gurbani

Simple
while ! ping -c1 192.69.212.61 &>/dev/null; do sleep 5 ; done ; /usr/bin/omxplayer http://192.69.212.61:8020/stream -o local --vol -500

Mount HDD
Use a 5V 2A Micro USB Power Adapter sudo nano /boot/config.txt

Add this line to the bottom of the file, it replaces the old safe_mode_gpio=4 max_usb_current=1 sudo reboot

Now check to see if the hard drive is visible sudo blkid

Ping without sudo
Source: serverfault.com

chmod u+s $( which ping );

Reading Temperature
cat /sys/class/thermal/thermal_zone0/temp /opt/vc/vcgencmd measure_temp