Introduction

Raspberry Pi, the versatile and affordable single-board computer, has become a favorite among DIY enthusiasts and developers. In this blog post, we’ll guide you through the process of setting up your Raspberry Pi, installing the Raspberry Pi OS, and culminating in a hands-on project to control an LED using Python in a Jupyter Notebook.

Installation Steps

1. Download Raspberry Pi OS

Begin by visiting the Raspberry Pi Software page. Download the Raspberry Pi Imager.

2. Install Raspberry Pi OS

  • Insert your microSD card into the computer.
  • Run the Raspberry Pi Imager and select Raspberry Pi OS (64-bit).
  • Set storage options and enable SSH.
  • Set a username and password.
  • Click “WRITE” to transfer the OS to the microSD card.

3. Initial Setup on Raspberry Pi

  • Insert the microSD card into the Raspberry Pi and power it on.
  • Set your Country, Language, and Timezone.
  • Create a user account and connect to a WiFi network.
  • Choose a browser and update software.

4. Installing Python Libraries

Open a terminal and run the following commands to install essential Python libraries:

sudo su
apt-get update
apt-get install python3-matplotlib
apt-get install python3-scipy
exit

5. Configuring a Jupyter Notebook

To avoid the “externally-managed-environment” error, follow the steps outlined in the Raspberry Pi documentation.

mkdir my_project
cd my_project
python -m venv env
#or python -m venv --system-site-packages env
source env/bin/activate
pip3 install --upgrade pip
pip3 install jupyter
deactivate
reboot
cd my_project
source env/bin/activate
jupyter notebook
#note the generated token

6. Network and Browswer Configuration

1. Retrieve Hostname and IP Address:

To discover the IP address of your machine, use the following command:

hostname -I

This command returns the IP address associated with your hostname.

2. View Routing Information:

To examine the routing information for your system, use the ip command:

ip r

This displays the routing table, providing insights into how network packets are directed.

3. Check DNS Configuration:

To identify the nameserver configuration and check DNS settings, execute:

grep "nameserver" /etc/resolv.conf

This command extracts lines containing “nameserver” from the resolv.conf file, revealing DNS server details.

4. Explore Operating System Information:

To gather information about your operating system, use the following command:

cat /etc/os-release

This command outputs details like the OS name, version, and other relevant information stored in the os-release file.

These commands provide a quick overview of your system’s network configuration and operating system details, aiding in troubleshooting and system understanding.

5. Improve browsing experience by setting a browser as the default:

sudo update-alternatives --config x-www-browser
sudo reboot

7. SSH Connection and Jupyter Notebook

  • Open PuTTY and enter the Raspberry Pi’s IP address.
  • Navigate to Connection -> SSH -> Tunnels. Set Source port to 8888 and Destination to localhost:8888.
  • Save the session and open the connection.
  • Open your web browser and go to http://localhost:8888/. Enter the generated token.

8. LED Control Project

Now, let’s delve into a simple LED control project.

Hardware Setup

  1. Insert an LED into the breadboard.
  2. Connect the cathode of the LED to a resistor and GPIO pin 6 on the Raspberry Pi.
  3. Connect the anode of the LED to a ground (GND) pin on the Raspberry Pi.

Software Setup (In Jupyter Notebook)

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)
GPIO.setup(6, GPIO.OUT)

while True:
    GPIO.output(6, GPIO.HIGH)
    time.sleep(15)
    GPIO.output(6, GPIO.LOW)
    time.sleep(10)

This simple Python script turns on the LED for 15 seconds and then turns it off for 10 seconds in an infinite loop.

Conclusion

Congratulations! You’ve successfully set up your Raspberry Pi, configured a Jupyter Notebook, and even embarked on a basic hardware project. The possibilities with Raspberry Pi are endless, and this blog serves as a stepping stone for more exciting ventures into the world of DIY electronics and programming. Explore further, experiment, and enjoy your Raspberry Pi journey!