AvidDabbler Blog

Ugh!!! I Broke My Pi

February 15, 2020

The Joys of Linux

So you know how you will always have a project that you you will come back to and inevitably something will have broken? Yeah that’s pretty much my relationship with the Raspberry Pi. as a big believer in open source and the community I inevitably every six months say, “I should wipe my OS and move to Linux and become a real Nerd”. Then I always say to myself “Hey you should do a Pi project before you make the jump”. And then I spend 3 days trying to figure out what the hell I did to mess up this piece of hardware that has just been sitting on the shelf for 6 months.

So like I said I pick up this Pi about every 6 months and say that I am going to do something with it and eventually get bogged down at work or I start a new coding class because I don’t like free time and I have always been exceptional at picking up more projects then I have the ability to take breaths. Which ironically I think that is partially the reason why I started “this” project… my blog. It is supposed to be here as documentation, to keep me focused and help my organize my thoughts and goals in a productive manor rather than attempting to grasp at them as they float by in my head.

Rundown

So my reasoning for getting started again with the Raspberry Pi kind of revolve around the Iot space. In the past couple of years I have become fascinated with this space in technology and its applications within the Transit Technology community. So the purpose of this “for me” is to set up a remote development environment so that I can connect to my Pi without having to set up accessories for it and it allows me to use VSCode or PyCharm without bogging down my Pi.

In this post I am hoping to accomplish a couple of things:

  1. Document out my frustrations with Linux
  2. Spell out how to do a fresh install of Raspbian on your Pi
  3. Connect to your Pi via SSH and Remote Desktop
  4. Manage your Pi files and write code remotely from your local machine

Things you will need:

  1. A Raspberry Pi (with sd card)
  2. A Windows machine that has a way to write to SD cards
  3. A copy of Raspbian
  4. A copy of Win32DiskImager

Wipe the damn thing

So like I said this is going to be a complete restart. I just decided that I wanted to do a full wipe of the SD card as I was just having some difficulties working with the install that I had tried to update. This section will cover how to wipe your SD card and reformat using Window Disk Management.

  1. Connect the SD Card Obviously the first thing that you need to do is get your card setup. Whether that is though a port in your local machine or an dongle just get the SD card connected so that your computer can read it
  2. In the Windows Menu type “Disk Management” A program will pop-up in the menu bar saying “Create and Format Hard Disk Partitions”. Open that program
  3. Look for your SD Card When the program loads up look for your SD card listed. If you already have a copy on there it will have a partition called “boot”. If not just make sure it matches the disk name that popped up when you inserted the card.

find the partitions

  1. Wipe out all of the partitions. When you open up Disk Management you should be able to right-click on each of the partitions that are set up on your SD card. Click ‘Delete Volume’ for each of the partitions so that you can start fresh. At the end you should just have an unformatted partition that takes up the whole disk space.

Download Raspbian

  1. Go to the Raspbian Site and download the latest version. For this instance I would just reccomend that you use the full download with recommended software. This will get you setup with the raspbian cli and gui all in one without additional configuration.

download raspbian

  1. Unzip the files

Write IMG file to SD card

  1. Download and install a Copy of Win32DiskImager
  2. Move the IMG file to the SD card.

Boot

  1. Insert the SD Card After inserting the SD Card you should be able to boot up the machine. Connect up a mouse keyboard and monitor to continue with setting up the internet through wifi or LAN connection.

Full update!!!

For sanity sake. Go ahead and update everything by opening up terminal on your pi and running.

This is going to take a while. So make sure that you have the time to run. So make sure that you will be able to leave it running with a secure internet connection.

sudo apt update && sudo apt full-upgrade -y

SSH

Config Pi

In this section we are going to cover how to connect your main computer or laptop to you pi via ssh. This is how we will be able to run commands via the command line to execute processes in terminal or windows.

  1. Boot up your Pi If your pi is not already on and connected to the internet go ahead a do that now.
  2. Open up ‘Raspberry Pi Configuration’ settings To do this you are going to want to click the start menu at the top left of the screen (The one with the raspberry). Go to preferences > raspberry pi configuration
  3. Click the interfaces tab
  4. Enable VNC and SSH In the pi configuration window, the second tab allows you enable and disable certain functions. You are going to want to enable VNC and SSH here.

Config Main Computer (Windows 10)

  1. (On your Pi) open up the terminal and type sudo ifconfig. Under wlan you will see an ip address next to inet. This is the pi’s ip address and you will need this to connect to the pi using putty.
  2. (On Windows) Download Putty
  3. Once you have downloaded and installed Putty open it up and create a new connection by inputting the ip address and using port 22

putty setup example

  1. Once you have add all of the inputs and saved the connection click open and this will open a terminal window.
  2. This window will prompt you to log in to your Pi by asking for your user name and password. The default username is pi and the password is raspberry.
  3. Once you fill out this information you should be logged into the device. If you get errors, go back and check the ip address that you entered is correct and that you have turned on all of the necessary permissions for ssl connections.

Remote Desktop (VNC)

In this section we are going to go over how to connect via ‘Remote Desktop Connection’ on Windows 10. This will allow you to actually see what is happening on your Raspberry pi in realtime via your main computer or laptop. Just like SSH this will only cover how to do so when both devices are on the same network connection.

On your Raspberry Pi

  1. Install the xrdp packages by opening terminal and running
sudo apt install xrdp

This should only take a couple of minutes, but it will require you to have an internet connection to your Pi to download the software.

  1. In the SSH section you should have already enabled VNC on your Pi, but if you are not sure go back to step 2 in the SSH Config Pi section On Windows
  2. Open up your Remote Desktop Connection
  3. Type in the IP address that you used to SSH into your Pi
  4. Connect
  5. When prompted enter your Pi username and password
  6. BOOM! Ya done son.

Access Pi files from Windows File Explorer

  1. Connect to Pi via SSH (using putty again)
  2. Navigate to the root directory by running cd ../..
  3. run sudo apt-get install samba samba-common-bin to install networking tools
  4. [Windows] in command prompt run ping raspberry pi to make sure you can connect to the pi.
  5. [pi] run sudo cp smb.conf smb.old to save a copy and sudo nano /ect/samba/smb.conf to start editing. This will open up the smbdgat.conf file to be edited via in command line
  6. Under Authentication add security = user
  7. Under Share Definition change read only = no
  8. Hit CTRL+O and then ENTER to save the file.
  9. Then Hit CTRL+X to exit nano.
  10. In the pi terminal. Run sudo smbpasswd -a pi to set the samba password
  11. Type in and confirm your password to set and save.
  12. Restart samba by running sudo service smbd restart
  13. [Windows] Open up file explorer and right-click ‘this pc’ > map network drive
  14. type in ’\raspberrypi\pi’ and set to different credentials hit okay and it will prompt you to sign in.
  15. There should now be a mapped pi to your file explorer and you can now transfer files between the 2.

SOURCES!!!

https://www.raspberrypi.org/documentation/installation/installing-images/ —> Reimage Pi SD Card https://www.raspberrypi.org/magpi/ssh-remote-control-raspberry-pi/ —> SSH Tutorial http://www.circuitbasics.com/access-raspberry-pi-desktop-remote-connection/ —> Remote Desktop Connection https://blog.jongallant.com/2017/09/raspberrypi-file-share/ —> Install and Configure Samba https://www.youtube.com/watch?v=4P5nEH9zGDI —> Video on mapping pi as a network drive


Written by Walter Jenkins who lives and works in Saint Louis. His passions are Civic Tech, Smart Cities and Alternative Transportation. He specializes in working with data analysis and visualization through maps.
You should follow him on Twitter.