Tuesday, July 28, 2020

Raspberry Pi set up for development

I had a really old Raspberry Pi sitting around that I set up for development yesterday. The Pi 2 doesn't come with WiFi by default, so I set up a WiFi Adapter so it would be easier to develop on my localhost and ssh as necessary.

Environment:
Host: macOS Catalina
Raspberry Pi 2 Model B
Raspberry Pi USB WiFi Adapter (I have this one)
Raspberry Pi Camera Module V2
  1. Install Raspberry Pi OS image on an SD card: I used Raspberry Pi Imager rbi-imager for macOS, chose Raspberry Pi OS (32-bit) -  https://www.raspberrypi.org/documentation/installation/installing-images/
  2. If you plan to use the WiFi Adapter and Camera, connect those.
  3. Boot into the Raspberry Pi and login
  4. Connect any peripherals (monitor, keyboard, mouse)
  5. Open terminal
  6. Confirm the OS version. Mine is "Raspbian GNU/Linux 10 (buster)"
  7. cat /etc/os-release
    
  8. Update settings for US.  
    • On the Welcome to Raspberry Pi screen
      • Click Next
        • Country: Choose United States
        • Language: American English
        • Time Zone: New York
          • Enable Use English language and Use US keyboard
      • Click Next
        • Enter password
      • I skipped the WiFi configuration screen since my SSID is not broadcasting so need to configure it manually
    • This is an alternative way to do it via the command line.  Key thing is I needed for my keyboard to recognize the double-quote key
    • sudo raspi-config 
      Choose Localisation Options 
      Choose Change Locale => en_US.UTF-8 UTF-8 
      Choose Change Keyboard Layout => Generic 101-key PC => Other => English (US) (Country of Origin) => English (US) (Keyboard layout) => The default for the keyboard layout => No compose key => 
      Choose Change WLAN Country => US United States 
      sudo reboot
  9. Configure Raspberry Pi to connect to WiFi

    Backup file and copy to your home folder
    sudo cp /etc/wpa_supplicant/wpa_supplicant.conf /etc/wpa_supplicant/wpa_supplicant.conf.orig
    cp /etc/wpa_supplicant/wpa_supplicant.conf ~
    

    Add below to the end of the file. I had to add scan_ssid=1 because my SSID is not broadcasting.  NOTE:  If you have special characters in your password, e.g. double quote I didn't have to escape it but I had to add in key_mgmt=WPA-PSK config attribute (with no quotes).
    vi ~/wpa_supplicant.conf 
    
    network={ 
      ssid="<ssid>"
      psk="<secret password>"
      scan_ssid=1 
    } 
    

    Copy updated file back
    sudo cp ~/wpa_supplicant.conf /etc/wpa_supplicant/wpa_supplicant.conf 
    

    Verify if the “inet addr” is available on wlan0
    ifconfig wlan0 
    

    If not, reboot to connect
    sudo reboot 
    

    On reboot, I can see it the IP address is XXX.XXX.XX.XXX”

    To verify internet connectivity perform a wget
    wget www.google.com
    
  10. Enable ssh on Raspberry Pi
    sudo raspi-config 
    Choose Interface Options 
    Choose SSH => Yes 
    [Didn’t need to reboot]
    
  11. Enable camera on Raspberry Pi
    sudo raspi-config 
    Choose Interface Options 
    Choose Camera => Yes 
    [Prompted to reboot] => Yes
    
  12. Connect to Raspberry Pi via ssh from localhost, update macOS hosts file with Raspberry Pi IP
    sudo vi /private/etc/hosts 
    

    Added this to bottom of file
    # raspberry pi 
    XXX.XXX.XX.XXXX csrp
    

    ssh to the Raspberry Pi
    ssh pi@csrp
    
  13. Verify camera works
    • The Raspberry Pi captures video as raw H264 video stream
      • raspistill -o ~/image-small.jpg -w 640 -h 480
        raspivid -o ~/video.h264 
        
    • secure copy to and open it in macOS
      • scp pi@csrp:/home/pi/image-small.jpg ~/Downloads
        scp pi@csrp:/home/pi/video.h264 ~/Downloads
        
  14. Shutdown the Raspberry Pi
    sudo halt
    

No comments:

Post a Comment

I appreciate your time in leaving a comment!