Rpi Config
Installing OS on MicroSD Card
- Download image from raspberrypi.org downloads page.
- Insert a (4GB+) SD Card using card reader into computer.
- Use gparted to format the entire disk as FAT32 (FAT16 will not work!).
- Open ImageWriter(GUI) & select the image file (example 2012-10-28-wheezy-raspbian.img).
- 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:
- Install Raspian(as explained above).
- Insert SD Card, LAN Cable/WIFI Adapter, Power cable, HDMI/RCA cable for video.
- Keyboard & Mouse are helpful, but optional.
- Use NMAP or Wifi DHCP IP List to find out IP assigned to PI.
- Connect using pi:raspberry credentials.
- Run sudo raspi-config
- Choose Boot into desktop mode option.
- Reboot
- Update the distro:
sudo apt-get update sudo apt-get upgrade
Install VNC Server
This method will create a new virtual desktop. If you want to access the first desktop itself(:0), refer below X11 method. |
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
This section is under construction. |
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
# 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:
- Get the list of what’s supported by your monitor:
tvservice -d edid edidparser edid
- Similar to following output will appear(along with several other lines):
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
- Edit the config file:
sudo nano /boot/config.txt
- Find the section about HDMI, uncomment it and set the right group and mode.
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
- 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
#wifi blacklist brcmfmac blacklist brcmutil #bt blacklist btbcm blacklist hci_uart
FFMPEG
Source: jeffreythompson.org
- INSTALL H264 SUPPORT
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 FFMPEG
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
Rpi Zero W
Headless Installation
- Burn fresh MicroSD Card
- Eject SD card, and reinsert to mount:
df cd /media/{your-username}/boot touch ssh
- Now create a wpa_supplicant.conf file for WiFi Config:
cd /media/{your-username}/boot nano wpa_supplicant.conf
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 }
- Boot up the Pi.
- Use a terminal to connect to it over ssh:
ssh [email protected]
Password is:
raspberry
Installing Python 3.6 using BerryConda
Sources: berryconda, stackexchange.com
- Download binary installer for armv6l installers (Raspberry Pi 1 or Zero)
wget https://github.com/jjhelmus/berryconda/releases/download/v2.0.0/Berryconda3-2.0.0-Linux-armv6l.sh
- Installation
chmod +x Berryconda3-2.0.0-Linux-armv6l.sh ./Berryconda3-2.0.0-Linux-armv6l.sh
- Verify installation
conda list which python3 pip --version
- Autorun Script using berryconda python
nano /home/pi/script.py #!/home/pi/berryconda3/bin/python3 <script body>
chmod +x script.py
nano /etc/rc.local /home/pi/script.py &
This section needs verification or testing! |
- Add Rpi channels for existing Conda installation
conda config --add channels rpi conda install python=3.6
Desktop environment
Installation
sudo apt install lightdm sudo apt install lxsession sudo raspi-config # Choose Desktop autologin option
Troubleshooting
cat .xsession-errors
VNC
- Run below command:
sudo raspi-config
- Enable VNC server
- Go to the options on the VNC Server on Raspberry Pi.
- Change the security authentication to "VNC Password" instead of "Unix Password"
Sense Hat
- Install Software:
sudo apt update sudo apt install sense-hat sudo reboot
- Copy the examples to home dir:
cp /usr/src/sense-hat/examples ~/ -a
- The C/C++ examples can be compiled by running make:
cd sense-hat/snake/ make ./snake
- Running pygame_joystick.py Game:
sudo apt install python-pygame DISPLAY=0:0; sudo ./pygame_joystick.py
- Checking the Sensors:
cd RTIMULib/RTIMULibDrive11/ make ./RTIMULibDrive11
SenseHat API
- Display Text:
from sense_hat import SenseHat
sense = SenseHat()
sense.show_message("Hello world!")
sense.show_message("One small step for Pi!", text_colour=[255, 0, 0], back_colour=[50,50,50], scroll_speed=0.1)
# rotation
sense.set_rotation(180)
# alternatives
sense.rotation = 180
- Question mark:
X = [255, 0, 0] # Red
O = [255, 255, 255] # White
question_mark = [
O, O, O, X, X, O, O, O,
O, O, X, O, O, X, O, O,
O, O, O, O, O, X, O, O,
O, O, O, O, X, O, O, O,
O, O, O, X, O, O, O, O,
O, O, O, X, O, O, O, O,
O, O, O, O, O, O, O, O,
O, O, O, X, O, O, O, O
]
sense.set_pixels(question_mark)
- Misc:
Text Color & Background Color
sense.show_letter('A', text_colour=[0,255,0], back_colour=[50,50,50])
sense.scroll_speed()
SenseHat Shutdown Button
Source: github.com
#!/usr/bin/python3
# Sense Hat Off Button Program
# Press the middle button twice to shutdown
# Press three times to end the program.
from sense_hat import SenseHat
from time import sleep
import os
s = SenseHat()
last_time = -1
second_last_time = -1
last_direction = ""
second_last_direction = ""
time_passed = 99
s.rotation = 270
low_light = True
# Bootup indicator
s.show_letter('U', text_colour=[0,255,0])
sleep(3)
s.clear()
def shutdown():
third = False
s.stick.get_events()
sleep(1)
recent_events = s.stick.get_events()
if len(recent_events) > 0:
for x in recent_events:
if x[1] == 'middle' and x[2] == 'pressed':
third = True
if third == True:
s.show_letter("X", text_colour=[0,0,255])
sleep(2)
s.clear()
quit()
else:
s.show_letter("S", text_colour=[255,0,0])
sleep(2)
s.clear()
os.system("sudo shutdown -h now")
while(True):
event = s.stick.wait_for_event(emptybuffer=True)
if (event.action == "released" or event.direction != "middle"):
continue
second_last_time = last_time
second_last_direction = last_direction
last_time = event.timestamp
last_direction = event.direction
if second_last_time == -1:
time_passed = 99
else:
time_passed = last_time - second_last_time
#print("time passed: {}\n direction: {}".format(time_passed,event.direction))
if time_passed < .3:
shutdown()
Misc
- Sound does not work with an HDMI monitor
Add the following line to the configuration file /boot/config.txt:
hdmi_drive=2
- Using OMX Player to play audio files through CLI:
omxplayer example.mp3 1
- By default output will be automatic (hdmi if hdmi supports audio, otherwise analogue).
You can force it with:
sudo amixer cset numid=3 <n> where n is 0=auto, 1=headphones, 2=hdmi.
- To find hardware info type:
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 free space in the filesystem/SD Card:
df -h df / -h
- Other Commands:
lsusb free
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
- Select url for the correct mode in RaspberryPi Builds section
http://openelec.tv/get-openelec
- SSH into OpenElec by using following credentials:
root:openelec
- Download the new release tar file at following location:
cd /storage/.update/ wget http://releases.openelec.tv/OpenELEC-RPi.arm-5.0.8.tar
- Reboot to install the update.
Accessing Raspberry Pi using Hostname
- Install avahi:
sudo apt-get install avahi-daemon sudo insserv avahi-daemon
- Create a configfile for Avahi at /etc/avahi/services/multiple.service:
sudo nano /etc/avahi/services/multiple.service
<?xml version="1.0" standalone='no'?> <!DOCTYPE service-group SYSTEM "avahi-service.dtd"> <service-group> <name replace-wildcards="yes">%h</name> <service> <type>_device-info._tcp</type> <port>0</port> <txt-record>model=RackMac</txt-record> </service> <service> <type>_ssh._tcp</type> <port>22</port> </service> </service-group>
- Apply the new configuration with:
sudo /etc/init.d/avahi-daemon restart
- Access Pi from other machines:
ssh [email protected]
- If you get "Name or service not known" error:
sudo nano /etc/nsswitch.conf
Edit this file & update to use below order
hosts: files resolve [!UNAVAIL=return] mdns4_minimal [NOTFOUND=return] dns
SD Card Backup
- Windows
- Download [Win32 Disk Imager]
- Insert SD card into PC & select the correct drive in Win32 Disk Imager.
- Click the folder icon beside it and select path to save your image.
- Linux
- Boor Raspberry Pi & run following command:
sudo apt-get clean
- Shutdown, Insert SD card into reader & Unmount the partitions.
- Install dcfldd
sudo apt-get install dcfldd
- Start Backup:
sudo dcfldd bs=4M if=/dev/sdb hash=sha1 hashlog=/data/sdcard.img.sha1sum | gzip -9 - > sdcard.img.gz && sudo sync
- Watch the progress:
watch ls -lh *img.gz
- Restoring
- Check the image:
diff -sq sdcard.img.sha1sum hash.log
- Restore image:
gunzip -c sdcard.img.gz | sudo dcfldd bs=4M of=/dev/mmcblk0 hash=sha1 hashlog=./hash.log && sudo sync
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:
- Find out the partitions:
df -hT
- For all partitions run the following:
sudo fsck /dev/mmcblk0p5
- Run the following command for the partitions with errors from above command:
sudo fsck -rV /dev/mmcblk0p5
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.
- RCA Audio-Video cable [Link]
3.5MM to Composite Audio / Video Cable 3.5mm Stereo to 3 RCA AV Cable
- Model B+ RCA Cable requirements
Video Ground Right Left Sleeve Ring 2 Ring 1 Tip 4 3 2 1
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
Foe Ext4:
UUID=XXXX-XXXX /media/aman32 ext4 defaults 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:
#!/bin/sh #/etc/init.d/gurbani sleep 10 omxplayer http://192.69.212.61:8020/stream -o local --vol -500
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 );
VCGenCmd
- Shows a list of possible commands:
vcgencmd commands
- Board Temperature:
cat /sys/class/thermal/thermal_zone0/temp /opt/vc/vcgencmd measure_temp OR vcgencmd measure_temp
- CPU & GPU Memory allocation:
vcgencmd get_mem arm vcgencmd get_mem gpu
- Check Codec Status:
vcgencmd codec_enabled MPG2 for codec in H264 MPG2 WVC1 MPG4 MJPG WMV9; do echo -e "$codec:\t$(vcgencmd codec_enabled $codec)"; done
- Rpi Config
vcgencmd get_config int
IPv6 Disable
Edit below file:
sudo nano /boot/cmdline.txt ipv6.disable=1
Change MAC address
Edit below file:
sudo nano /etc/rc.local sudo ifconfig wlan0 hw ether b8:27:eb:4f:14:24
Shrink Rpi Image
Source: github.com
Installation:
wget https://raw.githubusercontent.com/Drewsif/PiShrink/master/pishrink.sh chmod +x pishrink.sh sudo mv pishrink.sh /usr/local/bin
Shrink:
sudo pishrink.sh pi.img
Upgrade Raspbian to Raspberry Pi OS
Source: makeuseof.com
Update Raspbian:
sudo apt update sudo apt dist-upgrade -y
Run the firmware update:
sudo rpi-update
Edit the sources.list file:
sudo nano /etc/apt/sources.list
Change “buster” to “bullseye” from:
deb http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi
To:
deb http://raspbian.raspberrypi.org/raspbian/ bullseye main contrib non-free rpi
Run the update and upgrade commands:
sudo apt update sudo apt install gcc-8-base sudo apt dist-upgrade
Use the autoclean instruction to discard unused update files, then reboot:
sudo apt autoclean sudo reboot
{{#widget:DISQUS |id=networkm |uniqid=Rpi Config |url=https://aman.awiki.org/wiki/Rpi_Config }}