Difference between revisions of "Setting Up Your Raspberry Pi"

From AstroBaki
Jump to navigationJump to search
(Created page with "With the growing utility and prevalence of low-cost computing boards, it is becoming increasingly common to embed computing directly into instrumentation. The Raspberry Pi is...")
 
 
(24 intermediate revisions by 2 users not shown)
Line 10: Line 10:
 
==Raspberry Pi==
 
==Raspberry Pi==
 
* Raspberry PI 4 version B (2 or 4 GB RAM) (~$45/$55 ea). Alternately, may use RPI 3.
 
* Raspberry PI 4 version B (2 or 4 GB RAM) (~$45/$55 ea). Alternately, may use RPI 3.
** stock is low because of pandemic supply chain problems. Try https://www.canakit.com/raspberry-pi-4-4gb.html or https://www.sparkfun.com/products/15446.
+
** stock is low because of pandemic supply chain problems. Try https://rpilocator.com , https://www.canakit.com/raspberry-pi-4-4gb.html or https://www.sparkfun.com/products/15446.
 
** if stock is exhausted, back-order and switch to using it whenever it arrives (using the class ones in the meantime)
 
** if stock is exhausted, back-order and switch to using it whenever it arrives (using the class ones in the meantime)
 
** the computing board does not come with: monitor, keyboard, mouse, power supply, SD card (its hard drive), or even a case to hold it. Some places sell a "starter kit" that has many of these things, or you can buy them separately (under accessories below).
 
** the computing board does not come with: monitor, keyboard, mouse, power supply, SD card (its hard drive), or even a case to hold it. Some places sell a "starter kit" that has many of these things, or you can buy them separately (under accessories below).
Line 16: Line 16:
 
====RPi Accessories====
 
====RPi Accessories====
 
