Estimated time for lesson: 2-3 Hours
Have you ever wondered what all uses can a Raspberry pi be put into? Well let’s explore one such use case. In this series we are going to build a Music Jukebox using a Raspberry Pi, Simple Speakers, DotNet Core and Angular 6. The final product requirements can be organised into 4 categories:
- A computer with Windows, Linux or Mac
- Visual Studio Community or Visual Studio Code
- DotNet Core 2.1 SDK
- Raspberry Pi 3 B+
- 64 GB Class 10 micro SD card.
- Speakers with 3.5 MM Jack
- Wi-Fi router for connectivity/internet access.
- API’s and Frameworks:
- DotNet Core SDK 2.1
- Bass.Net: open source dotnet core wrapper around cross-platform audio library BASS from un4seen.
- Angular 6
- DotNet Core 2.1 music jukebox application: The application would also expose the endpoints to control music operations using REST endpoints (using ASP.Net Core 2.1 WebApi and Kestrel server).
- Angular 6 client App served from Asp.Net Core 2.1 WebServer running inside a Kestrel process.
In the first part let’s setup our Raspberry Pi 3 B+ by setting up the SD Card and installing the latest version of Raspbian. Raspbian is a Debian based linux distribution. As of writing of this article, the latest version of Raspbian is Raspbian Stretch (Kernel v 4.14). You can install Raspbian either:
- By downloading the NOOBS setup image.
- By downloading the full Raspbian Image.
Both the downloads are available on the Raspberry Pi Foundation website at https://www.raspberrypi.org/downloads/.
We will perform the following steps in order to get the Raspbian Setup on our Raspberry Pi.
- Format the 64 GB micro SD card using FAT32 file system.
- Copy the NOOBS/Raspbian Image to micro SD Card
- Complete Setup of Raspbian:
- Connect to Wi-Fi network
- Check audio functionality
- Configure Raspberry Pi to have static IP address.
- Enable VNC and SSH on Raspberry PI
1. Format 64 GB micro SD Card with FAT32 file system
The raspberry PI can boot from any disk that has a FAT32 file system. The NOOBS or Raspbian images that we are going to download from https://www.raspberrypi.org/downloads/ can be used to boot the Raspberry Pi 3. The key concept to note here is that the SD card needs to be formatted using FAT32 (and not exFat file system or NTFS):
One of the key challenges when using Windows to format 64 GB SD card to use FAT32 file system is that Microsoft has set a limit of 32GB partition size for FAT32 file system to promote NTFS file system. FAT32 file system can support upto 16TB partitions but on Windows operating system you cannot format a disk with size greater than 32 GB with FAT32 file system. In order to overcome this you can either use a Mac or Linux machine or if you insist on Windows then I recommend this software called GUI Format – it’s a GUI wrapper around fat32format command line utility. You can download it from below links.
The utility is created by Ridgecrop Consultants Ltd. and they own all rights of the software. I am providing the tool as is.
2. Copy the NOOBS/Raspbian to SD card
After formatting your card you need to download NOOBS setup or Raspbian OS image from https://www.raspberrypi.org/downloads/ on your computer. After downloading, extract the contents of the zip file to a folder and copy the extracted files (from root of the extracted folder) over to the SD card. If you downloaded the Raspbian Image (and not NOOBS image) – you can jump directly to Step 4.
3. Install Raspbian using NOOBS
In this step we will setup our Raspberry PI by installing Raspbian using NOOBS image.
- Insert the SD card into your Raspberry PI (see below illustration – courtesy: https://projects.raspberrypi.org)
- Connect keyboard and mouse (USB only) to the Raspberry PI (see below illustration – courtesy: https://projects.raspberrypi.org)
- Connect a HDMI screen to your Raspberry PI – needed only for one time setup (see below illustration – courtesy: https://projects.raspberrypi.org)
- Start your Raspberry PI (see below illustration – courtesy: https://projects.raspberrypi.org)
- Follow the instructions as explained in the section below (images courtesy: https://projects.raspberrypi.org)
- Power up your Raspberry PI
- Once the Raspberry PI finishes booting up you will be presented with the below screen.
- Select Raspbian Full from the list and click on the install button.
- Click “Yes” in the dialog box that follows and then wait for the installation to complete as shown below.
- After installation is complete you will get a confirmation message as shown below.
- Raspberry PI will reboot and you will see the Raspbian Desktop as seen below.
4. Setup Raspbian OS
- When you start your Raspberry Pi for the first time, the Welcome to Raspberry Pi application will pop up and guide you through the initial setup.
- Click Next to start the setup.
- Set your Country, Language, and Timezone, then click Next again.
- Enter a new password for your Raspberry Pi and click Next.
- Connect to your WiFi network by selecting its name, entering the password, and clicking Next.
- Click Next let the wizard check for updates to Raspbian and install them (this might take some time).
- Click Done or Reboot to finish the setup.
- Open terminal after the Raspberry PI reboots (as shown below), in the next steps we will set static IP address and enable VNC and SSH on our Raspberry PI. This would give us a static access point for connecting to our PI for configuration.
- In the terminal window type the command sudo nano /etc/dhcpcd.conf and delete everything in the editor window that comes up and add the following:
interface eth0 static ip_address=192.168.1.201/24 static routers=192.168.1.1 static domain_name_servers=192.168.1.1 interface wlan0 static ip_address=192.168.1.201/24 static routers=192.168.1.1 static domain_name_servers=192.168.1.1
- Save the file by pressing ctrl+O, exit the editor by pressing ctrl+X
- Open the Raspbian OS start menu by clicking on the Raspberry Icon on top left corner of the screen and select Preferences>Raspberry Pi Configuration utility as shown below
Enable all options as shown below and click on OK button and reboot your Raspberry Pi.
- You can now unplug the HDMI cable from your Raspberry PI and connect using VNC Viewer (can be downloaded from https://www.realvnc.com/en/connect/download/viewer/)
- Now your Raspberry PI is ready for hosting our .Net Core 2.1 applications. DotNet Core 2.1 applications can be published as stand alone applications so you don’t need to have DotNet core SDK installed on your target devices.
- You can either connect to your Raspberry PI using RealVNC Viewer or SSH for the next steps (I am not going to talk about SSH or Real VNC to keep the focus on the core topic – you can learn more about these here) :
- Real VNC Connection: https://www.realvnc.com/en/connect/docs/raspberry-pi.html
- SSH Connection: https://www.raspberrypi.org/magpi/ssh-remote-control-raspberry-pi/
In the next article we will understand this setup. Later in the series we will start creating our applications and deploy them several times to Raspberry PI until we have the final interface ready.