Raspberry Pi Crash Course

Photo by henry perks on Unsplash

Raspberry Pi Crash Course

How I went from 'not knowing shit' to 'LED lit'

My partner got me a Raspberry Pi (CanaKit) a few years back, and I only recently took the time to get to know how to use it.

I still barely know what I'm doing, but I know enough now to fix the initial issues I was having, so now I can move on to doing cool shit with it.

We're going to go over each of the issues I had, how I solved them, and finally -- make an LED blink using JavaScript.

Issues Out of the Box

My unit wasn't defective or anything. These were software issues. Still, I wasn't sure how to solve them; my normal approaches weren't working.

The first issue was that Bluetooth wouldn't work. Not that big of a deal, since I had a wired keyboard and mouse laying around. Still kind of annoying, but I was willing to make peace with it since it's a barebones computer.

The next issue was a bit more problematic, though. I was getting errors any time I tried to use apt or apt-get. Everything I came across online suggested I update the distro mirror URL in the /etc/apt/sources.list file.

I tried for a while to make this work, but it just wasn't happening. After I changed up my Google search a bit, I discovered that I was running an older distro, Stretch. All of the forums were referencing newer distros -- Buster and Bullseye.

This gave me a bit more hope. Upgrading the distro would surely fix my issues.

Distro Updates

From a forum answer, I gleaned that Buster came after Stretch, and Bullseye came after Buster. It was recommended to first upgrade to Buster, then to Bullseye, rather than upgrading from Stretch straight to Bullseye.

Again, the forums suggested editing the /etc/apt/sources.list file, but this time instead of adding a new mirror URL, the suggestion was to change any instances of the word 'stretch' to 'buster', then run a sudo apt-get update.

This worked, but the next time I booted up the pi, I got an error saying that the root account was locked. I couldn't even access the desktop.

Googling some more, I discovered the Raspberry Pi Imager tool, which is what I should have been using from the start. At this point, I was glad I had the Cana Kit, because it came with a microSD caddy. Now all that was left to do to do was:

  • put the microSD card from the pi into the caddy

  • plug the caddy into my laptop

  • open the imager tool

  • select the Bullseye distro

  • select the USB caddy

From here, the imager tool took care of the rest. I popped the microSD back into the pi, and Bullseye loaded right up.

Once Bullseye was installed, I was able to connect to Bluetooth, and all of my shell commands worked the way I expected them to. With that, I proceeded to install zsh, oh-my-zsh, and neovim.

Hardware Time

Now that my software issues were out of the way, it was finally time to work on the hardware. Well, almost.

The literature that came with my CanaKit had examples of setting up a circuit and then running it on the Pi using Python. I've used Python before and was confident I could get it to work in Python, but I am a big fan of sticking to one programming language for as many things as possible.

Seeing that JavaScript is ubiquitous these days, I figured there had to be some resources out there to guide me in that direction.

Sure enough, I was in luck. The first steps were to install Node.js and npm. That was simple enough, but I wasn't sure how Node could let me control the hardware. Then I realized, "Well shit, I don't actually know much about this hardware at all".

That was when I found this blog post, which gave me a primer on how the pins on the pi work, the reasoning behind using resistors, and a few other electrical engineering tidbits.

The blog post also filled in my knowledge gap around how Node can interface with the Raspberry Pi -- through the onoff package. onoff implements the GPIO logic of the pins in Node.js, so that people like me who find that sort of thing intimidating can work with a simple/intuitive API and have fun with their pi (hey, that rhymes!)

Although the blog post had an example with an LED using pin 4, I didn't want to copy it directly. I always like to change things up a bit to make sure I understand the concepts, instead of just following someone else's work to the tee.

So what I decided to do was use the Python example from the CanaKit (which used pin 18), and convert the Python code they provided into Node.js code. Once the circuit was set up and the code was written, running it was as easy as node led.js.

I was pleasantly surprised at how straightforward the coding part of this was. I had expected to install a bunch of things to get it working.


At this point, I was feeling pretty good. I felt like I finally had a basic understanding of everything that came in my CanaKit, except for one box that said "breakout board" on it.

Off to the Google Machine again. Turns out, a breakout board is just a labeled (and therefore more convenient) set of pins for the Raspberry Pi.

When I was going through the LED example in the previous section, I had to keep referencing a GPIO chart that tells you which pin is which. The breakout board has labels next to each of the 40 pins so that you don't need to reference a chart.

The tradeoff here is the form factor. The original 40 pins fit right in the tiny Raspberry Pi case. The breakout board attaches to the original 40 pins and sits outside the case. If the pins inside the Raspberry Pi were labeled, then the device would have to be made bigger to account for that.

Next Steps

This has got me excited about the possibilities of tinkering with hardware. I want to see how far I can take it, both on the hardware and the software side. How complex of a circuit can I make? What sort of useful hardware can I wire this up to? Can I have that hardware signal some software I write, based on the conditions of the circuit?

I hope you'll stick around to find out!