* plastic case ($6 ea; e.g. https://www.adafruit.com/product/4301)
 
* plastic case ($6 ea; e.g. https://www.adafruit.com/product/4301)
 +
** note that RPi1-3 cases are not compatible with RPi4
 
* 15W USB-C charger w/ cable (~$15 ea; e.g. https://www.adafruit.com/product/4298)
 
* 15W USB-C charger w/ cable (~$15 ea; e.g. https://www.adafruit.com/product/4298)
* micro HDMI to HDMI cable (~$10 ea; e.g. https://www.adafruit.com/product/1322)
+
** not all USB-C chargers source the same power. Any USB-C charger will work, provided it supplies >= 15 W.
 +
** RPi1-3 use micro-USB (not USB-C). a cheap USB-C to micro-USB adapter (e.g. https://www.amazon.com/Adapter-Convert-Connector-Support-Compatible/dp/B07GH5KJH2) will do the trick.
 +
* micro-HDMI to HDMI cable (~$10 ea; e.g. https://www.adafruit.com/product/1322)
 +
** necessary for RPi4 (RPi1-3 use HDMI)
 
** we will have these in class, but if you want to plug into a monitor (or TV) at home, you'll need this
 
** we will have these in class, but if you want to plug into a monitor (or TV) at home, you'll need this
 
* aluminum 15x15x15 mm heatsink ($2 ea; e.g. https://www.adafruit.com/product/3082)
 
* aluminum 15x15x15 mm heatsink ($2 ea; e.g. https://www.adafruit.com/product/3082)
Line 34: Line 38:
 
* (option 2) Nooelec NESDR Mini R820T SDR & DVB-T (~$25 ea; e.g. https://www.nooelec.com/store/sdr/sdr-receivers/nesdr-mini.html)
 
* (option 2) Nooelec NESDR Mini R820T SDR & DVB-T (~$25 ea; e.g. https://www.nooelec.com/store/sdr/sdr-receivers/nesdr-mini.html)
 
** same chipset as above, but less rugged. has a mcx connector that requires a male mcx to male sma pigtail connector ($10, https://www.nooelec.com/store/male-mcx-to-male-sma-pigtail-rg316-0-5-length.html) to connect to other stuff in class, but we will buy some of these to have on hand.
 
** same chipset as above, but less rugged. has a mcx connector that requires a male mcx to male sma pigtail connector ($10, https://www.nooelec.com/store/male-mcx-to-male-sma-pigtail-rg316-0-5-length.html) to connect to other stuff in class, but we will buy some of these to have on hand.
 +
 +
==Setup==
 +
The SD card you ordered functions as your RPi's hard drive. You will need to install it with an operating system, along with any software you will need. The easy way to do this is to clone an existing installation from another card. If you come to class, we will do this for you. Otherwise, follow the instructions below.
 +
 +
===Setup from Scratch===
 +
Raspberry Pi's benefit from being a standard set of hardware. As such, they have a customized version of Linux (a free, open-source version of Unix) that runs on them an includes drivers for all their hardware. That customized Linux version is called Raspbian (being a branch of Debian Linux for a Raspberry Pi). Other operating systems exist, but we will only support Raspbian in class.
 +
 +
* Set up SD Card
 +
** This has to be done on an already working computer with an SD Card reader. Instructions are [https://elinux.org/RPi_Easy_SD_Card_Setup here]. Below is a summary outline for Linux.
 +
** On an existing linux installation, you can use <tt>gparted</tt>
 +
*** plug in SD card
 +
*** use <tt>dmesg</tt> to find the <tt>/dev/</tt> path to the device (<tt>/dev/mmcblk0</tt> in this tutorial). Do *not* use any <tt>pN</tt> extensions to this name (e.g. <tt>mmcblk0p1</tt>).
 +
*** format SD Card as FAT32
 +
*** <tt>umount /dev/mmcblk0</tt>
 +
*** download a basic Raspbian install from https://www.raspberrypi.com/software/operating-systems
 +
**** current (Jan. 2022) version is https://downloads.raspberrypi.org/raspios_full_armhf/images/raspios_full_armhf-2021-11-08/2021-10-30-raspios-bullseye-armhf-full.zip
 +
*** <tt>sudo dd bs=1M if=2021-10-30-raspios-bullseye-armhf-full.img of=/dev/mmcblk0
 +
**** (can check progress with <tt>sudo iotop -o </tt>, takes about 5 min)
 +
 +
* Initial boot
 +
** get wireless up (click Desktop icon in top-right)
 +
** open up a terminal and run the following commands
 +
*** <tt>sudo apt update</tt>
 +
*** <tt>sudo apt upgrade</tt>
 +
** open Raspberry Pi Configuration (menu)
 +
*** change hostname to, e.g., radiopi
 +
*** Interfaces: ssh=enabled, vnc=enabled, remote gpio=enabled
 +
*** Localisation: Keyboard US layout
 +
** reboot
 +
** change passwd
 +
 +
* Software Install
 +
** <tt>sudo apt install python3-ipython jupyter vim texlive libusb-1.0-0-dev libtool autoconf screen</tt>
 +
** Copy over VIM config (if you use vim)
 +
** <tt>scp .vimrc pi@radiopi:</tt>
 +
** Fix missing ipython command
 +
*** <tt>vi .pydisutils.cfg</tt> and add these lines:
 +
**** <tt>[install]
 +
**** <tt>install-scripts=/usr/local/bin</tt>
 +
*** <tt>sudo pip3 install --force ipython</tt>
 +
*** <tt>sudo pip3 install astropy</tt>
 +
*** <tt>sudo apt-get install autoconf</tt>
 +
*** <tt>sudo apt install libtool</tt>
 +
*** <tt>sudo pip3 install wxpython</tt>
 +
*** <tt>sudo apt-get install libatlas-base-dev</tt>
 +
*** <tt>sudo pip3 install numpy==1.22</tt>
 +
 +
===SDR Setup===
 +
See https://wiki.gentoo.org/wiki/Rtl-sdr
 +
* Plug SDR module in
 +
* Force detect as sdr, not dvb
 +
** <tt>sudo vi /etc/modprobe.d/blacklist-dvb.conf</tt> add the following line:
 +
*** <tt>blacklist dvb_usb_rtl28xxu</tt>
 +
** <tt>sudo apt install rtl-sdr gqrx-sdr</tt>
 +
** <tt>sudo vi /etc/udev/rules.d/20-rtlsdr.rules</tt> add the following line:
 +
*** <tt>SUBSYSTEM==”usb”, ATTRS{idVendor}==”0bda”, ATTRS{idProduct}==”2838”, GROUP=”pi”, MODE=”0666”, SYMLINK+=”rtl_sdr”</tt>
 +
 +
===USBTMC Setup===
 +
Necessary only for controlling Agilent signal generator
 +
* <tt>sudo vi /etc/udev/rules.d/55-usbtmc.rules</tt> with the following lines:
 +
** <tt>SUBSYSTEM=="usb", ATTR(idVendor)=="0957", ATTR(idProduct)=="2018", GROUP="plugdev"</tt>
 +
** <tt>KERNEL=="usbtmc/*", MODE="0660", GROUP="plugdev"</tt>
 +
** <tt>KERNEL=="usbtmc[0-9]*", MODE="0660", GROUP="plugdev"</tt>
 +
 +
===Class Software===
 +
 +
* install <tt>librtlsdr</tt>
 +
** <tt>git clone https://github.com/AaronParsons/librtlsdr.git</tt>
 +
***<tt>place in src/ directory</tt>
 +
** <tt>cd librtlsdr/</tt>
 +
** <tt>autoreconf -i</tt>
 +
*** <tt>install autoconf, libtool if not found</tt>
 +
** <tt>./configure </tt>
 +
** <tt>make</tt>
 +
** <tt>sudo make install</tt>
 +
** <tt>sudo ldconfig</tt>
 +
* install <tt>pyrtlsdr</tt>
 +
** <tt>git clone https://github.com/AaronParsons/pyrtlsdr.git</tt>
 +
** <tt>cd pyrtlsdr</tt>
 +
** <tt>pip install .</tt>
 +
* install <tt>ugradio</tt>
 +
** <tt>git clone https://github.com/AaronParsons/ugradio.git</tt>
 +
** <tt>cd ugradio/ugradio_code</tt>
 +
** <tt>sudo pip3 install .</tt>
 +
 +
==Networking==
 +
This assumes that your Raspberry Pi will be plugged into the UGAstro LAN in 541
 +
* sudo nano /etc/dhcpcd.conf
 +
** add the following lines at to the end of the dhcpcd.conf file
 +
*** <tt>interface eth0</tt>
 +
*** <tt>static ip_address=10.32.92.###/24</tt>
 +
**** where 200<###<220
 +
*** <tt>static routers=10.32.92.1</tt>
 +
*** <tt>domain_name_servers=128.32.136.12,8.8.8.8 </tt>
 +
** Save and Exit ^O ^X
 +
** turn off wifi
 +
** shutdown the pi
 +
* to check that your IP address is now static
 +
** plug the pi into the ethernet switch and power on
 +
*** ssh into ugastro <tt>ssh USERNAME@ugastro.berkeley.edu</tt>
 +
*** <tt>ping 10.32.92.###</tt>
 +
 +
==Cloning==
 +
This assumes you are on a Linux system.
 +
* Make a copy of an existing RPi filesystem:
 +
** Insert SD Card
 +
** <tt>sudo dd if=/dev/mmcblk0 of=radiopi.img bs=4M status=progress</tt>
 +
* Optional: shrink file system:
 +
** <tt>wget https://raw.githubusercontent.com/Drewsif/PiShrink/master/pishrink.sh</tt>
 +
** <tt>chmod a+x pyshrink.sh</tt>
 +
** <tt>sudo pishrink.sh radiopi.img</tt>
 +
* Copy to a new SD card
 +
** Insert new SD Card
 +
** Ensure it is formatted FAT32 (else use <tt>gparted</tt>)
 +
** unmount the new disk: <tt>umount /media/disk_name</tt>
 +
** <tt>sudo dd bs=4M if=radiopi.img of=/dev/mmcblk0 conv=fsync status=progress</tt>

Latest revision as of 11:41, 12 April 2023

With the growing utility and prevalence of low-cost computing boards, it is becoming increasingly common to embed computing directly into instrumentation. The Raspberry Pi is an example of a relatively low-cost but very versatile computer capable of running a full-fledged (Linux) operating system and performing a non-trivial amount of computing, while also providing interfaces for low-level communication with electronics. The Raspberry PI (RPi) is not the only example of such board, and it is not necessarily suited to all embedded computing applications, but it is widely used and quite capable.

Because of its ubiquity and versatility, we have chosen the RPi as a platform for data acquisition and computing for the Undergraduate Radio Lab. Having a common computing platform for the class makes it easy for us to introduce you to the Linux operating system (a mainstay of scientific computing), the world of embedded computing, and new developments in software-defined radio (SDR). I strongly encourage you to buy your own for use in this class so that you can take it home with you. These little computers are super versatile and you will find that you can use them for all sorts of things. In my home, I use them for wireless print servers, robot controllers, roku-like TV streamers, video game emulators, and as a straight-up desktop computer for kids doing remote schooling. Think of this purchase as your "textbook" for this class.

To get started, here is a parts list:

Raspberry Pi[edit]

  • Raspberry PI 4 version B (2 or 4 GB RAM) (~$45/$55 ea). Alternately, may use RPI 3.
    • stock is low because of pandemic supply chain problems. Try https://rpilocator.com , https://www.canakit.com/raspberry-pi-4-4gb.html or https://www.sparkfun.com/products/15446.
    • if stock is exhausted, back-order and switch to using it whenever it arrives (using the class ones in the meantime)
    • the computing board does not come with: monitor, keyboard, mouse, power supply, SD card (its hard drive), or even a case to hold it. Some places sell a "starter kit" that has many of these things, or you can buy them separately (under accessories below).

RPi Accessories[edit]

Software-Defined Radio (SDR) Receiver[edit]

To digitize radio-frequency (RF) signals and get them on an RPi, you need SDR receiver (we will stock these in class, but if you want one for home, or if you are working remotely, consider buying). These are only necessary for "radio" applications. They come with some cheap antennas you can use to listen to, e.g., FM radio on your RPI. Cheap SDRs have become available because they are used for tuning in to broadcast TV and FM radio.

Setup[edit]

The SD card you ordered functions as your RPi's hard drive. You will need to install it with an operating system, along with any software you will need. The easy way to do this is to clone an existing installation from another card. If you come to class, we will do this for you. Otherwise, follow the instructions below.

Setup from Scratch[edit]

Raspberry Pi's benefit from being a standard set of hardware. As such, they have a customized version of Linux (a free, open-source version of Unix) that runs on them an includes drivers for all their hardware. That customized Linux version is called Raspbian (being a branch of Debian Linux for a Raspberry Pi). Other operating systems exist, but we will only support Raspbian in class.

  • Initial boot
    • get wireless up (click Desktop icon in top-right)
    • open up a terminal and run the following commands
      • sudo apt update
      • sudo apt upgrade
    • open Raspberry Pi Configuration (menu)
      • change hostname to, e.g., radiopi
      • Interfaces: ssh=enabled, vnc=enabled, remote gpio=enabled
      • Localisation: Keyboard US layout
    • reboot
    • change passwd
  • Software Install
    • sudo apt install python3-ipython jupyter vim texlive libusb-1.0-0-dev libtool autoconf screen
    • Copy over VIM config (if you use vim)
    • scp .vimrc pi@radiopi:
    • Fix missing ipython command
      • vi .pydisutils.cfg and add these lines:
        • [install]
        • install-scripts=/usr/local/bin
      • sudo pip3 install --force ipython
      • sudo pip3 install astropy
      • sudo apt-get install autoconf
      • sudo apt install libtool
      • sudo pip3 install wxpython
      • sudo apt-get install libatlas-base-dev
      • sudo pip3 install numpy==1.22

SDR Setup[edit]

See https://wiki.gentoo.org/wiki/Rtl-sdr

  • Plug SDR module in
  • Force detect as sdr, not dvb
    • sudo vi /etc/modprobe.d/blacklist-dvb.conf add the following line:
      • blacklist dvb_usb_rtl28xxu
    • sudo apt install rtl-sdr gqrx-sdr
    • sudo vi /etc/udev/rules.d/20-rtlsdr.rules add the following line:
      • SUBSYSTEM==”usb”, ATTRS{idVendor}==”0bda”, ATTRS{idProduct}==”2838”, GROUP=”pi”, MODE=”0666”, SYMLINK+=”rtl_sdr”

USBTMC Setup[edit]

Necessary only for controlling Agilent signal generator

  • sudo vi /etc/udev/rules.d/55-usbtmc.rules with the following lines:
    • SUBSYSTEM=="usb", ATTR(idVendor)=="0957", ATTR(idProduct)=="2018", GROUP="plugdev"
    • KERNEL=="usbtmc/*", MODE="0660", GROUP="plugdev"
    • KERNEL=="usbtmc[0-9]*", MODE="0660", GROUP="plugdev"

Class Software[edit]

Networking[edit]

This assumes that your Raspberry Pi will be plugged into the UGAstro LAN in 541

  • sudo nano /etc/dhcpcd.conf
    • add the following lines at to the end of the dhcpcd.conf file
      • interface eth0
      • static ip_address=10.32.92.###/24
        • where 200<###<220
      • static routers=10.32.92.1
      • domain_name_servers=128.32.136.12,8.8.8.8
    • Save and Exit ^O ^X
    • turn off wifi
    • shutdown the pi
  • to check that your IP address is now static
    • plug the pi into the ethernet switch and power on
      • ssh into ugastro ssh USERNAME@ugastro.berkeley.edu
      • ping 10.32.92.###

Cloning[edit]

This assumes you are on a Linux system.

  • Make a copy of an existing RPi filesystem:
    • Insert SD Card
    • sudo dd if=/dev/mmcblk0 of=radiopi.img bs=4M status=progress
  • Optional: shrink file system:
  • Copy to a new SD card
    • Insert new SD Card
    • Ensure it is formatted FAT32 (else use gparted)
    • unmount the new disk: umount /media/disk_name
    • sudo dd bs=4M if=radiopi.img of=/dev/mmcblk0 conv=fsync status=progress