Difference between revisions of "Raspberry Pi"

From RHS Wiki
Jump to navigation Jump to search
Tag: visualeditor
 
(31 intermediate revisions by the same user not shown)
Line 1: Line 1:
== Installing Raspbian ==
+
==Enable ssh on first boot==
1. Download Raspbian image from [http://www.raspberrypi.org/downloads/ here].<br />
+
On the boot partition create a file called ssh
2. Format SD card using FAT32.<br />
+
<br />
<nowiki>sudo mkdosfs -F 32 -v /dev/mmcblk0</nowiki>
+
==Installing Raspbian==
3. Install squashed file sistem on SD card.
+
 
<nowiki>sudo dd bs=4M if="/home/linux/2013-02-09-wheezy-raspbian.img" of=/dev/mmcblk0</nowiki>
+
#Download Raspbian image from [http://www.raspberrypi.org/downloads/ here].<br />
 +
#Format SD card using FAT32.<br />
 +
#:<pre>sudo mkdosfs -F 32 -v /dev/mmcblk0</pre>
 +
#umount /dev/mmcblk0
 +
#Install squashed file sistem on SD card.
 +
#:<pre>sudo dd bs=4M if="/home/linux/2013-02-09-wheezy-raspbian.img" of=/dev/mmcblk0
 +
#::
 +
#:: # Or directly from zipped image:
 +
#:: unzip -p 2017-04-10-raspbian-jessie.zip | sudo dd of=/dev/sdX bs=4096
 +
#::
 +
#:: # With progress indicator:
 +
#:: dd bs=4M if=2017-04-10-raspbian-jessie.img of=/dev/sdX status=progress
 +
#:: To see progres bar:
 +
#:: dd bs=4M if=/media/rafa/GIT/iso/2016-03-18-raspbian-jessie.zip | pv | dd of=/dev/mmcblk0</pre>
 +
 
 
[https://cmanios.wordpress.com/2013/03/10/install-raspbian-wheezy-linux-to-raspberry-pi-using-linux/ Linux]
 
[https://cmanios.wordpress.com/2013/03/10/install-raspbian-wheezy-linux-to-raspberry-pi-using-linux/ Linux]
  
== Raspbian default username & password ==
+
==Raspbian default username & password==
 
By default the username and password are:<br />
 
By default the username and password are:<br />
 
Username: pi<br />
 
Username: pi<br />
 
Passowrd:raspberry
 
Passowrd:raspberry
  
== WiFi setup ==
+
==WiFi setup==
 +
===WPA2===
 
1. Scan wifi networks available:
 
1. Scan wifi networks available:
 
  <nowiki>sudo iwlist wlan0 scan</nowiki>
 
  <nowiki>sudo iwlist wlan0 scan</nowiki>
2. Write down the ESSID (wifi network name) and IE (authentication used)<br />
+
2. Write down the ESSID (wifi network name) and IE (authentication used)<br />3. Edit /etc/wpa_supplicant/wpa_supplicant.conf, add the following at the bottom of the file.
3. Edit /etc/wpa_supplicant/wpa_supplicant.conf, add the following at the bottom of the file.
+
<br /><syntaxhighlight lang="text">
<nowiki>
+
country=ES
 +
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
 +
update_config=1
 
network={
 
network={
     ssid="The_ESSID_from_earlier"
+
     ssid="MyWiFiNetwork"
     psk="Your_wifi_password"
+
     psk="MyWiFiPassword"
 +
    key_mgmt=WPA-PSK
 
}
 
}
</nowiki>
+
</syntaxhighlight>
 +
  network={
 +
      ssid="The_ESSID_from_earlier"
 +
      psk="Your_wifi_password"
 +
  }
 
4. If after a few seconds the Raspberry WiFi isn't connected:
 
4. If after a few seconds the Raspberry WiFi isn't connected:
 
  <nowiki>
 
  <nowiki>
sudo ifdown wlan0
+
      sudo ifdown wlan0
sudo ifup wlan0
+
      sudo ifup wlan0 </nowiki>
  </nowiki>
+
 
 +
===WPA2 + hidden SSID===
 +
==interfaces==
 +
Edit /etc/network/interfaces
 +
  <nowiki>
 +
      # /etc/network/interfaces
 +
      allow-hotplug wlan0
 +
      auto wlan0
 +
      iface wlan0 inet dhcp
 +
      wpa-ap-scan 1
 +
      wpa-scan-ssid 1
 +
      wpa-ssid "SSID"
 +
      wpa-proto RSN
 +
      wpa-pairwise CCMP
 +
      wpa-key-mgmt WPA-PSK
 +
      wpa-psk "PASS"</nowiki>
  
== Domain name setup ==
+
==wpa_suplicant==
 +
Not Working:
 +
Edit /etc/network/interfaces
 +
<nowiki>auto lo
 +
     
 +
      iface lo inet loopback
 +
      iface eth0 inet dhcp
 +
     
 +
      allow-hotplug wlan0
 +
      auto wlan0
 +
     
 +
      iface wlan0 inet dhcp
 +
              pre-up wpa_supplicant -Dwext -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf -B</nowiki>
 +
Edit /etc/wpa_supplicant/wpa_suplicant.conf
 +
<nowiki>
 +
      ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
 +
      update_config=1
 +
     
 +
      network={
 +
          ssid=NETWORK_NAME # it can be any encryption type, just make sure to add the "scan_ssid=1" line after your settings.
 +
          psk=password_without_double_quotes
 +
          scan_ssid=1
 +
          mode=0
 +
          protp=WPA2
 +
          key_mgmt=WPA-PSK
 +
          pairwise=CCMP
 +
          group=CCMP
 +
          auth_alg=OPEN
 +
          id_str="raspII"
 +
          priority=1
 +
     
 +
      } </nowiki>
 +
Another example:
 +
<nowiki>ctrl_interface=/var/run/wpa_supplicant
 +
      update_config=1
 +
      ap_scan=2
 +
      eapol_version=1
 +
      network={
 +
              ssid="YOUR-SSID-GOES-HERE"
 +
              scan_ssid=1
 +
              mode=0
 +
              proto=WPA2
 +
              pairwise=TKIP
 +
              group=TKIP
 +
              key_mgmt=WPA-PSK
 +
              psk="YOUR-PASSWORD-GOES-HERE"
 +
      }</nowiki>
 +
 
 +
=== WiFi BBVA ===
 +
<syntaxhighlight lang="text">
 +
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
 +
update_config=1
 +
network={
 +
ssid="BBVA"
 +
key_mgmt=WPA-EAP
 +
eap=TTLS
 +
identity="XE505824"
 +
password="********"
 +
phase2="auth=MSCHAPV2"
 +
}
 +
</syntaxhighlight>
 +
 
 +
==Domain name setup==
 
To change the domain server:<br />
 
To change the domain server:<br />
 
Edit /etc/hosts<br />
 
Edit /etc/hosts<br />
Line 36: Line 135:
 
sudo /etc/init.d/hostname.sh<br />
 
sudo /etc/init.d/hostname.sh<br />
  
== ssh rsa key setup ==
+
==Use network time server (NTP)==
 +
<syntaxhighlight lang="bash">
 +
sudo systemctl start systemd-timesyncd
 +
sudo systemctl enable systemd-timesyncd
 +
</syntaxhighlight>
 +
 
 +
==ssh rsa key setup==
 
1. If you don't have an rsa key generate one by runing:
 
1. If you don't have an rsa key generate one by runing:
 
  <nowiki>ssh-keygen -t rsa -C user@domain</nowiki>
 
  <nowiki>ssh-keygen -t rsa -C user@domain</nowiki>
Line 43: Line 148:
 
  <nowiki>cat rsa_key.pub >> ~/.ssh/authorized_keys</nowiki>
 
  <nowiki>cat rsa_key.pub >> ~/.ssh/authorized_keys</nowiki>
  
== Git server ==
+
==Git server==
 
1. Install Git:
 
1. Install Git:
 
  <nowiki>sudo apt-get install wget git-core</nowiki>
 
  <nowiki>sudo apt-get install wget git-core</nowiki>
Line 61: Line 166:
 
<nowiki>git push pi master</nowiki>
 
<nowiki>git push pi master</nowiki>
  
== Disable sleep mode ==
+
==Disable sleep mode==
 
The file /etc/kbd/config contains settings for non-x screen blanking.
 
The file /etc/kbd/config contains settings for non-x screen blanking.
  
Line 69: Line 174:
 
POWERDOWN_TIME=0
 
POWERDOWN_TIME=0
  
=== Disable Realtek 8192cu WiFi Sleep Mode ===
+
===Disable Realtek 8192cu WiFi Sleep Mode===
 
Edit: /sys/module/8192cu/parameters/rtw_power_mgnt
 
Edit: /sys/module/8192cu/parameters/rtw_power_mgnt
 
  cat /sys/module/8192cu/parameters/rtw_power_mgnt
 
  cat /sys/module/8192cu/parameters/rtw_power_mgnt
Line 81: Line 186:
 
With the following content:
 
With the following content:
 
  <nowiki>
 
  <nowiki>
# Disable power management
+
      # Disable power management
options 8192cu rtw_power_mgnt=0</nowiki>
+
      options 8192cu rtw_power_mgnt=0</nowiki>
 
Then reboot. And it's done.
 
Then reboot. And it's done.
 +
 +
==Print Server==
 +
===Install CUPS===
 +
sudo apt-get update
 +
sudo apt-get install cups
 +
Add your raspberry user to lpadmin group.
 +
sudo usermod -a -G lpadmin <user_name>
 +
Log out and log in again for the changes to take effect.<br />
 +
If you are in a trusted network execute:
 +
cupsctl --remote-any
 +
sudo /etc/init.d/cups restart
 +
Connect to the cups management via web browser:<br />
 +
http://raspberry_ip:631<br />
 +
Configure your printer.<br />
 +
To add scanner compatibility you must follow more steps explained in:<br />
 +
http://www.raspberry-pi-geek.com/Archive/2013/01/Converting-the-Raspberry-Pi-to-a-wireless-print-server
 +
 +
==Keyboard Layout==
 +
sudo nano /etc/default/keyboard
 +
XKBLAYOUT="es"
 +
or
 +
dpkg-reconfigure keyboard-configuration
 +
 +
==Raspberry PI HDMI-VGA Compatibility==
 +
[[Raspberry Pi: HDMI-VGA Converter]]<br />
 +
When Raspberry Pi is using a HDMI-VGA adapter is necessary to add an extra configuration in config.txt file (It must be located in boot partition directory but If it does not exist you need to create it). Add next lines at the begining of the file.
 +
<nowiki>#HDMI-VGA Configuration
 +
      hdmi_force_hotplug=1
 +
      hdmi_group=2
 +
      hdmi_mode=16
 +
      hdmi_drive=2</nowiki>   
 +
 +
This setting will force a screen size of '''1024x768 60 Hz'''. Although the screen does not support the new setting will work.
 +
<br />
 +
<br />
 +
Note: This setting works for '''Kali''' and '''Raspbian''' OS.
 +
 +
==Install Python Pillow==
 +
 +
wget http://www.zlib.net/zlib-1.2.11.tar.gz
 +
wget http://www.ijg.org/files/jpegsrc.v8c.tar.gz
 +
extract both: tar -xzvf ...
 +
./configure
 +
./make
 +
./make install
 +
both...
 +
pip install Pillow
 +
<nowiki>accepted
 +
     
 +
     
 +
      You have to re-install PIL and also install the needed libraries as well as link them manually. This answer is based on this blog post for a regular ubuntu PIL installation and this askubuntu question, where it is explained how to compile the jpeg encoding:
 +
     
 +
      ### uninstall PIL
 +
      sudo pip uninstall pil
 +
     
 +
      ### download and compile the JPEG library
 +
      wget http://www.ijg.org/files/jpegsrc.v8c.tar.gz   
 +
      tar xvfz jpegsrc.v8c.tar.gz
 +
      cd jpeg-8c
 +
      ./configure --enable-shared --prefix=$CONFIGURE_PREFIX
 +
      make
 +
      sudo make install
 +
     
 +
      ### link the libraries correctly - RASPBERRY PI ONLY
 +
      sudo ln -s /usr/lib/arm-linux-gnueabi/libjpeg.so /usr/lib
 +
      sudo ln -s /usr/lib/arm-linux-gnueabi/libfreetype.so /usr/lib
 +
      sudo ln -s /usr/lib/arm-linux-gnueabi/libz.so /usr/lib
 +
     
 +
      ### install rest of the libraries, as well as freetrype and zlib
 +
      sudo apt-get install libjpeg-dev libfreetype6 libfreetype6-dev zlib1g-dev
 +
     
 +
      ### re-install PIL
 +
      sudo pip install pil</nowiki>
 +
=Send mail from command line=
 +
https://www.cyberciti.biz/tips/linux-use-gmail-as-a-smarthost.html
 +
echo "this is a test" | mail -s Subject recipient@gmail.com
 +
 +
=Find Raspberry on network=
 +
arp -a | grep 'b8:27:eb'
 +
 +
==GPIO==
 +
 +
===???===
 +
On the boot partition: Edit config.txt to include the following lines...<syntaxhighlight lang="text">
 +
dtparam=i2c_arm=on
 +
dtoverlay=w1-gpio # One wire for sensors sudo systemctl start systemd-timesyncd
 +
sudo systemctl enable systemd-timesyncd
 +
dtoverlay=pwm-2chan  # Pulse with modulation
 +
</syntaxhighlight>
 +
 +
 +
=Other configurations=
 +
https://elinux.org/RPiconfig

Latest revision as of 10:25, 11 February 2021

Enable ssh on first boot

On the boot partition create a file called ssh

Installing Raspbian

  1. Download Raspbian image from here.
  2. Format SD card using FAT32.
    sudo mkdosfs -F 32 -v /dev/mmcblk0
  3. umount /dev/mmcblk0
  4. Install squashed file sistem on SD card.
    sudo dd bs=4M if="/home/linux/2013-02-09-wheezy-raspbian.img" of=/dev/mmcblk0
    
    # Or directly from zipped image:
    unzip -p 2017-04-10-raspbian-jessie.zip | sudo dd of=/dev/sdX bs=4096
    # With progress indicator:
    dd bs=4M if=2017-04-10-raspbian-jessie.img of=/dev/sdX status=progress
    To see progres bar:
    dd bs=4M if=/media/rafa/GIT/iso/2016-03-18-raspbian-jessie.zip | pv | dd of=/dev/mmcblk0

Linux

Raspbian default username & password

By default the username and password are:
Username: pi
Passowrd:raspberry

WiFi setup

WPA2

1. Scan wifi networks available:

sudo iwlist wlan0 scan

2. Write down the ESSID (wifi network name) and IE (authentication used)
3. Edit /etc/wpa_supplicant/wpa_supplicant.conf, add the following at the bottom of the file.


country=ES
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
    ssid="MyWiFiNetwork"
    psk="MyWiFiPassword"
    key_mgmt=WPA-PSK
}
 network={
     ssid="The_ESSID_from_earlier"
     psk="Your_wifi_password"
 }

4. If after a few seconds the Raspberry WiFi isn't connected:

      sudo ifdown wlan0
      sudo ifup wlan0 

WPA2 + hidden SSID

interfaces

Edit /etc/network/interfaces

      # /etc/network/interfaces
      allow-hotplug wlan0
      auto wlan0
      iface wlan0 inet dhcp
      wpa-ap-scan 1
      wpa-scan-ssid 1
      wpa-ssid "SSID"
      wpa-proto RSN
      wpa-pairwise CCMP
      wpa-key-mgmt WPA-PSK
      wpa-psk "PASS"

wpa_suplicant

Not Working: Edit /etc/network/interfaces

auto lo
      
      iface lo inet loopback
      iface eth0 inet dhcp
      
      allow-hotplug wlan0
      auto wlan0
      
      iface wlan0 inet dhcp
              pre-up wpa_supplicant -Dwext -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf -B

Edit /etc/wpa_supplicant/wpa_suplicant.conf

      ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
      update_config=1
      
      network={
          ssid=NETWORK_NAME # it can be any encryption type, just make sure to add the "scan_ssid=1" line after your settings.
          psk=password_without_double_quotes
          scan_ssid=1
          mode=0
          protp=WPA2
          key_mgmt=WPA-PSK
          pairwise=CCMP
          group=CCMP
          auth_alg=OPEN
          id_str="raspII"
          priority=1
      
      } 

Another example:

ctrl_interface=/var/run/wpa_supplicant
      update_config=1
      ap_scan=2
      eapol_version=1
      network={
              ssid="YOUR-SSID-GOES-HERE"
              scan_ssid=1
              mode=0
              proto=WPA2
              pairwise=TKIP
              group=TKIP
              key_mgmt=WPA-PSK
              psk="YOUR-PASSWORD-GOES-HERE"
      }

WiFi BBVA

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
	ssid="BBVA"
	key_mgmt=WPA-EAP
	eap=TTLS
	identity="XE505824"
	password="********"
	phase2="auth=MSCHAPV2"
}

Domain name setup

To change the domain server:
Edit /etc/hosts
Edit /etc/hostname
Commit changes by runing:
sudo /etc/init.d/hostname.sh

Use network time server (NTP)

sudo systemctl start systemd-timesyncd
sudo systemctl enable systemd-timesyncd

ssh rsa key setup

1. If you don't have an rsa key generate one by runing:

ssh-keygen -t rsa -C user@domain

2. Upload the .pub rsa key to the raspberry
3. Add the .pub key to ~/.ssh/authorized_keys

cat rsa_key.pub >> ~/.ssh/authorized_keys

Git server

1. Install Git:

sudo apt-get install wget git-core

2. Format an USB with FAT32, and connect it to the Raspberry (First turn off the raspberry)
3. Set up a mount point for the USB drive.
3.1 Create directory
3.2 Edit /etc/fstab, add line:

/dev/sda1 /home/pi/usbdrv vfat uid=pi,gid=pi,umask=0022,sync,auto,nosuid,rw,nouser 0 0

note: /dev/sda1 should correspond to usb drive you want to map, pi = user that will own the drieve. umask sets the permissions (substract from 7 the chmod octal value (to set rwx use 0...)
4. reboot Raspberry and check if the usb mounts correctly with lsblk
5. For each repository:
5.1 create a folder and cd into it.
5.2 git init --bare
5.3 add origin to your local git repository. Example:

git remote add pi pi@10.0.1.64:/home/pi/usbdrv/justdiedbot.git

5.4 push your repository into raspberry. Example: git push pi master

Disable sleep mode

The file /etc/kbd/config contains settings for non-x screen blanking.

change the following: BLANK_TIME=0 BLANK_DPMS=off POWERDOWN_TIME=0

Disable Realtek 8192cu WiFi Sleep Mode

Edit: /sys/module/8192cu/parameters/rtw_power_mgnt

cat /sys/module/8192cu/parameters/rtw_power_mgnt

If the file doesn't exist your WiFi adapter uses a diferent chip.
If it's set to:
1: Power safe is enabled
2: Power safe is disabled

Create a new file:

sudo nano /etc/modprobe.d/8192cu.conf

With the following content:

      # Disable power management
      options 8192cu rtw_power_mgnt=0

Then reboot. And it's done.

Print Server

Install CUPS

sudo apt-get update
sudo apt-get install cups

Add your raspberry user to lpadmin group.

sudo usermod -a -G lpadmin <user_name>

Log out and log in again for the changes to take effect.
If you are in a trusted network execute:

cupsctl --remote-any
sudo /etc/init.d/cups restart

Connect to the cups management via web browser:
http://raspberry_ip:631
Configure your printer.
To add scanner compatibility you must follow more steps explained in:
http://www.raspberry-pi-geek.com/Archive/2013/01/Converting-the-Raspberry-Pi-to-a-wireless-print-server

Keyboard Layout

sudo nano /etc/default/keyboard

XKBLAYOUT="es" or

dpkg-reconfigure keyboard-configuration

Raspberry PI HDMI-VGA Compatibility

Raspberry Pi: HDMI-VGA Converter
When Raspberry Pi is using a HDMI-VGA adapter is necessary to add an extra configuration in config.txt file (It must be located in boot partition directory but If it does not exist you need to create it). Add next lines at the begining of the file.

#HDMI-VGA Configuration
      hdmi_force_hotplug=1
      hdmi_group=2
      hdmi_mode=16
      hdmi_drive=2    

This setting will force a screen size of 1024x768 60 Hz. Although the screen does not support the new setting will work.

Note: This setting works for Kali and Raspbian OS.

Install Python Pillow

wget http://www.zlib.net/zlib-1.2.11.tar.gz
wget http://www.ijg.org/files/jpegsrc.v8c.tar.gz
extract both: tar -xzvf ...
./configure
./make
./make install
both...
pip install Pillow
accepted
      	
      
      You have to re-install PIL and also install the needed libraries as well as link them manually. This answer is based on this blog post for a regular ubuntu PIL installation and this askubuntu question, where it is explained how to compile the jpeg encoding:
      
      ### uninstall PIL
      sudo pip uninstall pil
      
      ### download and compile the JPEG library
      wget http://www.ijg.org/files/jpegsrc.v8c.tar.gz    
      tar xvfz jpegsrc.v8c.tar.gz
      cd jpeg-8c
      ./configure --enable-shared --prefix=$CONFIGURE_PREFIX
      make
      sudo make install
      
      ### link the libraries correctly - RASPBERRY PI ONLY
      sudo ln -s /usr/lib/arm-linux-gnueabi/libjpeg.so /usr/lib
      sudo ln -s /usr/lib/arm-linux-gnueabi/libfreetype.so /usr/lib
      sudo ln -s /usr/lib/arm-linux-gnueabi/libz.so /usr/lib
      
      ### install rest of the libraries, as well as freetrype and zlib
      sudo apt-get install libjpeg-dev libfreetype6 libfreetype6-dev zlib1g-dev
      
      ### re-install PIL
      sudo pip install pil

Send mail from command line

https://www.cyberciti.biz/tips/linux-use-gmail-as-a-smarthost.html

echo "this is a test" | mail -s Subject recipient@gmail.com

Find Raspberry on network

arp -a | grep 'b8:27:eb'

GPIO

???

On the boot partition: Edit config.txt to include the following lines...

dtparam=i2c_arm=on
dtoverlay=w1-gpio # One wire for sensors sudo systemctl start systemd-timesyncd
sudo systemctl enable systemd-timesyncd
dtoverlay=pwm-2chan  # Pulse with modulation


Other configurations

https://elinux.org/RPiconfig