Raspberry Pi Tip and Tricks

I’ve had a Raspberry Pi since it launched back in 2012, I was that excited when mine arrived that I even Tweeted about it 😀.

Over the years I’ve used them for all kinds of things, ranging from testing my Internet connection, which I blogged about here to playing my favourite video games from the 90s using RetroPie, what better use of a Pi than winding back the years and playing Sonic the Hedgehog and Mario like it’s 1992 again!

I thought I’d share a few of my Tips and Tricks for using a Raspberry Pi.

Running a Headless Raspberry Pi

I run all my Pi’s headless (not attached to a monitor, keyboard, and mouse) I use SSH and VNC to access my various Pi’s over the network which works well. One small annoyance I had was the need to manually configure the Wifi and SSH whenever I setup a new Pi (or re-image an existing Pi – as I tend to break them!), which meant I had to connect the Pi to a monitor and keyboard to perform the initial configuration prior to going headless.

I recently became aware that the Raspberry Pi Imager (a tool that can be used to write OS images to an SD card for the Pi) has a hidden advanced options menu that you can use to configure elements of the OS. All you need to do after launching Raspberry Pi Imager is hit CTRL+SHIFT+X (on Windows) to launch the advanced options menu, whatever you configure here gets applied to Raspberry Pi OS when it’s written to the SD card – neat eh!

In the example below, I did the following:

  • Set the hostname to mypi
  • Enabled SSH and set the password for the default pi user
  • Configured it to connect to a Wifi network (QWERTY in this example)

You can also do other things such as disabling overscan and setting the locale. Once you’ve finished editing the configuration, hit save, then when you write Raspberry Pi OS to the SD card it will pre-configure the OS with the settings specified. This has saved me a ton of time (and fiddling around with cables!). The oly thing I have to do manually now is to configure VNC, although I can do this via SSH using raspi-config.

Exposing a Pi to the Internet

I built a rudimentary surveillance camera for my house using the Pi Camera and this script sample which creates a basic web server and streams footage from the Pi Camera.

I didn’t use this to monitor my house for burglars…..it’s main purpose was to help me keep an eye on my cat 😸. The one problem was that it was only accessible from within my home network, which wasn’t really that useful when I was out and about. I did some research and came across ngrok, which makes it super simple to expose a Raspberry Pi to the Internet without doing anything too risky such as configuring port forwarding on your router. This enabled me to keep tabs on my cat wherever I was in the world (as long as I had an Internet connection).

ngrok support Mac OS, Windows, Linux and FreeBSD and it’s super simple to setup and free to use (with some restrictions), here is a guide on how to expose a local web server to the Internet – it’s literally a single command!

ngrok http 80

Once this command is run, it will provide the external URLs that the local port (80) has been exposed to (by default it will create HTTP and HTTPS endpoint if the command above is run). It’s then as simple as connecting to one of the public URLs which will then route traffic to the port exposed on the Pi.

Below you can see this in action….I’ve obscured the publicly accessible URLs (“Forwarding”) as these contain my public IP address.

There is also a local web management interface that can be accessed locally from the device which allows you to inspect requests, review the configuration and also metrics.

Obviously, this is a great tool for testing and playing around with, it’s definitely not something I’d use in production 😀.

Using PowerShell on the Pi

Yes, you read that correctly – you can run PowerShell on the Pi! As somebody who comes from a Windows background who loves PowerShell I was over the moon when PowerShell went cross-platform. I couldn’t ever imagine a day that PowerShell would be available on the Pi – kudos to whoever pushed for making it a cross-platform tool.

As much as I like Python, I have far more experience with PowerShell and sometimes it’s simpler to run a PowerShell command using my muscle memory than spending time researching how to do the equivalent using Python.

PowerShell is super-simple to install on Raspberry Pi OS, this guide steps through the process. I also create a symbolic link so that I don’t have to type the full path to the pwsh (PowerShell) binary when using it (this is also covered in the guide).

Once you’ve done that, you are good to go:

As a side note, I can also highly recommend Visual Studio Code I write all my Python and PowerShell scripts on the Pi using this.

3 thoughts on “Raspberry Pi Tip and Tricks

  1. Really great post – although I would expect nothing less from a chap of your calibre.

    Have a look at remote.it not only can you use it to SSH remote to your RPI (without DMZ and VPN etc) but you can tunnel through the RPI to any other device on your network. I run a remote site – Domoticz, Webcam’s, Tasmotised Sonoff switches etc all via a Pi zero.

    While you are at it, don’t forget Pi-Hole, DietPie and netdata.cloud.

    Like

  2. […] Before I started jumping into creating an Azure Function to “do something” based upon a webhook call from my Starling Bank account, I needed to see what these calls look like, so that I could figure out the data I had to play with. This is where I had the bright idea of using ngrok. My theory was that I could publish an endpoint on my local machine, publish this to the Internet and configure the Starling Bank webhook to call this public URL and then inspect the request made. I’ve previously written about ngrok here. […]

    Like

Leave a Reply to Brendan Griffin Cancel reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s