# IMPORT NECESSARY DEPENDENCIES
# THE SSD1306 DEPENDENCY IS AN EXTERNAL DEPENDENCY
from machine import Pin, I2C, Timer, PWM
from ssd1306 import SSD1306_I2C
# INITIALIZE DISPLAY
i2c = I2C(0,sda=Pin(0),scl=Pin(1),freq=40000)
oled = SSD1306_I2C(128,64,i2c)
# INITIALIZE HC-SR04 SENSOR
trigger = Pin(3, Pin.OUT)
echo = Pin(2, Pin.IN)
# INITITALIZE BUZZER #
buzzer = PWM(Pin(13))
# set audio frequency
# set audio volume from 0 to 1000
# INITIALIZE VARIABLES #
target_distance = 2 #meters
# CREATE A FUNCTION TO CHECK FOR DISTANCE #
# turn off trigger, and wait for 2 microseconds
# turn on trigger, and wait for 5 microseconds
# turn off trigger
# count time it takes to receive an echo
while echo.value() == 0:
signaloff = utime.ticks_us()
while echo.value() == 1:
signalon = utime.ticks_us()
timepassed = signalon - signaloff
#convert the time to measurements
#measurement in cm
#distance = (timepassed * 0.0343) / 2
#measurement in m
distance = (timepassed * 0.000343) / 2
#measurement in feet
#distance = (timepassed * 1125) / 2
# ADD MAIN LOOP TO 'TRY' STATEMENT IN CASE OF ERRORS #
# CREATE MAIN LOOP #
# WIPE DISPLAY SCREEN #
# GET RESULT FROM SENSOR #
result = sensor()
if result < target_distance:
oled.text(str(result) + " m",0,10)
[slogan id=”header” h1=”Overview” h3=”How To Install WordPress On A Raspberry Pi”]
Ever wanted a blog? No? Yes you do, ’cause I say you do. You want a blog, and you want it small. You want it on a Raspberry Pi. Are we clear? Good. Well, I’m glad you agree because that just so happens to be what my tutorial is about this week! I walk you through the steps of setting up Nginx, PHP, MariaDB and WordPress so that you can host your own blog using a teeny tiny Raspberry Pi!
[slogan id=”header” h1=”Important Links” h3=”How To Install WordPress On A Raspberry Pi”]
[slogan id=”step1″ h1=”Step 1″ h3=”Setup The Pi”][/slogan]
To get wordpress running on a Raspberry Pi, we obviously need a Raspberry Pi to install it on. If you aren’t familiar with them, Raspberry Pi’s are cheap ($35) linux computers. Assuming that you have a keyboard, mouse and HDMI monitor plugged into the Pi, we need to load the operating system onto it.
Before we can install WordPress, we need to install a few pre-requisites. The first and foremost is a webserver. There are several free webserver applications available, but I’m going to use Nginx because it works well with the Pi’s limited resources. So open up a command line and run these commands.
sudo apt-get update
sudo apt-get install nginx
sudo service nginx start
sudo service nginx status
systemctl status nginx.service
To exit out of the last command, just hit CTRL+C. Now you can open up a web browser on the Pi and type “localhost” into the address bar. When you hit enter, you should see the Nginx splash page.
[slogan id=”header” h1=”Overview” h3=”Cheap Alexa Printer From An Old Receipt Printer”]
I hate wasting perfectly good technology, even if it’s old and outdated. So being the diligent tinker nut that I am, when I found this old receipt printer, I had to find some useful way to re-purpose it. And what better way to repurpose old tech than stuffing it with a Raspberry Pi? I’m sure eventually everything (including people) will be stuffed with Raspberry Pi’s. I’ll be the first in line 😉 Anyway, using the online service “If This Then That” (www.ifttt.com), I was able to connect the Pi and printer to a ton of online services, including Amazon Alexa. Long story long, I turned the old receipt printer into an Alexa printer. Guess I could’ve just said that at the beginning. Oh well.
[slogan id=”header” h1=”Parts List” h3=”Cheap Alexa Printer From An Old Receipt Printer”]
What did you bring for lunch? MARIO! Wait, does that mean your a cannibal? NOPE! I HAVE AN ARCADE IN MY LUNCHBOX! Sooo…your eating video games for lunch? YOU KNOW IT! THEY’RE GLUTEN FREE AND LOW ON CARBS!
I’m bringing back my old “Weekend Hacker” series, and I’m relaunching it with a portable Raspberry Pi Arcade. Some of you may remember the larger arcade cabinet I built a while back. I’ve been meaning to make another one that’s more portable. So when I acquired an old lunchbox and wanted to find something to do with it, this arcade idea sprang into mind!
Spotify is such an awesome music service. Raspberry Pi Zero is such an awesome ultra-mini computing device. Obviously, combining the two is something I must do!!! The idea here is to make something that’s stylish, portable, can play Spotify, and hopefully also display visuals such as album art. If you’re interested in following this project, feel free to click on the “Follow” icon just above this paragraph. Click the video below to see an overview, otherwise, scroll down to see how I made this musical masterpiece!
The Pi Zero W is a phenomenal full linux computer that’s basically the size of a stick of gum. And the “W” version has both bluetooth and wireless built in! That opens it up to so many amazing potential projects. One that I have been really wanting to do is a portable streaming Spotify client that displays album art or other visuals. Does it have to be a Pi Zero? Nope. You can use any other Pi or Pi alternative, but I just love the portable size and power consumption of the Pi Zero. The only issue is that the Pi Zero (at least the current iteration at the time of writing this guide) doesn’t support Audio Out, unless it’s through HDMI, but I’ll touch on that a little later on. There are pre-built audio output “hat’s” available, if you want to go that route. But anyway, here’s the basic goals and obstacles I’ll have to overcome for making this project work:
Add audio output to the Raspberry Pi
Add an amp/speaker to the Raspberry Pi
Find a way to stream Spotify as a “headless” client
Display album art on a small LCD screen.
[slogan id=”step2″ h1=”Step 2″ h3=”Setting Up The Pi Zero”][/slogan]
Before we do anything else, the first thing is to get the Pi Zero up and running. This is pretty much the standard setup for any Raspberry Pi that you get. Here’s the basic items a Raspberry Pi requires to setup, if you are unfamiliar with the process:
The first step is to load the Raspbian Operating System onto the SD card. The Raspbian OS can be downloaded from here. It downloads as a zip file that contains the Raspbian image file, and the way to transfer that image file to the SD card on Windows is by using the Win32 Disk Imager (you can use Etcher.io for other platforms).Once you launch Win 32 Disk Imager, you can choose the drive letter for your SD card, choose the Raspbian image, and then click “Write” to write the image to the SD card. Then eject the SD card and put it in the Raspberry Pi, along with the monitor, keyboard/mouse, and power.
Use Win32 Disk Imager to burn it to the SD Card
Insert the SD card into the PI
Add HDMI, Keyboard, Mouse, and power to the PI
After the Pi boots up, you can click on the wireless icon in the upper right and choosing your wireless network. Then by right clicking on that same wireless icon and choosing “Wireless & Wired Network Settings”, you can set a static IP address for your Pi. Lastly, you want to click on the menu icon in the upper left and choose Preferences > Raspberry Pi Configuration. Then click on the “Interfaces” tab and make sure SSH and SPIare enabled. After that, everything should be setup on the Pi and we can begin the dirty work.
It serves several purposes: it creates an audio output, serves as a mono-amp, and can be powered through the Pi zero GPIO pins. It’s pretty simple to wire up. I’ve decided to use the Adafruit Proto “Bonnet” for the Pi to make it easier to connect everything up to it. You can use the diagram below to connect it to your Pi.
[slogan id=”step4″ h1=”Step 4″ h3=”Adding the LCD”][/slogan]
The key to make my streaming radio stand out and give it a unique touch is to have a screen that displays the album art of the current song that is playing. Obviously this is going to require an LCD. I’m going with a 1.8″ TFT LCD screen.
This screen as well can be powered through the Raspberry Pi GPIO pins. So now the Pi, the amp, and the LCD screen can all be powered through a single source and can be self contained. Here’s a diagram of how to wire the LCD to the Pi Zero and how it connects to the Raspberry Pi “Bonnet”
If everything goes right, you should see the image you downloaded on the LCD screen. But as of right now, we would have to run those “modprobe” scripts every time we reboot the Pi. So we need to automatically start them at every boot. Here’s how to do it.
First create a new file called “fbtft.conf”
sudo nano /etc/modules-load.d/fbtft.conf
Add these two lines to this new file:
Now create a new modprobe file:
sudo nano /etc/modprobe.d/fbtft.conf
And add this line to it (the “adafruit18″ is for the 1.8” tft)
options fbtft_device name=adafruit18
With that done, everytime you reboot, the screen should automatically be initialized.
[slogan id=”step5″ h1=”Step 5″ h3=”Installing the Spotify Software”][/slogan]
Now it’s time to add the magic smoke! Since the goal here is to have a radio that streams Spotify, we’ll need to find some software that connects to it and plays whatever song we choose. Another requirement is that we essentially want this to run in “headless” mode, which means we want the software to run automatically and startup with no user intervention.
At first, the logical solution would be to use the Spotify web API. This would allow us to write a program that can get song information, get playlists, play songs, etc. The biggest issue is, however, that the song tracks are limited to 30 seconds, so that essentially takes it off the list as a viable candidate.
After doing more research, I stumbled across Mopidy, which is a python based music playing application for the Raspberry Pi. It can play music from several sources, including locally, Google Music, Soundcloud, and of course Spotify. The only catch, however, is that it requries a Spotify Premium account.
Setting up Mopidy with the Spotify client on the raspberry Pi is super simple. Just run the command below:
pip install Mopidy-Spotify
Now we’ll need to edit some of the configuration settings to make sure it connects and plays correctly.
Scroll down to the section and enter in your username and password.
Then type CTRL+X to exit the nano editor, and Y to save the changes. Then reboot your Pi with
After the Pi comes back up, and you can establish another SSH session, you can start Mopidy simply by typing
It will start up the mopidy server so that you can connect to it….but how do you connect to it?
Mopidy is also a Music Player Daemon (MPD) server. And MPD has many different clients across many different platforms. So you can download an MPD client on Windows, Mac, Linux, iOS, and Andriod and use that to control your music in Mopidy. You can use whichever one works best for you.
MPDroid Android client
So with the Mopidy server running on your Pi, you should be able to enter the Pi’s IP address (that we set earlier) into the settings of the MPD software to connect to it. Then you can remotely control what’s playing on your Pi.
To make it so that Mopidy automatically starts up when the Raspberry Pi starts up, you first need to copy over our config settings to the mopidyctl user
What would a radio be without physical knobs that you turn to control it? But adding custom physical controls to a computer can sometimes be tricky. First, let’s decide what these knobs will do. I’d like to have two, and I want one that can control the volume and one that can power the Pi on and off (although that can be tricky in itself).
My first thought was to grab a couple of potentiometers and control the Pi with them. But potentiometers are analog controls, which means we’d need some type of extra converter (ex. Arduino) to convert the analog signal to digital. Then I stumbled across a better option: rotary encoders, which are very similar, except the output is digital. There are even rotary encoders that also act as a push-button as well. So let’s see how we can use these to make our controls
As I mentioned before, adding a physical shutdown/power up switch for the Raspberry Pi can be tricky. If we simply added a switch between the Pi and a power supply, this will essentially cut all power to the Pi while it’s running, which can cause damage to the software and hardware of the Pi. So a better way would be to add a button that sends the Pi the shutdown command to power it down. Then we can use that switch to kill the power once it’s been safely shutdown.
With that in mind, I found this great guide on gilyes.com for adding a shutdown/reset button on the Raspberry pi. The guide and code is for use with a push-button, and luckily the rotary encoders I purchased also have a push-button function. So instead of turning the knob to turn it off/on, you have to push the knob. But hey, it works and keeps the aesthetic. Here’s how to connect it up:
After the reboot, you should be able to press the encoder button quickly to restart the Pi, and then hold it down for 5 seconds or more to shut it down. If you want to start it back up, just press the button again.
One knob down, one more to go! Time to tackle the volume knob. Using another rotary encoder, I was able to find this guide on modmypi.com for letting it control the volume on the Pi. I changed the guide a little to fit my design more (pin 18 was already being used), so here’s how I connected it up:
To test it out, launch your favorite MPD client and start some music playing. Then use the encoder knob to adjust it!
[slogan id=”step6″ h1=”Step 7″ h3=”Creating The Cover Art Software”][/slogan]
Now that we have the music playing, let’s see if we can make something that detects the current song playing and pulls the Cover Art for that song from the web and displays it on our little LCD screen.
LastFM has a good database of artists and album art, as well as an easy to use API. So I signed up for a developers account, and it gave me an API key to use in my programs.
Now that we have a place to get album art, let’s figure out how to know what song is currently playing on MPD. Searching the internet, I found python-mpd2 a simple python client that can extract information from an MPD server (such as artist, album, playtime, etc.)
pip install python-mpd2
In it’s library you can use calls like
to get the artist name, and
to get the album name.
Also, we will need to install the python “urllib” so that we can retrieve images from a URL.
and then starting the service will keep it running even after a reboot:
sudo systemctl start coverart.service
Now whenever you play a song on the Pi, it should download the album art and display it on the screen!
[slogan id=”step8″ h1=”Step 8″ h3=”Giving It Power”][/slogan]
The great thing about the Raspberry Pi is that it uses very little power. It can easily be run by using a power bank that’s normally used to charge cell phones. I found a 2500 maH power bank on Amazon. And the first thing I did was remove the casing leaving just the battery and the charging board. I then de-soldered the USB cable and added a slide switch, so that it can easily cut the power to the Pi. Finally, I extended the leads between the battery and the charging board so that it could fit better in the casing (which will get to in the last step).
[slogan id=”step9″ h1=”Step 9″ h3=”Making The Radio Case”][/slogan]
Finally it’s time for the fun stuff (not that it hasn’t been fun up to this part)! To give this project the “vintage radio” asthetic, we need to make a nice looking case. If you have an old vintage radio laying around, your welcome to shove all these components into it and resurrect it as a streaming radio, but in my case, I needed to make my own. Browsing online for inspiration, I found this cool looking Emerson AX-212.
With this as my muse, I opened up Tinkercad and designed a 3D model that mimics the design, but is scaled to fit the Raspberry Pi, LCD, Speaker, and all the other components (I took a ton of measurements). Then it was just a matter of downloading it as an STL file and 3D printing it. To give it a more Antique look, I spray painted it with a “hammered metal” textured spray paint.
Then it was just a matter of fitting in all the different components.
Then finally, it’s time to flip the switch to turn it on, connect to it with your favorite MPD client, and let the music play!
[slogan h1=”Make A Snapchat lens for your webcam?”][/slogan]
Ever use a Snapchat lens and just wonder “How’d they do that?”. Well, even if not, I’m going to take a look at some of the face tracking and computer vision technologies that makes the Snapchat lenses work, and you can even use it with your computers webcam!
There are tons of virtual assistants out on the market: Siri, Ok Google, Alexa, etc. As if virtual assistants weren’t creepy enough, I had this crazy idea…what if I made the virtual assistant real…kinda. Enter Teddy Ruxpin, an old animatronic teddy bear from the 80’s and 90’s. These bears were all the rage when I was a kid. Naturally, I decided to take the creepy little bear and hack it so that it ran Amazon Alexa. Now every time you ask it a question, it will move its eyes and mouth to answer your question! Let the nightmares begin 😉
[slogan h1=”DIY Retro Style Digital Camera”][/slogan]
Cameras have been around for centuries. But since the birth of digital, many of the old film cameras have just been tossed aside. Let’s give these amazing pieces of technology a second chance by upcycling an old film camera into a digital camera! We can do this using a small computer module called a Raspberry Pi Zero and it’s corresponding camera module. In part 1 of this 2 part series, we will assemble the hardware and retro-fit it all to fit inside the camera!
[slogan h1=”How To Make A Cheap 360 Video Camera With A Raspberry Pi”][/slogan]
Have you ever wanted to make a 360 degree videos without spending a fortune on a 360 video camera? Well, if you have $15, a Raspberry Pi and a webcam lying around, then you can make your own 360 degree videos! Watch my tutorial to find out more!
[slogan h1=”Project #394″ h3=”Turn An Old RC Car Into A Ping Pong Ball Blaster!”][/slogan]
Ok, let’s be honest. Is there any real need for a ping pong ball machine gun? No. But then again, is there any real need for a water gun? No. Both are definitely great for pranking friends or to spook intruders or pesky wild life! Regardless, in this video I show you how to make a ping pong ball machine gun using the parts from an old RC car.