aka Setting the Pi up for SSH and headless running!
Hello! Have you all been having fun watching your motors go backwards and forwards since Pt2? Good good…
My original intention for this article was to cover tapping the optical encoders for positional and directional feedback. The more observant folks out there will also have spotted that there are some extra wires soldered to the pin headers on the DRV8835 in the photo above. Well, it turns out that the LEDs in the encoders are also both dead and need replacing. I’ve got a matching pair of replacements on order from mouser.co.uk, but the next shipment doesn’t hit the country til January. So that’s that plan scuppered for a while. Ignore those additional wires. Their presence will be explained in the future.
Instead, we’ll turn our hands to making our Pi run “headless”, and then in Pt4 we’ll look at addressing MANUAL CONTROL!
Headlessness: The Decapitation of Pi
Running headlessly means setting our Pi up so that we can operate it remotely over the network – no need to have a monitor or keyboard connected to it! There are a few preparatory steps we need to perform to allow this. This bit should take 30 minutes, tops from start to finish.
Get your Pi hooked up to a monitor, keyboard & network, and plugin the 12v PSU that we connected to the DRV8835 board in Pt2. The Pi will boot up and land you at the log in prompt, so as per last time, we’ll use the username: pi and the password: raspberry, and we should then find ourselves at a usable command prompt. Run the following command:
This is the main tool for configuring the Pi. It should load with option 1 (Expand Filesystem) already highlighted, and look something like below:
This expands your Pi to consume all of the SD card that you’ve inserted into it, and we want to do this, so just hit the [enter] key on your keyboard and let it do it’s thang. When it returns to the utility, it should be informing you that it’ll take effect on the next reboot. Just hit the [enter] key again and you’ll be back at the raspi-config menu.
Next we need to use the arrow keys on our keyboard to move down to option 7 (Advanced Options) and hit [enter].
Use the down arrow key to highlight option A4 (SSH) and hit [enter]. You’ll be asked if you want to enable SSH. Use the left and right arrow keys to highlight [Yes] and hit [Enter]. Again you’ll end up back at the main menu. We need to make one final change, so shufty back down to Opt 7 (Advanced Options) and hit enter, then shufty down to Opt A2 (Hostname). Hit [enter] on the warning screen, then give your Pi a name – don’t use spaces. I’ve called mine scope for simplicity.
Hit [enter] to complete the process, and we’re back to the main menu. Use the left and right keys to highlight [Finish] and hit enter. You’ll be asked if you want to reboot now. Highlight [yes] and hit [enter].
Your Pi should reboot. Wait for it to return to the log in prompt.
Now, disconnect your monitor and keyboard from the Pi.
Your Pi is now running headlessly!
Connecting to the Pi using an SSH console
We still need to enter some manual commands on our Pi. To do so we need to connect to it remotely from a PC or other computer.
If you’re on a Mac, or a Linux box with Avahi mDNS installed, you can just pop open a terminal (found in Utilities) and enter the following command (replacing the emboldened scope with whatever you called your pi):
…so that’s ssh firstname.lastname@example.org – it should connect and prompt you for a password (raspberry)
If your main PC or Laptop is a Windows-based device, you’ll need to download PuTTy – an SSH Terminal.
Once it’s downloaded, run it, then fill in the Host Name as whatever-you-called-your-pi.local
Give your Putty connection a name in the “Saved Sessions” box, and hit the [Save] button to the right, then click [Open].
If you immediately receive a “Host does not exist” error message, then you need to download and install Bonjour Print Services for Windows, and then download and install the Bonjour SDK for Windows, reboot your PC, then head to your browser’s download folder where you’ll find putty.exe, run it, and repeat the preceding step above!
If you still have issues, try installing iTunes (by far the simplest method – remember, just cos you’ve installed it doesn’t mean you have to actually ever run it), or, if you’d rather not have iTunes on your PC, see this blog post which details how to get the Bonjour installer out of the iTunes installer and run it separately.
Once you’re at the log in prompt, you can proceed just as though you would have if you still had a keyboard and monitor hooked up. Everything works the same when it comes to linux command line. Log in with the username: pi and password: raspberry
Connected by SSH?
SECURITY NOTE: Your Pi is now exposed to the network. You should change the default username for the pi account, so once logged in via SSH, enter:passwd
and you’ll be prompted to change the password to something more secure than the default of raspberry
Whenever you need to connect to your Pi, on windows just run Putty (from your downloads folder, or right click it, make a shortcut and drag that to your desktop) and dbl-click Scope or whatever you saved the session as, and login. On Mac/Linux, just re-enter the ssh command into terminal in the format ssh email@example.com
Next we need to crack on with getting Node-Red and it’s dependants up and running so that we can start programming the Pi graphically via Node-Red’s web interface from any machine on the network and begin building this monstrosity! I’ve separated this out into Pt4.